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

Wednesday, January 13, 2010

J4Fry on Twitter

J4Fry is now available on Twitter.
Just follow @J4Fry

Monday, December 14, 2009

CVS log commit messages

Every now and then when making a release I need an alphabetical list of all CVS commit messages since a particular previous tag. This is what I use (for tag 'mytag'):

cvs log -rmytag:: -S -N | grep '^RCS\|^Working\|^head\|^branch\|^locks\|^access\|^keyword\|^total\|^description\|^-------\|^========\|^revision\|^\?\|^date\|^$\|\*\*\*' -v | sort -u

Is there anybody on this planet with a more elegant solution?

Best regards,
Ganesh

Tuesday, June 23, 2009

Hibernate Event Listeners with Spring

You can configure your Hibernate event listeners via your spring-context.xml.
When you declare your Bean from type org.springframework.orm.hibernate3.LocalSessionFactoryBean you can initilize the property "eventListeners". This attribute is from type Map. The key defines the type of the event listeners (e.g. flush, load, delete, etc.). The value defines the corresponding class which implements the EventListener interface or extend the DefaultEventListener implementation class.


Sample of your context.xml

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
...
<property name="eventListeners">
<map>
<entry key="flush">
<bean class="org.j4fry.hibernate.eventlisteners.FlushEventListener" />
</entry>
</map>
</property>
...
</bean>
Sample of a FlushEventListener

package org.j4fry.hibernate.eventlisteners;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.event.FlushEvent;
import org.hibernate.event.def.DefaultFlushEventListener;

public class FlushEventListener extends DefaultFlushEventListener {
public void onFlush(FlushEvent fe) throws HibernateException {
super.onFlush(fe);
}
}
List of keys and the corresponding Interfaces and implementation-classes
Map-KeyInterfaceDefault implementation class
auto-flushAutoFlushEventListener
deleteDeleteEventListener
dirty-checkDirtyCheckEventListener
evictEvictEventListener
flush-entityFlushEntityEventListener
flushFlushEventListener
load-collectionInitializeCollectionEventListener
loadLoadEventListener
lockLockEventListener
mergeMergeEventListener
create-onflushPersistEventListener
post-deletePostDeleteEventListener
post-insertPostInsertEventListener
post-loadPostLoadEventListener
post-updatePostUpdateEventListener
pre-deletePreDeleteEventListener
pre-insertPreInsertEventListener
pre-loadPreLoadEventListener
pre-updatePreUpdateEventListener
refreshRefreshEventListener
replicateReplicateEventListener
save-updateSaveOrUpdateEventListener

Saturday, June 20, 2009

IE8 script cache and AJAX script replace

Today I tried debugging the MyFaces 2.0 AJAXS scripts in IE8. The debugger is quite nice. The hard side came in when I starting changing the scripts and tried testing my new script versions. IE8 prooved to be a resilient beast like it's anchestors and insisted on running an old script version. The nice button "clear browser cache" in the developer tools didn't do anything. What finally helped was the first menu option in menu "cache" - in german it says: Immer vom Server aktualisieren.
Now that I could step into my Javascript code things got even weirder. I had a simple

<span id="test"><script ... ></span>

construction and I tried do replace element "test" with an AJAX call. So what do you think happened? I did:

item.insertAdjacentHTML('beforeBegin', '<span id="test"><script ... ></span>');

and then checked item.previousSibling. I turned out IE8 had inserted:

<span id="test"></span>

It just left out my new script. I changed the HTML code to look like (don't ask me what gave me the idea to do so, years of suffering train intuition):

<span id="test">
<input type="hidden" />
<script ... >
</span>

and suddenly IE inserted it all like it should. If you want to know which tricks are necessary to trigger script execution have a look at the MyFaces repository:
http://svn.apache.org/repos/asf/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js

It's interesting code - external and embedded scripts need to be treated differently.