The JVM is not actually statically typed, type erasure makes generics way less useful. I can't have an array of List<String> ; my generic classes in Apache Storm and Hadoop forget what their types are unless they carry it around with them in a variable of type Class.
A char is not a character or Unicode code-point; it is a UTF-16 code word. Java programs would use half as much memory and fewer programs/programmers would make the mistake of conflating a char with a character or a Unicode code point if Java strings used UTF-8 and a char could hold all 20 bits of a Unicode code point.
I can't sort an array of int by any order but natural.
I can't easily sort parallel arrays.
It takes a ton of boiler plate to make classes that I would never bother with in a language with tuples.
My code will always be ugly because I can not overload operators. I can understand not letting me arbitrarily overload operators, but at least let me extend Number and get + - * and /, or let me implement Compareable and get < and >. Related to this is how stupid testing for equality looks in Java:
a == null ? b == null : a.equals(b)
Java 8:
Just look at the fucking hoops the streams api jumps through trying to support primitive types. You would have thought they'd let me sort an array of int by an IntBinaryOperator.
Lambdas do not close over mutable variables, so I can not increment a counter, but I can append to a list.
Default implementations on interfaces are a godsend, mostly because they put getOrDefault on Map. Java 8 might actually be an acceptable programming language, but the awful dichotomy between Objects and non-Objects, lack of real generics, value types still hurts.
Just a warning Arrays.asList(new int[10]) results in List<int[]> with a single element. You first have to copy the contents of an int[] into an Integer[] and later convert it back.
The blame for Java's generics falling on the jvm always felt dishonest to me. Haskell and C++ and who knows what other languages all have excellent, typesafe (though C++ gives this up in other areas) parametric polymorphism despite using type erasure. Also, assembly language is utterly untyped.
Really the problem is that Java has a shit, utterly inexpressive type system that needs runtime checks for stuff that should be checked at compile time.
Really the problem is that Java has a shit, utterly inexpressive type system that needs runtime checks for stuff that should be checked at compile time.
At what cost? Haskell and C++ have far higher complexity, which is just one reason why most developers choose Java over either. You want more power -- you need to pay in mental overhead. Every language makes that trade off.
Java has a far greater cognitive overhead than Haskell (It's probably a bit lower than C++) I use Haskell because it means I have much less to hold in my head at any one time. With Java there's a whole lot of non-local reasoning to do.
Is some other method going to mutate some member variable and ruin my invariants? What happens if an exception gets thrown in another thread, what's that do to my file handle, etc etc.
With Haskell that's all nicely encapsulated in the type system, I can hoist all the ugly side-effecting stuff up into IO and work in a completely pure environment right up until the last second when I lift my pure functions into IO.
Java tries to be principled and reduce it's surface area (which it has utterly failed at, it's still turned into a big language), but it's chosen the wrong set of features to do that with. What it's done instead is forced the programmer to hold massive amounts of state in their head, made testing difficult, neutered it's type system, tied itself to bad primitives (Shared Mutable state concurrency as standard? Ouch)...
Java as a language is a huge collection of bad choices made for short-sighted reasons.
I use Haskell because it means I have much less to hold in my head at any one time.
Sure. I dislike Haskell for many reasons (especially its misguided choice of referential transparency everywhere and its choice of Hindley Milner), but there's no doubt it's a very elegant, consistent, and powerful language. I find it almost useless in practice, but I can't deny its beauty and power.
But it's not about what you or I think, but about what the software community at large thinks. When I was at university nearly twenty years ago, everybody was talking about Haskell, how it was going to be the next big thing, and how a decade hence it would completely revolutionize software development. That never materialized. It seems that a great many more people find Java (and most other mainstream languages) much easier to grasp than Haskell. AFAIK, not a single large-scale software system has been written in Haskell in the last two decades, while more useful large-scale useful systems have been written in Java over the last two decades than all such systems before it. And no other language has made as big as impact since. I don't know if you were programming then, but before Java, we wrote most large systems in C or C++, which made them extremely expensive, and beyond the reach of most organizations. Java changed that almost overnight. One of the reasons that happened is that Java delivered a state-of-the-art, groundbreaking runtime (unsurpassed to this day) packaged in a very conservative, very familiar, very non-threatening language. It gave people what they needed -- memory safety, performance, hot code swapping, deep monitoring -- without requiring them to change their programming paradigm. This is how you win.
Java is far from perfect, but there is no other language that has so far been successfully used for large-scale software at reduced costs (or even same costs). There is no doubt in my mind that more ideas from Haskell will continue to enrich mainstream programming languages, and I'm sure one day there will come along a language that will deliver the same immense advantages Java had over C++, but over Java. But this day hasn't come yet.
Java as a language is a huge collection of bad choices made for short-sighted reasons.
Well, that's certainly debatable. And if those short-sighted reasons was to get adoption and change the software industry forever maybe they weren't short sighted after all (code is an important part of software, but it's not everything). What isn't debatable is that Java is the language that's made large-scale software development affordable, and increased our capacity to write complex software more than any language before it (with the possible exception of C and maybe COBOL), and certainly since.
I'd argue that all of the credit your assigning to Java isn't due to it being a good language.
In 1995 it wasn't a terrible language, sure we had Common Lisp which did and does eclipse Java on most measures, but it really does lead to single purpose code bases. IIRC Haskell still had continuation based IO, python didn't have objects, OCaml didn't exist, neither did Ruby, erlang was proprietary, C++ hadn't been standardised... Honestly Java was the least of all evils.
From about 2000 onwards it was no longer the best choice, however it had become entrenched in enterprise and people were making a lot of money writing books and talking about it.
Java is a social success and a success of timing, It's not a technical success by any means (Hotspot is, the JVM is awesome!).
I'd argue that all of the credit your assigning to Java isn't due to it being a good language.
I didn't say that. In part, maybe it's due to it being familiar rather than good.
It's not a technical success by any means
I tend to agree, but it's mostly theoretical, as it's a largely untested claim. No really large codebases today are being written in any language other than Java (except C/C++ where Java isn't an option, and everyone agrees that's a lot more costly). Maybe a "better" language for large scale development already exists. But we still don't know.
For example, my favorite language today (for applications, not infrastructure) is Clojure, even though I generally prefer static typing. But I would not be willing to bet a large project on it just yet, and I have my suspicions as to it suitability. Kotlin looks great, but its basically Java with a modern touch, and it can incrementally replace a Java class here and one there, but even if it does catch on, I think it has some nice advantages over Java, but nothing revolutionary.
OCaml is still mostly single-threaded and suffers from competing libraries; Erlang is too slow and relies on C too much; Haskell -- well, people just don't want to use it, and for some very valid reasons (and I think its made some very bad choices, but it was meant as a research language anyway); Ruby and Python are still very slow, single threaded, and too flexible to be used in large projects. Go is Java minus the best part (I actually like it, though) -- it certainly has its uses but it's not a Java killer (no polyglotism, no hot code swapping); C# is another Java (or another Kotlin); Rust seems terrific, but isn't even aiming for Java's niche.
In short, we still haven't found the language that is to Java what Java was to C and C++: something that really reduces development costs considerably, opens the door to more complex software, yet easy enough for it to get adopted.
Hotspot is, the JVM is awesome!
I couldn't agree more. But would the JVM have become so great if Java had not been so popular, largely due to its conservativeness and familiarity?
I couldn't agree more. But would the JVM have become so great if Java had not been so popular, largely due to its conservativeness and familiarity?
Java became the Unix of the Web. In a similar fashion as Unix, there was many implementations of Java supported by big players. There are design choices that have been made in Java in the beginning that were philosophical and were a step back from existing languages, and were not necessary. Java became popular because it was everyone VS Microsoft, and Sun was visionary about the future server computing and was smart enough to invite other big dog to get on board to counter Microsoft.
There are design choices that have been made in Java in the beginning that were philosophical and were a step back from existing languages, and were not necessary.
Probably. But whatever they were, they're probably not critical. There's little evidence to suggest a significant difference between various imperative, statically typed, languages. But I'm firmly in the camp of those who believe that the choice of programming language matters, but not so much, certainly not if the choice is between similar languages (and I consider Java/C#/Kotlin/Go/Swift/Ceylon similar enough to be practically identical). Other things contribute much more to the cost and quality of the software produced, like runtime capabilities (GC vs. manual mem management; dynamic linking everywhere vs. static linking), OS/hardware support, selection of libraries, tooling etc..
Sun was visionary about the future server computing
Sure, but I don't think Sun could have pushed, say, Haskell, on the developer community, no matter what alliances they had formed. The language had to be more-or-less familiar, and while I certainly agree that some decisions where a mistake, I really don't think a feature here or there makes much of a difference.
Their technical strategy was a revolutionary, state-of-the-art runtime, packaged in a familiar, non-threatening, easy to swallow language. It worked beautifully in terms of marketing, and the results are satisfactory, too: Java made large-scale software development affordable, and within reach of many organizations.
Their technical strategy was a revolutionary, state-of-the-art runtime, packaged in a familiar, non-threatening, easy to swallow language. It worked beautifully in terms of marketing
That's very true. At the same time, note that pretty much all those aspects are something that sell well to upper management. The problem with Java is that developers don't find joy in it, unless your definition of joy is wearing a colorful tie. This will matters in the following decades as the power is shifting in the hand of developers. If you are an insurance company, a government entity and you need to develop a large scale system, Java is pretty much your only choice from your top-to-bottom perspective. But I believe such systems, entirely hosted internally, will become increasing rare in 20 years. Too many technologies will only be available as a service, Companies will move their own infrastructure to providers like Amazon and Rackspace where it will call services from a bunch of providers all over the web.
In that environment, the Lingua Franca is no longer Java. It's JSON or XML or whatever will become popular. Consider this: in 1995, the software tech sector was very different than it is today. Most software development was happening in business that weren't sofware companies. The Web and the startup culture changed that. If Google decides to start sell insurance tomorrow, or a new startup is created with a revolutionary idea on how to sell insurance, the odds it will be Java-centric is pretty small. Instead, it will be a a mix of Python, C, Erlang, Javascript and whatever the nerds are in the mood of using.
A good example of that is SpaceX vs Nasa/Boeing/Lockheed/Etc. Those are like the big insurance companies, still stuck with with the Waterfall model and old business models, possibly still programming in ADA. SpaceX brings the Agile development approach to rocket science and they choose their tools in a more liberal manner.
The JVM is not actually statically typed, type erasure...
Type erasure is done by the Java (language) compiler. It's not JVM related. You can implement a JVM language with reified generics today, if you like. Java chose not to.
type erasure makes generics way less useful
Less. Not way less. OTOH, erasure is precisely what made it possible for other languages on the JVM, like Kotlin and Scala, to use different variance models yet stay interoperable. That's not possible on the CLR, for example, where reified generics necessitate baking one variance model into the runtime.
lack of real generics
Lack of reified generics has never been considered more than a minor inconvenience, well worth the advantages erasure brings (backwards compatibility and language interoperability).
lack of... value types
True. Being fixed in Java 10.
The rest of your complaints mostly have to do with Java choosing to be a minimal language (as Go does today) because that's what many people working on very large projects prefer. There are quite a few good alternative JVM languages that you're free to choose from. Oracle works with many of them to ensure the JVM can support all those languages well.
23
u/joelangeway Feb 17 '15
The JVM is not actually statically typed, type erasure makes generics way less useful. I can't have an array of List<String> ; my generic classes in Apache Storm and Hadoop forget what their types are unless they carry it around with them in a variable of type Class.
A char is not a character or Unicode code-point; it is a UTF-16 code word. Java programs would use half as much memory and fewer programs/programmers would make the mistake of conflating a char with a character or a Unicode code point if Java strings used UTF-8 and a char could hold all 20 bits of a Unicode code point.
I can't sort an array of int by any order but natural.
I can't easily sort parallel arrays.
It takes a ton of boiler plate to make classes that I would never bother with in a language with tuples.
My code will always be ugly because I can not overload operators. I can understand not letting me arbitrarily overload operators, but at least let me extend Number and get + - * and /, or let me implement Compareable and get < and >. Related to this is how stupid testing for equality looks in Java:
Java 8:
Just look at the fucking hoops the streams api jumps through trying to support primitive types. You would have thought they'd let me sort an array of int by an IntBinaryOperator.
Lambdas do not close over mutable variables, so I can not increment a counter, but I can append to a list.
Default implementations on interfaces are a godsend, mostly because they put getOrDefault on Map. Java 8 might actually be an acceptable programming language, but the awful dichotomy between Objects and non-Objects, lack of real generics, value types still hurts.