Wednesday, April 25, 2007

Old world of Java





I've been coding in Java language for some time now. To be honest I many times complained about features that it just doesn't have. It's really easy to pick some things that are missing there. Hey, but it is going to be better. Recently I've been reading Neal's blog and as I can clearly see it is going to happen. The world of Java is going to receive plenty of goodies in a new Dolphin release, but why wait. Groovy, Nice, SISC-scheme of course are already there. They are not fully featured but they do have "the meat". I don't have to say that sic-scheme is my favorite one, but it is also the most scary one for the typical Java developer so lets begin with something easier - Groovy.

Groovy workspace

This framework is really easy to use and it has a pretty good documentation. So it has plugins for Eclipse, Idea, Emacs, JDeveloper and plenty other editors. Be aware that it is really hard (and I do mean it) to create a good plugin for a highly dynamic language (take a look at those for Ruby, thats what I call fun) so be prepared that sometimes they have hard time telling you what attributes or methods some object has. Right, First cool thing is literals for lists and maps (no need to construct a class). Finally I can create a list just by typing:

By the string "->" I mean "returns".


foo = [1, 3, 4, "sigma", "lambda"]
foo[1] -> 3
foo[3] -> "sigma"


And yes lists are polymorphic just as dictionaries called maps here.


bar = [123:4, "gamma":"omega", "pi":3.14]

bar["gamma"] -> "omega"
bar[123] -> 4


or in a shorter way

bar.gamma -> "omega"

unfortunately when you try to execute

bar.123 an error will accure


This syntaxt is much more modern and in my opinion much better then typical construction with "new" prefix. Im also glad that dynamic and static typing is supported - hey, maybe one day I will be able to do all the tricks that I can do with VB.NET language (now don't laugh it's sad but it is true), but as for now Groovy is not quite yet there.

Next thing that I really missed from python was the string agility, basicly I could use " or ' character as a string and If I wanted to create some complicated string I could just put it into """ block. And here it is ready to use in groovy.


name = "Basho Matsuo"

someXML = """
Fallen sick on a journey,
In dreams I run wildly
Over a withered moor.
${name}
"""



Next sexy thing to investigate is a support for closers - Ladies and Gentlemens finally, Java stops to look like Logo language and introduce some meat that makes your job easier.

1 comment:

Unknown said...

When Java begin's to looks like Python, it't quit good trend :)
I recomend You to read "Beyond Java" (maby you read it already).