Wide Awake Developers

« When Should You Jump? JSR 308. That's When. | Main | SAP's SOA ESR »

Type Inference Without Gagging

I am not a language designer, nor a researcher in type systems. My concerns are purely pragmatic. I want usable languages, ones where doing the easy thing also happens to be doing the right thing.

Even today, I see a lot of code that handles exceptions poorly (whether checked or unchecked!). Even after 13 years and some trillion words of books, most Java developers barely understand when to synchronize code. (And, by the way, I now believe that there's only one book on concurrency you actually need.)

I still recall the agony of converting a large C++ code base to const-correctness. That's something that you can't just do a little bit. You add one little "const" keyword and sooner or later, you end up writing some gibberish that looks like:

const int foo(const char * const * blah) = const;

I'm exaggerating a little bit, but I bet somebody more current on C++ can come up with an even worse example.

That's the path I don't want to see Java tread.

On the other hand, Robert Fischer pointed out that type inference doesn't have to hurt so much. His post on OCAML's type inferencing system is a breath of fresh air.

There's quite a bit of other interesting stuff in there, too. I particularly like this remark:

What the Rubyists call a "DSL", Ocamlists call "readable code".

I'm still working on wrapping my head around Erlang right now (it's my "new language" for 2008), but I might just have to give OCAML preferred position for my 2009 new language.

Comments

Thanks for the reference.

Ocaml's got its own share of problems, but it's type system is nicer than anything else I've dealt with, particularly when you look at the JoCaml extension for expressing concurrency. Now, admittedly I haven't spent enough time out there to really grok Haskell: its type system and laziness both freak me out a bit.

Which brings up one of the nice things about learning Ocaml -- you can write code in a functional or OO style if that's how you're used to thinking about a problem, and you can take the training wheels off and go functional as you feel comfortable doing so.

> What the Rubyists call a "DSL", Ocamlists call "readable code".

And what Java people call a "DSL", Rubyists call a String token.

Casper,

Can you elaborate on that? I'm not sure what you mean about a String token.

Thanks,
-Michael Nygard

Sorry, suppose I could have been more clear. I'm referring to the current trends of placing a DSL inside string tokens of annotations. This can be seen among other places in JSR-220 (JPA query language), JSR-295 (Swing App Framework) and JSR-296 (beans binding).

The problem with this is that it can only be interpreted, resolved and verified at runtime. Fair enough for a light, dynamic language, but it feels clumsy and unnatural in a heavy, static language like Java - and refactoring tools fails completely at coming to the rescue.

Ah, when you put it that way, I could not agree more!

Great post, as usual. But shouldn't the syntax for the C++ code be this:

const int foo(const char * const * blah) const;


Stefan,

I'm sure you're right. It's been many years since I did any C++, and I was trying to dredge up the syntax for a pure virtual method from the dusty reaches of my memory.

Thanks,
-Michael

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)