Friday, June 14, 2013

Static type system over dynamic language - short stories.

About 5 years ago, I was still a "pure" enterprise developer - meaning I only knew Java and C#. One of my teammates on our Java project was a Ruby veteran who just switched to Java. He kept complaining that he underestimated how much less agile Java is in comparison with Ruby. I just couldn't understand why he had such feelings against Java - "one of the most beautiful Object Oriented programming language in the world."

Fast forward to two months ago, Ruby/Coffeescript has been my primary language for about 4 years. I got the opportunity to switch to a scala project, and boy I was excited.

But not before soon that excitement was replaced by the frustration of having to work with all the limitations imposed by the static type system, especially when it came to some generic library I tried to write. I admit that scala's complex type system wasn't helpful either. My memory of my Ruby veteran co-worker complaining about Java became really vivid. I now understand exactly how he felt!

Fast forward again to now, two months later, I reached the point that I started to see advantages of static type system over dynamic language other than performance.

I just wrote a web socket library with play and akka. It was not a large one - 5,6 classes that took me about 5 hours to design and write. I don't normally do this but because it was the 3rd time I rewrite this library, I took the "write it all in one run and throw it against the wall" approach. It took me quite some time to get all the code compiles. The turning point was after that, it only took me 5 minutes to debug the whole socket to work perfectly with my tests and my front-end application. This was unimaginable when I was still writing dynamic language and is consistent with my recent experience with scala - compilation check found more errors (including real-time check in IDE) than tests.

In a static type language, if you design carefully (and follow some functional programming principles), chances are that the majority of the human errors will be detected during compilation time. Whoever said that compilation check is close to useless is clearly wrong this time.

Plus, designing in a static type language is a lot more fun - you have more structures to design as well as more limitation to work with.

No comments:

Post a Comment