Will Java change, stay the same or be replaced?

Disclaimer: my opinions on programming languages are based on intuition and casual observations more often than on deep knowledge and experience, so please take everything said below with a grain of salt.

I think Java is definitely the programming language and platform for most applications right now, be it server, desktop or mobile. C#/.NET is comparable and C# as a language may actually be a bit better when it comes to features, but as long as it’s controlled by Microsoft and at the same time Java is more open, less controlled, and the JRE has many implementations, most people and organizations will (or should) choose Java.

All the other more or less popular languages certainly have their place as well. C and C++ are good for writing efficient and close to hardware programs — Java may actually be faster than C++ in some rare cases, but it will always have some overhead simply because it runs in a VM and is managed. JavaScript, Perl, PHP, Python, Ruby etc. are either well suited for some tastes or have some specific advantages for certain applications or development styles. Functional languages and more specialized languages will not go anywhere either, they are needed too.

But Java is the general purpose language that can satisfy almost any requirements and scale in most directions (if not quite down to scripting).

However, Java has problems as well.

Continue reading

Learning Scala: Compiler Surprises

Scala seems to be getting a lot of publicity lately. I’m glad for that, because the more I learn about it, the more I realize that it’s a really great language and needs more attention. Some other bloggers have already written introductory articles and talked about various aspects of Scala, but maybe I’ll have something to add. I’m planning on using Scala alongside Java in personal projects, but at the moment I’m just learning and experimenting, writing short pieces of code to try out the various language features.

Coming from Java programming, even after learning the basics and perhaps some of the advanced concepts of Scala, one can run into some really surprising compiler error messages because of the way Scala works. I ran into one of these issues and thought this would be an interesting way to illustrate some features of Scala. Note: for clarity, I’m using type annotations in this blog entry where I would normally leave them out.

After executing the following code, it’s natural to expect that i will have the value 13, as we’re used to in Java, C++ and other languages:

var i: Int = 1
i += 10 + 2

In Scala, the above code will actually produce a compiler error:

error: type mismatch;
found : Int(2)
required: String
Continue reading