Posted 2010-06-16 18:42:34 GMT
1 watching live
The Scala programming language has all the features of Java, and supports all sorts of fun things like closures, higher-kinded types and inline XML. If you're starting a new project for the JVM, shouldn't you just use Scala?
The Scala environment is very interesting and in 2.8 has the ability to pass around unboxed primitive types through to functions that are specified over multiple types — so that generic functions no longer have a massive performance penalty.
Scala has operator overloading, and even the ability to give the appearance of adding new methods to existing types via the implicit mechanism.
These things make the task of writing code much more convenient. There's less need to explicitly distinguish between arrays and other sequences and unboxed doubles and other numeric types. Papering over the division between arrays, primitive types and reference types in the JVM actually reduces to some extent the conceptual complexity of using it.
But these ideas are fundamentally opposed to the reason Java came into
being. Scala positions itself as multi-paradigm programming
language designed to express common programming patterns in a concise,
elegant
way. Java is culturally opposed to these ideas: it is
deliberately simple.
The Java design team examined many aspects of the "modern" C and
C++ languages to determine features that could be eliminated in the
context of modern object-oriented programming
while still
retaining some similarity to C++ syntax.
In particular, a founding principle was that everything should
be very explicit: A major problem with C and C++ is the amount
of context you need to understand another programmer's code: you have
to read all related header files, all related #defines, and all
related typedefs before you can even begin to analyze a program. In
essence, programming with #defines and typedefs results in every
programmer inventing a new programming language that's
incomprehensible to anybody other than its creator, thus defeating the
goals of good programming practices.
This definition of a good programming practice is one that Scala vehemently opposes. The ability to write domain specific languages that integrate with the core is promoted as a positive.
In my opinion, the definition of a good programming practice should include whether or not it gets results. After the HotJava experiment failed perhaps it's time to admit that all three major webbrowsers (Mozilla Gecko, Webkit, and Internet Explorer) are all written in C++ for real reasons and not just force of habit.
Java was supposed to start small and grow as a reaction against the perceived causes for which languages like Lisp and Smalltalk were rejected. Scala is proud of the power of its higher-kinded types: Java is proud of removing multiple inheritance. They're not really competitors: the cultural gulf is huge.
Perhaps Scala will be able to drag the JVM into competition with numerous other platforms. It has a good set of web companies (for example, Foursquare) using it as a replacement for programmer-orientated scripting languages, and that's where Scala has a natural fit, albeit with strong-typing.
Java is deliberately not programmer-orientated. That's the point of using it — it was designed to restrict the kind of trouble programmers can get themselves into. If you're stuck with the JVM, I guess the question is: how much rope do you want to give your programmers? Scala is essentially the opposite answer to Java.
Post a comment
'Give your programmers'? Who is choosing the platform here? Sounds like it's not the programmers, and that's a deal-breaker.
Posted 2010-06-16 21:21:46 GMT by Anonymous from 76.65.227.177
A programming language that isn't programmer-oriented--what a great idea. So was COBOL.
Posted 2010-06-17 03:31:26 GMT by Anonymous from 68.82.121.17
The companies adopting Scala are not using it as a replacement for scripting languages, they're using it to write complex high performance systems: foursquare uses it for their website, LinkedIn has many of its systems in Scala, Novell Pulse is entirely written in Scala, etc. Twitter replaced it's backend with a Scala solution. There's plenty of examples...
Maybe Java 1.0 started with the goal that everything must be explicit, but that's not the current Java, it has its own share of warts.
Let's not even consider autoboxing and generics, start with something as simple as "Hi "+ 2.
1) there's operator overloading: the same operator "+" does something different than 2+2
2) The "int" is converted to a string
3) The string concatenation creates internally a StringBuffer and concatenates it... hardly explicit.
But I think the cultural gulf is clearly evident at the end: you consider that a language must restrict what programmers can do with it. I believe that more powerful languages give you more freedom to solve complex problems in a more effective way.
If you can't trust your programmers, you have a bigger problem and I'm pretty sure they can create unmaintainable code in Java or any other language...
Posted 2010-06-17 04:08:18 GMT by Anonymous from 76.122.83.249
I have seen many poorly written Java programs in my years. However, unlike terribly-written C++ or even Ruby programs, this awful code was at least sort-of understandable and wasn't much of a battle to rewrite properly. In my opinion it's not very easy to write a totally unmaintainable program in Java... unless of course you compile it to bytecode, obfuscate the hell out of it and then JAD it back to source, throwing away the original. John, I'm afraid you might be right about Scala. That bothers me. I was really hoping that Scala would be the successor to Java and I'd be able to migrate my half-million-line cash cow over to it piece by piece (once they straighten out the IDE issues of course) but even with me being the primary developer I think Scala might cause more harm than good to its future.
Posted 2010-06-17 04:18:26 GMT by Anonymous from 12.144.107.130
Perhaps the title of this post should be "Java is simpler than Scala, IMHO" rather than "Scala is not a better Java".
Posted 2010-06-17 11:13:20 GMT by Anonymous from 82.20.76.209
I really like Java for the simplicity reasons you list. It is a great language to develop in a complex 'enterprise' environment. Perhaps Scala can attract some to the strays - e.g. Python - back to using strong typing.
Posted 2010-06-17 12:44:04 GMT by Anonymous from 78.105.116.231
How about the anonymous classes introduced afterwards, Generics introduced afterwards in Java? Even more so, how about the new closure functionality in Java. Don't these enhancement contradict Java's staying simple rule then?
Posted 2010-06-17 19:46:04 GMT by Anonymous from 119.160.51.159
While the complexity of Scala can easily lead to programs with all the readability of, say, Perl (and I don't mean that in a good way), Java's simplicity is no panacea. I've spent more than a decade coding in Java, and I've seen my share of hard-to-read code that the simplicity of the Java language did nothing to ameliorate. Examples include (but are not limited to):
* Spider webs of anonymous inner classes, interwoven with poorly named variables and enormous undocumented methods, leading to a vast unreadable mess.
* Duplicated code, because Java interfaces can't contain executable code (unlike Scala traits or Ruby modules) and because the subclasses were already inheriting from different parent classes.
* Extended string classes that must wrap the entire java.lang.String class, just to add a few methods that java.lang.String doesn't have (versus shoving those new methods into a static class, C-style), all because String is final and cannot be extended. Scala also addresses this problem. Hell, C# addresses this problem, too.
* IOC frameworks, like Spring, which, misused, lead to hard-to-debug large-scale systems that are wired together and interconnected in non-obvious ways.
* Class after class after class with single-line setters and getters galore, all obscuring the actual business logic that serves as the reason the class was written in the first place--and all violating the uniform access principle. Scala, Python, Ruby and C# all address this problem quite nicely, leading to a reduction of extraneous code which, in turn, enhances readability and maintainability by obscuring LESS of the actual business logic.
Java's simplicity did nothing to prevent or ameliorate these problems.
Yes, there's something to be said for simple languages. But sometimes, oversimplification causes as many problems as it alleviates.
Posted 2010-06-17 23:06:22 GMT by Anonymous from 108.2.224.113
Someone already said it, but I'll say it again: the complexity of Scala can easily lead to programs with all the readability of Perl (in a bad way). In this way, Scala is definately worse than Java. Sure Scala has lots of cool features and fixes some of the warts of Java - but at what cost?
Posted 2010-06-19 04:17:28 GMT by Anonymous from 74.232.10.171
Complexity comes from many places. I think the real world experience is not predictable and the results depend much on the culture created.
I spent yesterday debugging a production issue with a Java system that copies data from one database to another. It does this with two programs, one of which is a Web Service server and the other a client. Both ends use complex stored procedures and the web service uses a complex authentication and authorization system based on Kerberos tickets etc, which, after hours of work, we determined was the cause of the fault. The web service has exactly one client.
Lets not forget Java is a market failure as a client side language, which was its original target.
Many features missing from Java are more about not enough time than a deliberate omission.
I think the apparent ease of maintaining Java programs compared to the C/C++ programs I maintained before, comes down to mainly that Java protects its abstractions.
The failure to re-compile a Java class or fix a header results in clear message. A similar failure in C/C++ results in corruption which shows up much later. The other main feature helps is garbage collection removing many memory leaks and corruptions.
Scala's additional features will reduce the need for tools outside of the language (spring config etc.) and this will help programs more maintainable. This must be balanced against whether use and mis-use of power reduces maintainability. My money is that Scala is a better Java in the real world.
Posted 2010-06-22 23:20:51 GMT by Anonymous from 124.188.97.90
"Lets not forget Java is a market failure as a client side language, which was its original target."
Java (originally Oak) was targeted at embedded.
Posted 2010-07-01 03:30:44 GMT by Anonymous from 99.54.151.26
"Java (originally Oak) was targeted at embedded."
and at this Java has been extremely successful. cellphones, kindle, blu-ray, smartcards, etc. oh my.
Posted 2010-07-19 18:31:48 GMT by Anonymous from 65.165.176.62