Monday, July 17, 2006

.Net: pathway to many abilities some would consider unnatural

You just know I've been waiting for an opportunity to use that particular dark side quote.

On Saturday afternoon, I decided to learn more about OCaml since it has long been on my list of "interesting languages I should look into sometime". The wikipedia page had a link to the F# project. It is to OCaml as Boo is to Python: a .Net implementation that mutated the language by enhancing some features, smoothing out some rough edges, and, last and least, taking on new restrictions/limitations due to the platform. Here's a nice table. I've read recreationally about some other functional languages like Lisp, Scheme, Haskell, but I must say that OCaml/F# appeals to me the most at this point. Part of the reason may be because of the down-to-earth, clearly written tutorial I skimmed through. Honestly, my comprehension level reminded me of when I learned Perl. When you start out at ground zero, the code looks like so much gibberish (Python would be an example of code that at least looks more welcoming to beginners), but with each little bit you learn the code makes more and more sense. Haskell gave me the same impression, but on the other hand I still can't read Haskell code as fluently as I can read OCaml now.

Some of the specifics I like:
  • OCaml is fundamentally functional, but it has perfectly adequate support for imperative and object-oriented styles if the need arises. F# has different ways of doing objects than OCaml, but for the sake of CLR interoperability this could be a hybrid bug/feature. OCaml is multi-paradigm to a pleasing degree. Lazy evaluation can be turned on at will.
  • An impressive list of language primitives, and unlike some other languages the primitives are REAL unboxed primitives, not object wrappers. Tuples, lists of course, records, discriminated unions, even references for those cases in which you feel you must have a true variable to store an intermediate result. The syntax doesn't make you want to choke yourself, either.
  • It has good roots and history. OCaml is not just a project that outgrew its original boundaries; it was carefully architected upon solid theoretical work.
  • Static typing without explicit variable type declarations. I like to think of it as adding program efficiency and safety without even trying. Of course, this can only go so far before the programmer needs to intervene to prevent the compiler from guessing wrong, but it's still a marvel. Something about me just gets queasy at the idea of a variable containing a variety of possible things at runtime, or morphing into something else accidentally. OCaml does offer a 'generic' type, by the way, and since its operators can handle all data types, functions with generic type parameters just work without having to write separate code paths per type. Its templating ability is par excellence.
  • It's not Ruby. I have an irrational animosity toward anything that even hints of being the latest pasture for sheeple, even if the category is "languages with functional features and dynamic (meaning the type is not set at compile time) typing". I hate the concept of a herd controlling my thoughts, with or without my consent.
Unfortunately, I'm not sure that there's a strong case for using OCaml or F# as general-purpose languages. The syntax is definitely tilted toward heavy symbolic/math applications. Some of the examples I have seen look more like algebra than any other programming language, except Haskell perhaps. A hundred lines of Caml will blow your mind. In particular, the example of the 3rd derivative of a sine is still blowing my mind. The great thing about F# is the potential to mate this great power (when wielded responsibility) with the extensive .Net libraries. But I could see myself having trouble explaining an F# program to people who haven't been initiated. OO would feel more natural to them. Thanks to some people at Microsoft Research working on F#, the .Net CLR is a pathway to many abilities some would consider to be unnatural.

1 comment:

  1. Haha... I use that quote, and try to paraphrase Palpatine as often and as surreptitiously as possible in my conversation. Peace

    Arché

    ReplyDelete

Note: Only a member of this blog may post a comment.