Tuesday, October 25, 2011

((Ceylon vs. Kotlin) vs. Scala) vs. The Rest of the World

The blog title sounds a bit like buzzword bingo, doesn't it? Damn, I forgot to mention Gosu.

There are quite many new brand-new-must-have-technologies these days.
There are Android, HTML5, PhoneGap, CoffeeScript, node.js, Websockets, Flex, Adobe Air, REST, JSON, BSON, AMQP, RabbitMQ, JEE6/7, Cloud (you know, everything is in the cloud today), NoSQL, SaaS/PaaS/IaaS, and of course, Ceylon, Kotlin, Gosu, Clojure, Scala, Groovy, JRuby and all the other JVM based programming languages.
So, how should look a really, really cool application? Android Mobile Frontend written in Scala, REST Interface to get some data from a server which is written in Ceylon which access a NoSQL HBase Database via Map/Reduce to read&write Big Data. Our server is hosted on AWS (plain Tomcat, Glassfish or JBoss AS on AWS or should we use OpenShift from RedHat rather than Amazon?), of course. Oops, I forgot a non-smart-phone client. Ok, web-based client written in... hmmm... JSF? GWT? Wicket? JavaFX 2.0? Flex? Silverlight? or just plain HTML5 with a ass kickin' Websocket connection to our server? Ok we pick HTML5. But when I wanna pick HTML5 and I do not wanna write so much JavaScript by myself (even if the new JavaScript API is pretty cool in HTML5) I am gonna need a full-fledged JavaScript Library/Toolkit. No problem at all. What do you want? jQuery, dojo, ExJS, MooTools, scriptaculous or YUI? Whatever... just pick jQuery as everybody does... (BTW I did not mention AJAX because it is not buzzword-noteworthy anymore. Even Comet/Bayeux got the kiss of death from Websockets...)

Puhhh, buzzword scrabble finished and application architecture defined. Nope. We have made a mistake. There isn't a compiler for Ceylon yet. Someone told me Ceylon is a vaporware until now. Ok, replace Ceylon with Kotlin. Ops, there isn't a compiler for Kotlin as well. Doesn't matter let's assume that I can run my Ceylon/Kotlin code (instead of just write them down on some slides). What should we choose? Ceylon or Kotlin? In the following you will find a short feature comparison. It is a non-offical and subjective comparison from my point of view. It relies on the information which is available until now. Found any mistakes? Just leave a comment!

Enough said. Here is the comparison. BTW I did not include Scala because it is "to academic/function/not functional enough/..." ;-)

Comparison is not finished yet. I will update it from time to time.


Ceylon
Kotlin
Source Code organization (Java's packages)
derived from the file path of the source code file e.g. Class Person in package org.j4fry.mypkg must be in directory org/j4fry/mypkg/Person.ceylon
import org.j4fry.mypkg { Person }
uses namespaces e.g.
namespace org.j4fry.Person
with import statement
import org.j4fry.Person
Semicolons
mandatory
optional
Return types (Java's void)
uses void keyword which is, in fact, a return type named Void
shared abstract class Void() of Object|Nothing {}
uses Unit
Unit is a tuple of zero components (Tuple0) e.g.
fun myFunc( ) : Unit {… }
String interpolation
shared variable Natural c := 10
writeLine("Value of c " c "!");
var c = 10
print("Value of c ${c} !")
Using types and type inference
like Java
String s = "Ceylon"
With type inference
local s = "Ceylon"
Like Scala:
val c : Int
With type inference
val c = 10
Mutable and Immutable
Mutable: local, variable (with := assignment)
class C { shared variable Natural c := 10 }
Immutable: without variable
class C { shared Natural c = 10; }
Mutable: var
public class C(){private var c : Int = 0;}
Immutable: val
public class C(){private val c : Int = 0;}
Fields and Properties (Java's Getter&Setter Freak-Show)
Actually there are only properties (like in C#)
public class C() {
public val mutable_name : String
public var immutable_name : String
get() = …
set(value) { $immutable_name = value }
}
Accessability, Visibility & Modifiers (Java's public, protected, private and default scope)
Doesn't know the usual modifiers. Uses instead the shared keyword which controls the visibility of attributes, methods, classes, etc. depending on the context e.g.
non-shared class à class only visible to classes in the same package
shared class à class visible to other packages
shared class C( ) { … }
Uses Java's access modifiers private, protected and public. Additionally internal modifier. Probably internal works like the C# internal modifier e.g. visible in same namespace?
Enums (Java's enum)
Not included. Use of clause (mention subtypes in the base-class signature) in combination with anonymous classes.
Like Java enums on steroids. You can subclass enums in Kotlin and there are some other enum features in Kotlin e.g. member overriding, enum pattern-matchin, etc.
Inheritance
Uses the extends clause in class signature but different annotations to declare overridable and overridden methods.
class Base( ) {
shared default String doSth() {…}
}
class Subclass() extends Base() {
shared actual String doSth() {…}
}
Overloading
Not supported. Use optional parameters instead. Comment of Kotlin FAQ: "Ceylon is Java-incompatible, because it does not support overloading"
Interfaces


There are some heated discussions about Ceylon and Kotline already.

Pro Ceylon

Contra Ceylon


On the following websites you could find the resources which I have used to create the above mentioned comparison:

Resources Ceylon

Resources Kotlin

Hopefully you have learnt to understand the irony and sarcasm at the beginning of this blog post. It doesn't matter which programming language you choose. It is only important to try out new things because "Standstill".means("Falling Behind")

cheers Alex

4 comments:

  1. There is/was an issue in the Kotlin issue tracker "Merge with Ceylon" - http://youtrack.jetbrains.net/issue/KT-230?projectKey=KT&query=ceylon - State: Won't fix

    ReplyDelete
  2. Ceylon, out now!
    http://ceylon-lang.org\

    ReplyDelete
  3. Any questions regarding Ceylon? Just use the developer list: ceylon-dev@googlegroups.com

    ReplyDelete