четверг, 7 января 2010 г.

Next generation programming style

A very good article about programming:
http://codemonkeyism.com/generation-java-programming-style/

in particular, this one is great:
http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/

Bad books samples

Today I read a blog entry How Programming Books Promote Code Smells.

This is true: many books contain examples of bad code.

One of my favorite examples is the main method with try/catch like this one.


public static void main(String args[]) {
try{
FileInputStream fstream = ...
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}


This try/catch is absolutely NOT NEEDED! If you skip them, the JVM does exactly the same work. the well-known "Throw early catch late" principle says that you shoudn't catch exception until you know what to do with it (except the trivial actions that the system does by default).