Thursday, March 20, 2008

Static Vs Dynamic Language

I find traversing applications written in static languages (Java) easier than traversing applications written in dynamic languages (Ruby) . When I spoke with some of my co workers, they felt otherwise.

I wanted to know what everyone feels. It will be great if you could post your experience as comments to this post.

2 comments:

Jun-Dai said...

The problem is it's not quite an apples-to-apples comparison. File-for-file and line-for-line, statically-typed code is much easier to traverse largely because of the powerful tools built for them and the certainty you have about the variables you are looking at, but there's a huge tradeoff, which is that an application written in a (good) dynamically-typed language is likely to be considerably smaller, and so the question sort of becomes something like "is it easier to saw through a 2 x 4 with a handsaw or to saw through a dozen planks with a table saw?".

A similar issue comes up when you think about the fact that compile-time errors are incredibly valuable when working with a statically-typed language, whereas while you might miss them with a dynamically-typed language (as you would miss the powerful IDEs), you are also going to produce fewer of those types of errors that compiling is going to catch.

Dave Kirby said...

I work on a commercial Python application with ~250,000 lines of executable code, which is large by Python standards. I use Vim as my primary development environment, and have little trouble navigating round the code base.

The combination of exuberant ctags and a few Vim plugins gives me most of the functionality that I would want from a full IDE - I can put the cursor on a method or class name, press a key and jump to the definition. I can get a list of the class and function definitions in a file with the taglist plugin, and jump to a class or function with a click of the mouse or key.

I can also explore code interactively from the python shell or iPython - something that is much harder to do with a static language like Java. It is hard to explain to someone who does not have the capability just how useful this is.

The other consideration is that once I have found the piece of code that I want, it is much easier to read because the signal to noise ratio is so much better. For example, compare the following:
Java:
class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}

Python:
print "Hello World!"

In the Java program most of the text is noise - it adds nothing to understanding what the program does and is only there to satisfy the Java compiler. OK this is a trivial example, but the principle holds true as you scale up to large programs. Most code is read many more times than it is (re)written, so IMHO readability is more important than navigability.