Friday, July 27, 2012

Type safety + auto = win!

A while back, playing around with functional programming, I started trying to implement interesting functions in Lisp. It all went well until permute, a function which isn't that complicated but involves lists, lists of lists, and lists of lists of lists. This was so confusing and complicated that I gave up.

More recently, I tried it again in Haskell. It took less than twenty minutes! The reason was Haskell's type declarations, which made it so much easier to think about what was going in and out.

The type system can often get annoying, and become a pain (e.g. Java), hence the popularity of dynamic typing (Python/Ruby/Ecmascript). But when thinking about complicated algorithms and systems, they are a great structuring force. Which is part of why I love D: "auto" and "Variant" lets you forget about a lot of it, but you can still be explicit when it is important.

No comments:

Post a Comment