Archive for the ‘dynamic languages’ Category

Here is a small sample code I wrote that shows object serialization in groovy. when I ran this directly in groovy shell it did not work off the bat. I had to move the class Name to separate file Name.groovy and make sure it is in the class-path to work. Here is the link to original discussion on groovy forum.

// put this in a file named Name.groovy and compile using groovyc 
class Name implements Serializable  {
   def fname, lname
}
// Now run the code below to see the Object serialization and de-serialization.
def test1= new Name(fname: "fn1", lname : "ln1")
def test2 = new Name(fname: "fn2", lname: "ln2")
//serialization
new File("C:/config.txt").withObjectOutputStream { out ->
    out << test1
    out << test2
}
//de-serialization
new File("C:/config.txt").withObjectInputStream { instream ->
    instream.eachObject { 
        println it
    }
}

It is evident from recent developments in the software industry that there is and will be a huge push towards dynamic languages in coming years. Emerging and successful frameworks like Ruby on Rails, Django, Grails etc. have shown the power of dynamic languages. Not only these frameworks offer large productivity gain, underlying they are all pushing towards a new era of programming languages and features. Even .Net guys have realized this and started incorporating dynamic language features into C#. C#4.o will have features like dynamic type, optional parameters and default parameter values. So what is a dynamic language. Wikipedia does a good job of explaining what features are considered for a language to be dynamic. The following definition is directly picked from wikipedia.

“Dynamic programming language is a term used broadly in computer science to describe a class of high-level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all. These behaviors could include extension of the program, by adding new code, by extending objects and definitions, or by modifying the type system, all during program execution. These behaviors can be emulated in nearly any language of sufficient complexity, but dynamic languages provide direct tools to make use of them.”

Ruby is my favorite among these especially because of its syntax and its ability to easily write DSLs. In my previous post I have  shown how we can write DSLs in Ruby and Groovy. Other features that make these languages more likable are Duck Typing, Closures, Meta-programming etc. There is a notion among lot of developers that these are scripting languages and not full blown programming languages. Any one who spends good amount of time learning Rails and Grails frameworks will take a step back and think. Although both ruby and groovy being ten times slower than java the productivity they offer outweighs the slowness, and with ever increasing power of CPUs we can afford that.