Friday, October 06, 2006

Compiled vs Dynamic Laguages and the Code Feedback Loop

So I bit the bullet and installed Ruby on Rails.  I’ve been reading a lot about Ruby (mainly blogs) and decided that it’s about time to learn another language.  The Pragmatic Programmers believe that you should dedicate some time to learn a new language every year.

My first impressions are probably pretty common.  Ruby is not easy to jump into.  They have a lot of great information on the internet, but I found that things didn’t go as smoothly as I had hoped.  This is probably due to the fact that there are major changes between each version of ruby/rails, and there are old tutorials directed at older versions of Ruby or Rails.

The second hinderance I found was that, with Ruby (among other dynamic languages), you don’t get any intellisense.  Being brought up with Visual Studio made me spoiled, I suppose.  The fact is, with any dynamic language, such as Ruby, Python, or Javascript…  Intellisense is difficult to provide.  Type information often isn’t available until runtime.

This really annoyed me at first, and I was quick to dismiss dynamic languages. 

Intellisense really makes your learning experience much easier.  When I started in .NET, I had a few books, but mainly I just used Intellisense to navigate my way around the framework.  If you didn’t know how to send email with .NET, you could easily just type System.Web.Mail. and you’d see the relevant classes involved.  Intellisense is an extremely effective discoverability tool.  

Now that I am an experienced .NET developer, I know all of these things by heart.  There’s not much stopping me from writing my programs in Notepad2.  I don’t rely as heavily on Intellisense like I did before.  I still use Visual Studio, though, because having your compiler and debugger integrated with your editor is almost a necessity.

This isn’t the case with dynamic languages.  You write a program (often times in a single file with FAR fewer lines of code) and you run it.  That’s it.  There’s no compilation or startup time.  You get your results right there.  If you mispell a type or call a method on the wrong class of course you’ll get an error.  But you find this out sooner that your C# / Java program will compile.  If you can write 5 lines of code and push a button to see if it worked…  without waiting for a compiler or debugger, then your code-feedback-loop is MUCH tighter.  Agile principles thrive on having small feedback loops.  This is (in my opinion) the single largest reason why Agile is so effective.

The compiler is becoming less and less popular these days because it cannot protect your program from logic flaws.  It’s becoming much like the spell-check feature of word processors.  They can tell you that you mispelled the word definate definite, but a sentence like this one will pass spell-check just fine:  We will meat at the movie theater.  A compiler can only take you so far.  To verify your program works, you have to compile it, run it, navigate to the section, and test it.  In a dynamic language, half of these steps are removed, leaving you with a much tighter code-feedback-loop.

We all love intellisense (and I will welcome it for Ruby with open-arms), but don’t let that stop you from writing your next small program in a language like Python or Ruby.  It will give you another tool in your developer toolbox and make you a better programmer in *any* language.