indiWiz.com

Subhash's Tech Log

Archive for the ‘python’ tag

Tornado (the Python WebServer/Framework behind FriendFeed) goes OpenSource

without comments

Post acquisition by Facebook, the software behind FriendFeed has been OpenSourced. Tornado is a Python WebServer/Framework. The distinguishing feature of this WebServer is that it is non-blocking and designed for high-scalability.

Facebook in the past has OpenSourced many of their frameworks and tools.

Written by Subhash Chandran

September 11th, 2009 at 11:10 am

Python 3.0 Released

without comments

My language of preference after Java, has a new release: 3.0. This is an interesting release as it breaks backwards compatibility. A conversion tool for 2.0 code migration to 3.0 is also made available by the community.

Written by Subhash Chandran

December 8th, 2008 at 4:52 am

Posted in OpenSource,Scripting

Tagged with ,

Beautiful Closures

without comments

One of the irritating things when writing code in Java is when managing files or database resources. We have to write so much redundant code:

File f = new File("/etc/passwd");
BufferedReader br = null;
try{
  br = new BufferedReader(new FileReader(f));
  String str;
  while((str=br.readLine())!=null){
    System.out.println(str);
  }
}
catch(IOException ex){
  ...
}
finally{
  if(br != null){
    try{
      br.close();
    }
    catch(IOException ex){
      ...
    }
  }
}

So much redundancy is ground for human errors. Issues like these are beautifully solved using programming concept called Closures. For example, in the newly released 2.6 version of Python, the same would be written as:

with open('/etc/passwd', 'r') as f:
    for line in f:
        print line

In the above code, even when an exception is raised during file read, the file is gracefully closed when the control exits with block. A similar example in Groovy:

File f = new File("/etc/passwd")
f.eachLine{
  line ->
  println line
}

Martin Fowler has written a short introduction to Closures.

Written by Subhash Chandran

November 18th, 2008 at 8:27 am

Posted in Java,Scripting

Tagged with , , , ,