1

John Fremlin's blog: Scala is not a better Java

 3 years ago
source link: http://john.freml.in/scala-is-not-a-better-java
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Posted 2010-06-16 16:43:00 GMT

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.

'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

After Ruby has proven its worth, I do not see why Scala cannot take the same path as a saner (decent IDE support!) and faster alternative.

Advocating Java nowadays is an act of pure resistance to change. Java is not a simple Language for a long time. It is just simple for the ones who just focused on it and do not want to change. If it were to the ones like you, we'd still be programming with punched cards.

Computer programming is for people who are open to change: In a lifetime, it is almost impossible that one will work with less than 3 languages along its professional path.

Posted 2010-10-03 11:57:53 GMT by Anonymous from 89.180.196.59

I believe that Bad Programmers will always make Bad Code, independent of the Language being used.

And from my experience I found that around 80% of the developers I know write Bad Code by default. People who I choose to be on my team are always brainwashed in the art of writting code, at least decent code.

With this in mind I have to say that Scala is powerful, complex and gives the programmer the choice to do things on his own way. This is what everyone wants. The problem is that when it goes to mainstream there will be 80% of people writting bad code by default, and since the language is so flexible it will quickly become big hard-ass huge mistake code, that good programmers will eventually have to fix and see themselfs inside a nightmare.

For good developers Scala is just a matter of learning the syntax, I've started with VB and C, made some .NET and have been using JAVA for more than 6 years now, and I find Scala a bit weird from the examples and source files I see. I believe they could have come up with a cleaner syntax to perform the same thing, but hey, the beauty of it is that I can code it in other ways, there are several options.

Again, the fears surrounding good developers when looking at Scala is how bad things can get worse on the majority of programmers these days, and in the end the job of fixing major problems always ends up in the hands of these good programmers.

If Scala goes mainstream, I guess we will see alot of good programmers changing jobs :).

Posted 2010-12-15 15:50:55 GMT by Anonymous from 87.103.109.21

You cannot rightfully call Java simple anymore. Smalltalk is a simple language. R3RS Scheme is a simple language. Java is not a simple language. It's complex, without the rewards.

Pascal Costanza

Posted 2011-01-23 18:21:02 GMT by Anonymous from 87.64.40.157

Premise: I do like Scala very much.

Now, I am sometimes afraid of the complexity of Scala. Especially I'm not yet convinced about implicit conversions.

For many other things however, you have a theoretically-founded elegant complexity: Scala's design is made to fit in somebody's head and to be easy to reason with, because most of that comes from theorists. C++'s design is not so, it is rather a design overloaded with historical cruft. Additionally, writing correct code is fundamentally more complex for little good reason, and the lack of some optimizations forces people to use very complex features (like template metaprogramming).

Admittedly, advanced features are intended for (good) library programmers, as explained by Odersky. If you have bad programmers, do the same thing as you'd do in Java: forbid them using advanced features in your coding guidelines. The only defensible reason to hire bad programmers at all, actually, is lack of good programmers - money is likely no point since you need 10 bad programmers to replace one good one (a 10x productivity ratio between good and bad programmers is often quoted), and you still get worse code.

However, I am more afraid of the "simplicity" of Java. Java is a psychological reaction of people scared from C++. C# has operator overloading and nobody cries. Guy Steele, who's behind both Scheme and Java, advocated operator overloading for Java, too.

Finally, one key thing that you omit is that Scala is also functional, and that's a key point. The ability to abstract algorithms better is fundamental.

Posted 2011-02-22 07:38:24 GMT by Paolo G. Giarrusso from 95.117.73.21

"java is a failure as a client side language" - android baby

"class after class after class with " - Java Bean model is not Java. You can be as terse as you please in Java. Webservers in a single file, if you wish (full OO).

Fundamentally, SUN failed to promote the projected/expected/hoped-for development of a component based market (from Applets to Beans) supported by the tool vendors. All of the defining specs of Java in the enterprise were written expecting that future that never materialized.

You weren't really supposed to muck around at source level looking at class after class after class all written in a standard component model (Java Beans to EJBs). You weren't really supposed to muck around in XML and Java. SUN architects had this utopian notion of role based development model with developers, assemblers, packagers, and deployers each working in a specialized silo producing components and apps made from components. If Steve Jobs was running SUN, you would have your AppletMarket and IBM and BEA and whoever would be towing the line and supporting the Java vision. Instead IBM comes out with "Eclipse" and makes sure Swing is backstabbed effectively. (.NET/C# hugely benefit from MS Universal Tools Mothership.)

Java is effective because it certainly provides enough deep hooks to keep even the certified geek happy and fascinated -- hacking byte codes ; fun! very powerful -- up to insuring that any reasonably competent programmer in the IT factories can crank out useful code at a reasonably (and predictably) productive rate for a spring container.

Scala is an /unreasonable/ language as it clearly demands full devotion and dedication for a /substantial/ period of time, even to the highly experienced. Is that demand for such an investment of time really reasonable anymore? One can pick up Go, or even Erlang for God's sake, in literally a day or two and write libraries! Try that with Scala (and don't give Java scala -- I mean real Scala).

(DSLs are nice, but mother-of-all-DSLs is too big to handle. And she can do functional too! And OO too! Take a call at 2 am to look at the server code in Scala written by god knows who? /great/ idea ... ;)

Posted 2011-07-25 01:44:48 GMT by Anonymous from 24.184.145.69

In other words, John Fremlin's position is (so far) entirely accurate if we consider the economic propositions of a language.

Scala presents rather unattractive economic propositions to both (a) developers and (b) companies. (a) is evident from the learning 'journey' (forget curves) of Scala. Why not Haskell, then? (b) The cost of labor and maintaing these Scala systems shift the

Companies that wish to specialize in Scala for high end work, however, are provided a much better economic proposition. (a) their work will be sticky (as will be obscure to the unlearned in their 'dialect' of Scala) and (b) there is a huge barrier to entry for any competitor. (This can't scale to IT factory but definitely wall-street, (effectively) infrastructure work ala LinkedIn or Twitter, etc.)

Based on above, it clearly can not replace Java.

Posted 2011-07-25 02:05:35 GMT by Anonymous from 24.184.145.69

Post a comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK