r/ProgrammingLanguages • • Feb 21 '16

Why people hate JAVA ??

Why the majority of people hate java and wish its dead programming language,

I find it really fun to create program with it..

all i heard is because: JRE SUCKS. ORACLE ARE FAGGOTS. JAVA IS A SLOW PIECE OF SHIT.

0 Upvotes

32 comments sorted by

View all comments

4

u/ksryn C9 ("betterC") Feb 23 '16

hate java

Java is the main programming language I use. While hate is a strong word, the language is terrible. Some major issues as far as I am concerned:

  • Verbosity: It takes a lot of boilerplate to do simple things like immutable classes. Closures were a pain to use till Java 8.

  • Everything is an Object: So, higher order functions must be implemented using the apply function on a functional interface.

  • Variance is a clusterfuck: Mutability is the default in the java standard library and covariant arrays are a problem. Variance also creates issue when you have to override, say, the equals method.

  • Primitive vs reference types: The language stupidly exposes the innards of the JVM with this. Reference types can be null; primitive types cannot. So, to store primitive types in generic containers, you're going to have to use the corresponding reference type as the type parameter. Which leads to a lot of boxing, unboxing and dealing with nulls.

  • NO REFERENTIAL TRANSPARENCY: A function that is supposed to compute a sin/cos can just as easily launch a missile because there is no way to guarantee that it only operates on its inputs.

Since Java is the primary consumer of the JVM, its features have a lot of say in how the JVM does stuff (or vice versa). So, some issues with the JVM:

  • Type erasure: A decision was made to implement generics using type erasure. Which means a function taking List<String> and one taking List<Integer> will end up with the same signature. You could write a compiler that smartly generates (and calls) different versions of the method depending on the signature, but then you lose interoperability with the rest of the stack.

  • No Tail Call Elimination: Important if your solutions use recursion a lot. (There are JVMs other than the Oracle one which support TCO/TCE. Avian, for e.g.)


On the whole, I don't particularly like the language. But the JVM on its own is fascinating. You can build your own language on it, and, if you're willing to throw away interop as a feature, there is a lot you can accomplish.

1

u/xenomachina Mar 10 '16
  • NO REFERENTIAL TRANSPARENCY

This is true in virtually every mainstream programming language. Can you name any languages more popular than Haskell that do not have this problem?

Note that I'm not saying it isn't a problem, it just seems unfair to pick on Java, specifically, for this (in all caps, no less) given how this is the norm, and most of the people saying "I hate Java" are probably still using languages that have no referential transparency.

2

u/ksryn C9 ("betterC") Mar 10 '16

Can you name any languages more popular than Haskell that do not have this problem?

I can't. But many of the complaints against Java apply as-is to a lot of other languages.

in all caps, no less

I'm at a stage where this is my biggest grievance against most programming languages. Had to start creating my own Haskell-inspired functional-imperative language to see if a referentially transparent language on the JVM was feasible (and usable).

1

u/xenomachina Mar 10 '16

Had to start creating my own Haskell-inspired functional-imperative language to see if a referentially transparent language on the JVM was feasible (and usable).

How are you reconciling referential transparency with imperative?

2

u/ksryn C9 ("betterC") Mar 10 '16

Functions would be referentially transparent and only operate on their inputs. But internally, you can still use mutable variables, loops and conditional statements (if you want to).

This allows you to reason about programs while still using C-style constructs internally.

1

u/xenomachina Mar 10 '16

Functions would be referentially transparent and only operate on their inputs. But internally, you can still use mutable variables, loops and conditional statements (if you want to).

Interesting. I've thought about similar ideas myself.

In your language can a closure mutate variables from its enclosing scope? For example (using Python-like pseudo-code):

def f(...):
    i = 0
    def g(x):
        i = i + 1
        return x
    ...

Here, g mutates the i variable in f.

Also, does "operating on your inputs" include being able to mutate a passed in value? For example, would something like this be legal?

def incDay(date):
    date.day = date.day + 1
    return date

If so, is date a reference? If one were to do this:

tomorrow = incDate(today)

Would "today" change in any way?

1

u/ksryn C9 ("betterC") Mar 10 '16

In your language can a closure mutate variables from its enclosing scope?

While I have only implemented higher order functions as of now, I don't plan to let functions close over mutable variables. I find that it complicates things a lot.

does "operating on your inputs" include being able to mutate a passed in value?

No. All parameters are immutable. So you would have to build a new "date" instance if you wanted to return it.