r/programming • • Feb 22 '15

Java Makes Programmers Want To Do Absolutely Anything Else With Their Time

http://www.forbes.com/sites/quora/2015/02/21/java-makes-programmers-want-to-do-absolutely-anything-else-with-their-time/
35 Upvotes

636 comments sorted by

View all comments

Show parent comments

8

u/ihcn Feb 22 '15

I think the argument is for compile time type inference, something every modern compiled language has, except java of course. Any IDE will tell you what the type is, without you having to type it out.

1

u/[deleted] Feb 22 '15

I mean it's not like it's technically infeasible to infer the type at compile time. The current approach is just a lot clearer (see the second point).

For example, a quick glance while scrolling through the code in a web-based code viewer shows you what type you're dealing with. You don't need to go into an IDE or follow the source code to figure this out. Basically what I'm getting at is that it's a feature, not a deficiency.

Also, IDEs kinda give you coding-time type inference and add the types to the source code for you. So you don't generally have to type it out.

2

u/ihcn Feb 22 '15

I strongly disagree that it's a feature. Java seems to have the mentality that it doesn't give you enough rope to hang yourself with, so it takes away all sorts of crucial features. The ostensible tradeoff is that your code is easier to understand as a result.

But in my experience with enterprise Java, bad developers will write awful code no matter how much you take away from them. The worst codebase I've ever seen, by far, was Java.

2

u/cmiles74 Feb 22 '15

I'm not convinced, I believe there are simply more people writing Java thus we see more poor quality Java code.

1

u/[deleted] Feb 22 '15

Agreed. Bad developers will write bad code regardless. I'm not saying it prevents bad code.

I think it's a feature because of the self-documenting nature of it.

In the end it's just a matter of personal opinion. I won't insist on attempting to change yours.

0

u/giuseppemag Feb 22 '15

If only we could do something to avoid this kind of lack of clarity. Like naming variables something descriptive that somehow makes the type obvious... :)

0

u/contantofaz Feb 22 '15

Java has thousands of libraries packaged up in jar files. Not many languages have that. Languages sometimes expose libraries in source-code format. With a binary-like format, information could be lost. So languages like Java that make declaring types extremely redundant may help the IDEs with figuring out the types of those variables. :-)

Also, one of the goals they may have had for Java was to make competing implementations compatible. Dumbing down the language may have been an effort to make that less difficult. It seems that even new languages are willing to go in that direction so they can help with multiple implementation goals.

Languages that do a great deal of type inference may end up with only their reference implementations. Although perhaps we shouldn't have blamed the type inferencing as the whole cause of it. I think languages willing to break backward compatibility with every other release may not be too enticing for mainstream use. Hence they ending up with just their reference implementations.

5

u/giuseppemag Feb 22 '15

What sort of argument against type inference is this?!?

Type inference just requires signatures, which should well be present in any precompiled library (linking is otherwise impossible). In principle Java has nothing that would prevent type inference, precisely like var in C#.

-1

u/[deleted] Feb 22 '15

What sort of argument against type inference is this?!?

I'd argue that IDEA's struggle to provide correct and meaningful Scala type information (the best form of type checking can often yield false positives) is a good argument against it.

1

u/giuseppemag Feb 28 '15

F# or Haskell have no such struggle. It just means that this specific implementation is of no such good quality.

-3

u/contantofaz Feb 22 '15 edited Feb 22 '15

I don't know how to respond to that. I think that ultimately the proof is in the pudding. Or as in Jerry Maguire: "Show me the money!" If type inference is no problem for libraries, multiple competing implementations, backward compatibility, etc, show me the money! :-)

3

u/ihcn Feb 22 '15

The compiler absolutely must know the type of every variable, because otherwise it couldn't possibly give you a mismatched type error.

-2

u/contantofaz Feb 22 '15

Yes. But it's the work of following the dependency to the original types that must be considered too. In some languages types can be inferred in a lot of places. More so than just local to a function. That extra work is not always advisable. Many languages in the Java ecosystem can share the libraries thanks to the effort that Java put into making the libraries easier to share. But once the library follows the Java standards, they may lose some unique informations as required by some languages in the source-code. Information that could implicitly depend on private types even. So language designers are sometimes skeptical of how much information can be leaked in type inference support.

3

u/jamougha Feb 22 '15

Scala already does this.

1

u/giuseppemag Feb 28 '15

F# and C#...