Python & Java: a Side-by-Side Comparison

Someone pointed me to this Python & Java comparison. Although many valid points were made, there are quite a lot things that I don't agree with and that are not right (and I'll compare it with C# too for convenience): To start off, the Hello World example. Sure the Java code is longer, so what? This doesn't prove Java is not compact (although it may be true, this example doesn't prove that). It just shows that when you start writing a Java programme you'll have to dive into classes right away, in Python you don't.

The second example is a bit sad too. Oh look how much space the Java code takes! Writing it like this saves quite a lot:

int myCounter = 0;
String myString = Integer.toString(myCounter);

Beside that, I think it's more logical to put the functions to convert integers to strings either in the Integer or String class (and they are in both) than having a 'str' function floating around. And the for loop example after that, cute, but how much do you do this? Ok, when walking over an array you may use this. C# offers a nicer way to iterate over arrays by the way:

int bla[] = {1, 2, 3, 4, 5};
foreach(int n in bla) {
   Console.WriteLine(n);
}

About classes having to be defined in different files, this is only true for public classes. But even then, having a file for each class is usually very handy (you never have to look in which file you put a class), C# allows you to put as many classes in a file if you want.

The thing about the exception throwing is only true for exceptions inheriting from Exception, if you let them inherit from RuntimeException you don't have to add them to the method's signature. And beside that, I think it's a very good idea to add exceptions to method signatures, it lets the user know what to expect.

The thing about the constructors is right, C# however offers default values for parameters.

About the opening of a file, yes this is quite verbose, but is beautiful from an abstraction standpoint. But usually some shortcuts would be appreciated indeed, C# (or rather .NET) offers those.

The String class is fairly limited, but since 1.4 it DOES offer the split() method I believe, so the last two of that list aren't valid anymore.

The add an int to a vector code is right too, this has also been resolved in C#, you can do this there:

ArrayList aList = new ArrayList();
aList.add(5);
int aValue = (int)aList[0];

About the space a simple if-statement uses, the example could be written as:

if ( a > b )
    a = b;

But admitted, this doesn't scale well, if you want to execute more statements you have to add the { and } any way.