Static vs Dynamic Typing: My Preference

There has been a vigourous debate in the couple of years running through the whole software development community on the merits of Dynamic vs Static typing.

When I was at uni in the mid 90’s, the static typing forces seemed dominant, but the tables have turned. Now dynamic typing is cool. Ruby, Groovy Python, Erlang, Clojure and Javascript are wowing everyone with their funky features and terseness. Sometimes it seems like all the smart people are doing it, while the mediocre corporate.programmers of the world plod along in statically typed Java, C# or C++.

Where do I stand?

Static Typing Forever!!!

I still love statically typed languages. For me, its the only way to fly.

The safety & correctness aspect of static typing is only a part of their value.The fundamental reason for typing is to put more of the intent of the code into the language. Thus requiring less knowledge be stored in the programmers head.

def writeToStream(stream)
  stream.write(@content)
end

bytesWritten = envelope.writeToStream(filestream)

In this Ruby example, the programmer clearly intended “stream” to be a particular type of object. That is, stream does have a type, its just implicit in their head. Well then, why not use a language and toolset smart enough to understand type of ‘stream’? Why burden the programmers brain with sole responsibility for implementing the type system?

Yes, I’ve used Dynamic Typing in Anger

For 6 months Ive been working on a large commercial JRuby/Rails and heavy Javascript dynamic web site. Dynamically typed code all day long. Yes, you can stay DRY and keep the syntax clutter low. But Im tired of operating in the fog of partial certainty about what the objects Im woking with actually are and can do.

The challenge: Making Static Typing easier

I think the surging popularity of dynamic typing is symptomatic of the pain of the syntax-heavy static type systems in C++/Java/C#. But I would rather fix the pain and keep the types.

Type Inference is the answer. To those who favor dynamic types: have you looked at statically inferred-type language like Scala, Boo or Haskell?

2 Comments

  1. David Kemp said,

    June 19, 2008 at 9:31 pm

    I agree. When writing new code, types may seem a chore, but when trying to use an API written by someone else, the type declarations really help. Type inference looks like a nice middle ground.

  2. SoftwareDeveloper said,

    May 15, 2009 at 9:17 pm

    I agree 100%, dynamic typing will always come back and bite you when your project gets bigger (and older).

    Given that 90% of development time goes to debugging and 10% to actual coding, it seems stupid to spend a a dime to save a nickel.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: