Archive for the ‘python’ tag
Tornado (the Python WebServer/Framework behind FriendFeed) goes OpenSource
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.
Python 3.0 Released
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.
Beautiful Closures
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.