marți, 28 iunie 2011

Scala and Ceylon vs Java - ups, downs and awkward design flaws

I am not trained as a computer scientist. All the Java I know, I have learned on my own, ignoring my social life Friday evenings, for quite a few months.

I am the kind of guy that before buying, really goes on a research spree. I did the same before learning some Java, and I'm doing it now, while learning.

What i mean by research is trying to find the best language there is to learn. Google taught me soon enough that the concept of the perfect language to learn is just like the concept of a perfect woman (or a perfect man for that matter) - having some faults is simply always a part of the deal.

But that's not to say that there can't be anything "better" in some way than Java. People complain about the lack of modern features that the language has, like the lack of support for language modularity, lack of support for functions and higher level functions, the awful java.io package, the messed-up synchronized word, the intrinsically inextensible nature of some constructs (the switches, loops and basically all the reserved words), the complex nature of some packages that try to solve some problems that "maybe" shouldn't be problems at all (java.util.concurrent), etc.

So Java came out in the early 90's. One would ask himself what stopped other people from developing another language that's comparably efficient (or more so), and that allows programmers to focus on truly useful design patterns to solving problems, rather than trying to convince java to let you solve a simple problem?

For this reason i had a look at some 2 newer languages that were hoping to become a "java killer". One of them is Scala, another is Ceylon.

Admittedly, Ceylon we've only made acquaintance with Ceylon this year, and a compiler isn't even out by the time i'm writing this. However the grammar of the language is there for both of them.
Also, i'm not gonna go into C# for now. I know next to nothing about it, mostly some syntax, so I think i look noobish enough just talking about these other 2.

First, Scala:
Now the guys at Twitter seem to like it.
Here is an interview with 3 Twitter developers.
They were working with Ruby on Rails, and found Scala great for threads, type safety, features and closures.
All purpose intended, Scala seems to be a successful attempt at dethroning Java (not that it was developed for the sole purpose of dethroning Java, but as the world programming community develops, as new and old ideas are tested in practice rather than just theory, and as older languages simply can't keep up the pace, they inevitably get replaced)

I've looked over the features of Scala, and my personal impressions are:
At first glance, the structure of the language is very unfamiliar (i have a Pascal - C++ - Java background). Sure, Scala runs on the JVM, but that doesn't mean the code and the concepts resemble.
Another silli thing about Scala is that whenever trying to cook up your own function, what you'll be doing is actually extending a template of a function already defined in the language. Doesn't sound too bad, right? Want me to get to the silly part? ok.
There are in the Scala language about 30 definitions like this
Function()
Function(Arg1)
Function(Arg1, Arg2)
Function(Arg1,Arg2,Arg3)

and on and on.... so you realize that Scala doesn't have something as basic as varargs. and EVERYBODY loves varargs. You just can't drop that feature and expect people to not give you a thumbs down. This isn't 1980's anymore.

Scala has that very nice feature of allowing you to "name" blocks of code, and to set parameters to them. "but hey, that's what methods are for in java".... yes and no.
"yes"- of course, for the obvious reasons.
"no" - because java limits your imagination. What i mean by this is, if you've ever wanted to add an ActionListener, as an annonymous inner class AND to pass an argument to that class, let's say a reference to something that needed to be updated, you know what i mean.
It's stupidly annoying to do without having to write another convenience class, that maybe you're never going to use again.

Those things called "closures" are planned for java 1.8. But since there's yet no such thing even as java 1.7 (official release), one has to give a thumbs down to someone.

All in all Scala has been developing for some 5 years or so, and seems promising enough. Twitter loves it, and that's a big plus, but it's very bad for your name to create a language with one of the most loved features taken out. Also since it's alien enough compared to java, that doesn't make for a nice advertisement for the language. We'll see how it develops over the next years

Now onto Ceylon:
Since it hasn't yet been released, but only showed through the incubator glass, much of what i'm going to say will simply be guesses.
Reading through a presentation about Ceylon given by its creator, Gavin King, in China this year, the language seems to promise a lot. Gavin King claims to have designed the language using all the lessons from Java, the good ones and the bad ones.

Now with all the fuss about this, I would expect them to both deliver, and not mess up in new and never before discovered ways... and in both of those cases they have.
I won't go that much into the language. Seems to be less verbose than Java, seems to deliver what it promises. You can have blocks of code like this
repeat(3)
perform(){
//something something
}

which reads like this: repeat 3 times this anonymous function that i'll just write here and you can call it "perform" if you wish, but doesn't really matter.... so just do what it says 3 times.

which is awesome. the perform() function can receive arguments, which means you can create new functions on top of the old. It specifically doesn't support lambda functions, and even if i "kinna" know what those are (i'd like to say hello to my friend wiki), i can't say i have any experience using them. I hear they're good though.

With all the concern for learning from java, I feel like they made an embarrassing mistake though.
Do you know those little convenience methods called "getters"? I'm sure you know and like them. They are so easy to grasp as concepts.

The made them look like this
apple.getColor
Whereas in java they look like this
apple.getColor()

Can you spot the difference?
There's no distinction between a getter and a field. I find that very awkward for people who have to maintain the code, or understand code that's not their own.
The old java way of calling methods with parentheses at the end had a purpose: that you'd know how to differentiate between a field and a method, so that you don't try to change the value of a method, and so that it's more transparent to you what you're doing.
Sure, it's not a big thing. you can make every getter have a standard name like "getPizza", but still, i think fighting verbosity went too far.

Anyways this is my review on the 2 languages. I will of course at some point, like everyone programming, try to learn some new language and test it out. I'll most likely try these 2 as they promise big. I'd just have loved it it they didn't make any aesthetic mistakes that any noob can spot. I had to learn a lot of java to figure out where its mistakes are, but only had to look 5 minutes at the structure of these 2 languages to find annoying stuff.

Niciun comentariu:

Trimiteți un comentariu