Saturday, August 13, 2005

NFJS 2.2 - Beyond Java

I attended this discussion on what is coming after Java partially to see if we had anything to fear about losing Java sometime soon (we don't), and to see if any other languages bring something new to the table (they do). The speaker, Bruce again, talked primarily about Ruby, because of some great metaprogramming, and programming by convention features built into the language. In the period following this session Bruce talked about libraries that bring some of these types of features into Java, although he alluded to them here.

The session covered some of the reasons that Java has become the great language that it is today, the downfalls of Java (yes there are some), and where other languages pick up the slack. His main point for evaluating these new tools is the X fold productivity increase if you use a language like Ruby. Generally speaking this is a great thing, except, I'm still not convinced that Ruby code will be readable enough (reusability), or scalable, and I know for a fact that Ruby on Rails has serious issues with SQL injection (two different speakers this weekend have alluded to it).

There are two major breaks from Java that I thought were very interesting. The first is
Metaprogramming which I think it will be quite interesting to watch as it evolves. I didn't get a hard definition of metaprogramming, and I found a wiki entry on metaprogramming but it wasn't that useful, so let me give you an example from the session instead. He created a string object with the value "Elephant". Then, in a live code demo, he wrote the couple of lines of code to change the Class definition for the String type, so that when you evaluated it (i.e. tried to get the value) it would return "Unattended keyboard error." So, then he printed out the string object (mind you that was created before he mucked with the string class definition), and it printed out "Unattended keyboard error."

Cute.

Allows you to do some really interesting AOP and dependency injection stuff, but I especially liked what he had to say about it:
"Is Ruby going to let me maul myself...Yes, they'll let you run with scissors. Sometimes, it's a more productive way to be."
Wow! I disagree with this principle so much. The sort of damage you could do so very easily with this sort of thing scares me quite a bit (as it probably should). To be fair, he did qualify this example, after the fact none the less, with a comment that this was stuff that the Rod Johnson & Gavin King type folks would do in Ruby, not the typicall programmer. But still....I dunno.

Second thing, and I've already alluded to this in my previous post. Continuations are absolutely the greatest thing since sliced bread, and I want them in Java, tomorrow. Ok, first let me explain what a continuation is, it's pretty simple really. A continuation is a snapshot of the execution context (would be the hash in Java), allowing the program execution to continue, but then backtrack or pickup from there very easily. The best example he had of this was a tool called Seaside (for Smalltalk), although there is one for Ruby as well (Iowa).

The Seaside demo app was a counter displayed on the web with ++ and -- links doing exactly what you'd expect. He clicked the plus button a few times, until the value was 8, then the back button to go back in the history until the value on the page was 5. At this point he asked what is going to be the value on the page when I click the ++. Most of us were certain it would be 9, given that the session variable only knew he had gone to 8 before, and shouldn't have been aware of him backing up to the point when it was only 5. He clicked the link, and there was the 6. As it turns out Seaside snaps a continuation after each of those pages, a far from realistic model, but interesting all the same. When you hit the back button, Seaside was smart enough to realize that you are moving backwards through the continuations, and so it reverts the session variables to their previous values. Pretty slick, but later in the day Bruce commented that Seaside is the best framework that will never get used. Still, how ridiculously nice would it be to have something like this in Java. Anyway, I digress.

The final thing I want to mention about this session is something called programming by convention, which is something Ruby takes heavy advantage of, maybe to its detriment. Programming by convention is the idea that if you have a convention for how you name things, then the language can logically infer things about it, and/or related things as well. For example if I have the class Trail, and I tell Ruby that I'd like to persist it to the database, it can infer that I want to write this Trail object to the trails table. Pretty sweet. Worth looking into, just to see what benefits it could have on the Java side of things. Speaking of which, a tool for doing programming by convention in Java is coincidentally called Trails as well. I'll

Primarily this session was about what other languages are doing right that Java still has horribly wrong. A lot of these things will be rather difficult to do in Java, but they are the hurdles that Java will have to jump in the next 3-5 years if it wants to continue leading the pack. It'll be an interesting ride.

1 Comments:

Anonymous Anonymous said...

Unless you heard about the Rails SQL injection problems from Dave Thomas, I'd say that what you heard is probably FUD. I belive that it had some problems early in it's life cycle (you had to escape things yourself), but now ActiveRecord, if used correctly, handles everything. There are a few cases when you can't use ActiveRecord and you need to escape things. But you can't blame Rails for a user avoiding the framework to do something stupid.

And, I've found Ruby to be the most readable and maintainable languages I've used. But, everyone working on a project should probably be pretty familiar with the Ruby way of doing things or things will get messy pretty quick.

Just gotta defend Rails a bit. Doubt anyone else reading this will.

11:22 AM  

Post a Comment

<< Home