Scala

Created on Jan. 13, 2013, 2:23 a.m. by Hevok & updated by Hevok on May 2, 2013, 5:14 p.m.

Scala is a general purpose programming language designed (as a "better Java") to express common programming patterns in a concise, elegant, and type-safe way.

A class can be simply declared like this:

class ScalaUser(var name:String,var surname:String, var email:String){}

Getters and setters are easy to create:

val setters = tp.members.filter(m=>m.isMethod && m.asMethod.isSetter).map(m=>(cutSetterEnding(m.name.toString),m.asMethod)).toMap

Scala reads and writes as it would be normal English:

something should equal("sfsf")

It is a statically typed language, but it supports dynamic traits. It provides similar paradigms like there exists in Python. You can for instance simply iterate over a collection:

for{
    item<-collection
    if item=="somevalue"
    if item.isSomething
} yield item

It is even possible to iterate over multiple collection at the same time:

for{item1<-collection1
   item2<-collection2
    if item1=="somevalue"
    if tiem2>item1
} yield( item1.someProp,item2.someProperty)

A basic function/procedure looks like this:

def someFunction(param1, param2) =
{
    ///do something
   (val1,val2)
}

It is not hard to work with OrientDB. To open a database:

val db:ODatabaseDocumentTx = new ODatabaseDocumentTx(url)

To create a document and fill it with data.

In order to save any class to the database all you need is two lines of code, considering you have created an instance of your class somehow:

val doc = new ObjectDocument(myPojo)
doc.save()

Where myPojo is an instance of any class created before. It does not work with nested classes yet, but works well with pojo's (classes with simple fields).

scala.svg

Tags: java, coding, programming
Categories: Tutorial, News, reST
Parent: Tutorials

Update entry (Admin) | See changes

1 Comment to Scala

Anton Kulaga (antonkulaga)  on Jan. 13, 2013, 4:36 a.m.

Scala is staticly typed although it supports dynamic traits.
"Getters and setters are easy to create:
val setters = tp.members.filter(m=>m.isMethod && m.asMethod.isSetter).map(m=>(cutSetterEnding(m.name.toString),m.asMethod)).toMap
"


you are quoting reflection related part of a code in one of my libs. It is not about getter and setter.

permalink for comment 1