Getting in on the ground floor
Mar. 16th, 2009 12:52 pmAs previously mentioned, I'm starting to play seriously with Scala, the cool new language for the JVM. It's being a lot of fun -- I think it has supplanted Ruby as my favorite programming language to date. It looks as sprawling and messy as Perl, but its complexity is built on top of a more careful language-design basis than most. In particular, one of the neat things about it is that most of the language can be built on top of lower-level constructs.
Here's an example, that struck me last week as especially cool. As with most modern functional languages, pattern-matching is quite important, so you get constructions like this:
Almost everything in the language is built this way. The scala-debate mailing list is currently embroiled in an argument about whether to allow "1-legged if" (that is, if without else), with the Java programmers arguing "yes" and the Haskell folks saying "no". And along the way, it's been pointed out that it's only three lines of code to add a "when" expression that has the semantics of 1-legged "if", so who cares? (And three more to add "unless". And only a few more to simply redefine "if" in terms of lower-level operators anyway.)
Which is all very cool, but does drive home the slightly scary part of using it for CommYou: the language is still a wee bit squishy. It's a very serious language, being used for serious apps, but they're still refining some of the details. It's not raw and experimental any more, but it's only about 90% mature at this point. That's not going to stop me from using it, but it does remind me that I'm going to need to be prepared for bits of rewriting down the road. (Fortunately, *most* of the arguments have to do with very high-power stuff to do with types, which matters a lot at the library level but is unlikely to affect my ordinary app code much.)
It's fun, though: I'm now on all the major Scala mailing lists, which are still dominated by the people actually writing the language and environment. I haven't been involved at this level of a fundamental-technology project since the early days of VRML. (And I think this group has more clue than we did in that project, and will come to better results...)
Here's an example, that struck me last week as especially cool. As with most modern functional languages, pattern-matching is quite important, so you get constructions like this:
def receiveMessage(x:MyMessageType) = x match {
case PING: { print "Got a Ping"; reply Pong; }
case PONG: print "Got Ponged";
}
So far, so ordinary -- on the surface, this looks like a conventional switch statement. But that stuff after "match", in the curly braces? That's actually a first-class type unto itself, called PartialFunction. Given a PartialFunction, you can check what types of things it matches, feed things into it and get return values, constrain its types, and so on. So it's easy to build powerful new operations using the same pattern-match facility.Almost everything in the language is built this way. The scala-debate mailing list is currently embroiled in an argument about whether to allow "1-legged if" (that is, if without else), with the Java programmers arguing "yes" and the Haskell folks saying "no". And along the way, it's been pointed out that it's only three lines of code to add a "when" expression that has the semantics of 1-legged "if", so who cares? (And three more to add "unless". And only a few more to simply redefine "if" in terms of lower-level operators anyway.)
Which is all very cool, but does drive home the slightly scary part of using it for CommYou: the language is still a wee bit squishy. It's a very serious language, being used for serious apps, but they're still refining some of the details. It's not raw and experimental any more, but it's only about 90% mature at this point. That's not going to stop me from using it, but it does remind me that I'm going to need to be prepared for bits of rewriting down the road. (Fortunately, *most* of the arguments have to do with very high-power stuff to do with types, which matters a lot at the library level but is unlikely to affect my ordinary app code much.)
It's fun, though: I'm now on all the major Scala mailing lists, which are still dominated by the people actually writing the language and environment. I haven't been involved at this level of a fundamental-technology project since the early days of VRML. (And I think this group has more clue than we did in that project, and will come to better results...)