Showing posts with label scala. Show all posts
Showing posts with label scala. Show all posts

Monday, December 27, 2010

Understanding Scala Implicits

Understanding Scala Implicits:

Many languages make use of implicit conversions. Scala is the only language I know of which makes implicit definitions a feature.

It is very easy to understand an implicit conversion since most programming languages do this already for you. Here are two examples (AS3/Java):

trace('Implicitly converted: '+1)
System.out.println('Implicitly converted: '+1);

We only have to care about the expression 'Implicitly converted: '+1 which will result in “Implicitly converted: 1″. Why does this happen? We have a string on the left hand side of the expression and an integer on the right hand side. When the compiler of your choice needs to emit code for this kind of expression it will widen the type of both operands. In this case the resulting type would be String since an implicit conversion from integer to String exists in both ActionScript and Java. If no such conversion exists you would probably get a compile time error.

The compiler inserts this conversion for you. In this example we can make use of an explicit conversion:

trace('Explicitly converted: '+1.toString())
System.out.println('Explicitly converted: '+Integer.toString(1));

[...]

Sunday, December 26, 2010

A Year Of Scala

A Year Of Scala:

About a year ago I started using Scala. A programming language I felt in love with after all. The one and only programming language that started making me smile when I was happy to see how elegant I can express my ideas.

I have been trying to spread the word about Scala during various Flash conferences and always tried convincing my colleagues and friends to learn this great language. A blog post by Alan Shaw about his experience with Haskell inspired me to write about my journey.

Why Scala

I was very unhappy with ActionScript and Java last year. ActionScript is a good start but needs to adapt the features of the dropped ECMAScript 4 proposal to become interesting and competitive in my humble opinion. Java on the other hand is only interesting to me because of its virtual machine. The language itself is simple and has the features you need to get the job done.

I got very late into the Java game and missed the bumpy early years. However I was never earning money with Java since I was doing only open source[...]