36
Esper
7y

I'm currently rewriting perfectly clean and functioning Scala code in Java (because "Enterprise", yay). The amount of unnecessary boilerplate I have to add is insane. I'm not even talking big complicated code but two liners or the lack of simple things like a range from 5 to 10.

Why do I have to write
List<Position> occupiedPositions = placedEntities.stream()
.flatMap((pe) -> pe.occupiedPositions().stream())
.collect(Collectors.toList());
instead of simply
val occupiedPositions = placedEntities.flatMap(_.occupiedPositions)

Why on earth does `occupiedPositions.distinct` suddenly become a monstrosity like `occupiedPositions.stream().distinct().collect(Collectors.toList())` where the majority of code is pure boilerplate? And this is supposed to be the new and better Java8 api which people use as evidence that Java is now suddenly "functional" (yeah no, just no).

Why do APIs that annotate parameters with @Nullable throw NullPointerExceptions when I pass a null? Why does the compiler not help prevent such stupidity? Why do we use static typing PLUS those annotations and it still crashes at runtime like every damn dynamic, interpreted language out there? That's not unfortunate, it's a complete waste of time.

Why is a simple idea like a range from x to 10 (in scala literally `x to 10`) not by default included in Java? There's Guava's version of Range which does not have a helper for integer ranges (even though they are the most used ones). Then there's apache.commons version which _has_ a helper for integers, but is strangely not iterable (wtf I don't even...).

Speaking of Iterable: How difficult could it be to convert an abstract Iterable<T> into a concrete List<T>? In scala it's surprisingly `someIterable.toList`. I found nothing like that so I took to stackoverflow where I found a thread in which people suggested everything from writing your own ListUtils helper class, using Guava (which is a huge dependency!) to using the new Java8 features inline (which is still about three lines long). I didn't know this was such a hard problem in computer science, TIL.

How anyone can be productive in this abomination of a language is beyond me now, even though I've used it for many years while learning to code (back then I didn't know there were much better ways to do things). The only good part is that I have to endure this nonsense for only about 3 days longer then I'm free again!

Comments
  • 2
    Good arguments, but Java as a language is pretty boilerplate any day. That is why you see quite a few JVM languages these days, trying to make it short, concise and even begin as Functional languages. Java just got started to become Functional, but it barely is, as your nice examples convey

    Also, why are you even rewriting it? Scala is pretty much Enterprisey as it stands today.
  • 0
    Yup. java in a nutshell. I prefer python nowdays. much less boilerplate, a lot less pitfalls.
  • 2
    And there are still people who do not believe me when I say Java is retarded. Aint that right, my enterprise boy @kaqqao & my nano pal @RazorSh4rk ? 😀

    Mind that this is not ill-willed, just want some input 😀

    @Esper, this will make a fine addition to my collection, smooth examples, thanks for ranting
  • 2
    @magnusi java is retarded but so am i :D
  • 1
    @RazorSh4rk with each day, I like you more and more 😁
  • 0
    I agree with everything you've said

    ... but that Scala syntax is ugly as fuuuuuuuuck 😲😂
  • 1
    Woohoo a Java rant let's go!
  • 1
    Java has IntStream.range tho
    And yes, java is and always was a verbose language. I personally like groovy a lot for being almost a superset of java. Going to take a look a Kotlin. Scala never really interested me. It has cool features but it just doesn't look sexy.
    That being said I still like coding in Java.
  • 0
    @asgs We used to do rails mostly and wanted to migrate to Scala and maybe some Elixir, but then we merged with other companies. Those code monkey only know Java/C#, so company policy mandates those two languages even if it makes no sense.

    @BlueDev I'm curious what part of scala you think is so ugly (apart from the ADTs, which are truly the worst in all typed functional languages ever). I think Kotlin and Swift look a bit nicer sometimes, but lack so many features Scala has... :-/
  • 0
    @Esper fuck mergers and acquisitions. Time to find another job then
  • 1
    @Esper I'm no Java Jockey, but tham that kind of a rant must be caused by your jimmies getting juggled for real.

    Have as many ++'s as Java's StacktraceOhMyFuckingDietyWhatTheActualFuckWhySoLongOutputExceptions() cause by ...
  • 2
    @kaqqao "Java's readability" must be sarcasm because if two thirds of the code I read are pure boilerplate, that's anything but readable. Sure, with a few years of experience, you'll know which parts are actually to be ignored, but that doesn't mean there's no problem there.

    Also, things like nullability by default, mutability by default or lack of means to add functionality to already existing types and heavily relying on unsafe runtime reflection are not a problem of "typing a bit more", they are huge design flaws compared to more modern alternatives like kotlin, swift, F# and yes, even Scala.
Add Comment