May
2008
I’ve been turning that question over in my head for a few months now. It’s really a worthy thought. At face value, it’s incredibly derogatory and implicative of an over-bulked, poorly designed language. While I’m sure this is not how the concept was originally intended, it certainly comes across that way.
But the more I think about it, the more I realize that the parallels are uncanny. Consider the situation back in 1983, when C++ first got started. C had become the dominant language for serious developments. It was fast, commonly known and perhaps more importantly, structured. C had successfully applied the concepts shown in Pascal to systems programming, revolutionizing the industry and becoming the lingua franca of developers everywhere.
When C++ arrived, one of its main selling points was as a “better C”. It was possible to interoperate seamlessly between C++ and C, even to the point of compiling most C programs unmodified in C++. But despite its roots, it still managed to introduce a number of features drawn from Smalltalk et al. (such as classes and virtual member functions). It represented a paradigm shift in the way developers represented concepts. In fact, I think it’s safe to say that the popular object-oriented design principles that we all take for granted would never have evolved to this level without the introduction of C++. (yes, I’m aware of Objective-C and other such efforts, but C++ was the one which caught on)
So we’ve got a few catch-phrases here: “better C”, “seamless interop”, “backwards compatibility”, “paradigm shift”, etc. Sound familiar? (actually, it sounds a lot like Groovy) The truth is that Scala seems to occupy a very similar place in history (if six months ago can be considered “history”). Scala is almost an extension to Java. It brings to the language things like higher-order functions, type inference and a type system of frightening power. Scala represents a fundamental shift in the concepts and designs we use to model problems. I truly believe that whatever language we’re using in a decade’s time, it will borrow heavily from the concepts introduced in Scala (in the same way that Java borrowed from C++).
But if Scala and C++ are so similar in historical inception, shouldn’t we view the language with a certain amount of distrust? We all know what a mess C++ turned out to be, why should Scala be any different? I believe the answer has to do with Scala’s fundamental design principles. Specifically, Scala is not trying to be source-compatible with Java. You can’t just take Java sources and compile them with Scala.
This clean break with the progenitor language has a number of ramifications. Most importantly, Scala is able to smooth many of the rough edges in Java without breaking existing libraries. For example, Scala’s generics are far more consistent than Java’s, despite still being implemented using erasure. This snippet, for example, fails to compile:
def doSomething(ls:List) = { ... } |
All we have done is omit the generic type parameter. In Java, the equivalent would lead to a compiler warning at worst, because Java has to remain backwards compatible with code written before the introduction of generics. This “error vs warning” distinction seems a bit trivial at first, but the distinction has massive implications throughout the rest of the type system. Anyone who has ever tried to write a “generified” library in Java will know what I mean.
Scala represents a clean break from Java. This is in sharp contrast to C++, which was trying to remain fully backward compatible with C sources. This meant inheriting all of C’s weird wrinkles (pass-by-value, no forward referencing, etc). If C++ had just abandoned it’s C legacy, it would have been a much nicer language. Arguably, a language more like Java.
Perhaps the most important distinction between Scala and C++ is that Scala is being designed from the ground up with consistency in mind. All of the major problems in C++ can be traced back to inconsistencies in syntax, semantics or both. That’s not to say that the designers of C++ didn’t put a good deal of effort into keeping the language homogenous, but the truth is that they ultimately failed. Now we could argue until the cows come home about why they failed, but whatever the reasons, it’s done and it has given C++ a very bad reputation. Scala on the other hand is being built by a close-knit team of academics who have spent a lifetime thinking about how to properly design a language. I tend to think that they have a better chance of succeeding than the C++ folks did.
So the moral of this long and rambling post is that you shouldn’t be wary of the Scala language. It’s not going to become the next evil emperor of the language world. Far from it, Scala may just represent the next step forward into true programmatic enlightenment.


Comments
Hm, … I do not think Scala will be the next C++. Following youre argumentation, one could argue that Groovy will be the next C++. Scala could perhaps be Objectiv-C then (- as far as I know it): Much better, butter not used widly.
Groovy introduces the concepts of dynamic languages to Java and trys to have a certain code compatibility. And I think you should a view Groovy “with a certain amount of distrust” - as you said.
I didn’t bring it up in the article, but I happen to agree with you. This is the main reason why I’m leery about Groovy. It really does remind me more of C++ than Scala does, especially when you consider the whole “backwards source compatibility” thing.
Hi, while your comments are interesting, I don’t think your arguments are terribly well thought out or backed up with any sorts of evidence. I for one, think C++ is a very successful language and use it successfully for a number of different projects. I’m not saying that Scala couldn’t become a language that is more successful than C++ (that may be difficult), however statements such as “Now we could argue until the cows come home about why they failed, but whatever the reasons, it’s done and it has given C++ a very bad reputation” are very subjective and opinionated - it doesn’t give me much confidence in the argument you are trying to put forward… maybe if you provided more empirical evidence for example, to back up your claims… Interesting comments, but it just feels like a load of bs to me ^_^ sorry - don’t take this negatively.
> but it just feels like a load of bs to me ^_^ sorry - don’t take this negatively.
Yeah, pretty much. For whatever reason, I wasn’t able to structure my thoughts too constructively when I wrote this. I still hold to the conclusion, but I should have provided some more useful samples to back up my claims. Since I didn’t, feel free to call “FUD”.
b.t.w Scala does look like a nice language… I haven’t used it though.
Maybe Groovy is for Java and Scala what Java is for C and C++. One level up from the original but keeping its main idea and avoiding the pitfalls of the sophisticated parent.
I wish there was a new language that is both powerful and easy to learn without learning its predecessors. I mean by this Java 5 without learning Java 1.4, C++ without learning C, Groovy and Scala without learning Java.
Well, I learned Ruby without learning Perl. I would also argue that you could learn Scala without learning Java, but I can’t speak to that personally. Groovy is obviously quite dependent on its Java underpinnings.
I am a lot more optimistic about Groovy (but I am one of those involved in its evolution). Groovy mostly provides Java compatible syntax (but does make a clean break in some places). It also can be argued that Groovy allows a Java programmer to make a clean break from Java’s static typing if they so choose. I have nothing bad to say about Scala as it has many nice features and is very well designed but I do think Groovy packages up powerful features on the whole in a more accessible form to everyday programmers than Scala does. I am optimistic that both will be around for the long haul and both have a great role to play in the JVM’s evolution.
@Paul: My personal opinion about groovy is, that it is not really “clean”. That is why I think it is more like C++ then Scala. Scala is much much cleaner. It has some features it do not like much. But it is a very clean language in contrast to Groovy. :-\
daniel, i really like your blog content. however, i think your article is poorly titled. there is a bit of a “scala is complex” meme and your title does not help. many folks only skim titles, and you may be unintentionally reinforcing this fallacy.
would like to see more scala examples on:
1. clean break - the language stands on its own and java-like is just an illusion (a great examples of this are the for comprehension, and that everything is an object…)
2. the language is orthogonal - any feeling of complexity in the language is there for a reason (amazing type system, or the ability to extend the language with constructs that look and feel like keywords or DSLs).
3. how simple it is to express things in scala via direct comparisons with ruby and java (you’ve done a bit of this in the past).
keep up the great work.
Post a Comment