Live data from Hacker News

The Java type system is broken

wouter.coekaerts.be

81–90 of 168 posts

Re: The Java type system is broken

#81

My favourite feature of Java's type system is that, because any object type also accepts null, the type system is unsound and you can convert anything to anything else: https://raw.githubusercontent.com/namin/unsound/master/doc/u...

Wouldn't that be a problem in most languages? Even Haskell allows for it through Data.Dynamic If I can serialize to String, and then deserialize a String to any type of class, I can effectively "cast" anything to anything.

Data.Dynamic is type safe. It performs a run-time type check.

Haskell can be made to be unsound using 'unsafeCoerce', but as you'll note, there is a giant unsafe in front of it.

Re: The Java type system is broken

#82

> Everything is broken. Everything is fine. This is the correct conclusion. The people getting outraged over this are the same that will hold long and boring monologues about how everybody does REST wrong.

Had a client just last month that were doing SOAP wrong somehow... Required a SOAP message, that contained no XML after the message tag, but instead the entire message body was to be a JSON, and responded with a JSON if something was wrong, and a fully formed SOAP message if things were Ok. That and the guys that handle your money use the Http status code as their personal error messages. Except when the error is on…

Well I hope the money was good at least. Yikes.

Re: The Java type system is broken

#83
post #77

The mess that is the current Java type system makes me skeptical when proponents of languages like Go say not to worry, that generics can be added later. If Java had generics in the beginning, it would look a lot different and the type system would be more powerful and safe.

Just use dynamic or better yet type-tag-free languages. Types are hard to get right and hard to reason about. Sure, there are some Sheldons out there who master it even under pasta applications, but most of us are not Sheldons. C# also bleeped up types by adding nullable types, making reflection into a scavenger hunt. For dynamic or tag-free languages, type indicators could be used to parse-check scalar (base) values…

> C# also bleeped up types by adding nullable types, making reflection into a scavenger hunt.

Having used reflection in C# with both nullable types and non-, I'm curious what you mean by "scavenger hunt".

Re: The Java type system is broken

#84
post #67

Earlier quoted context omitted.

For certain and specific definitions of "broken code".

Yeah, for the type of broken code that has the wrong types.

In some situations. The examples in this article, I think, make it clear that for a lot of "broken code" these errors are caught. It's too bad that there are edge cases, but that is Java all over, in my opinion.

Re: The Java type system is broken

#85
post #79
post #63

Earlier quoted context omitted.

Application of type theory, or any theory, or any formal method, requires humility and patience. To apply a formal method to your work requires to acknowledge that your intuition might me wrong, your past decisions incorrect, and your knowledge of the subject area deficient. Often you have to step back, rethink, and rework. This is a normal mindset for a scientist, and a pretty common mindset for an experienced engin…

It is also tribalism. When one is a polyglot developer, we are like mercenaries, a bag full of tools, each with its caveats, and we care about the solution less how we got there juggling those tools. Developer X tend to keep searching for external confirmation that they did the right choice. Any attack on tool X triggers defensive attacks, as if they would be a personal attack. Of course I am exaggerating here, just…

It is also really easy to look over flaws when you work around them everyday. I used to be on the java hate train but now after using it daily I can barely remember why I used t take issue with it

Re: The Java type system is broken

#86
post #57

Earlier quoted context omitted.

Unequivocally, yes. Several new languages (eg Typescript, Dart) have optional type systems that still bring significant value to the table. Sure - all other things being equal, I'd much rather have a type system that is completely sound. Ceylon's type system is beautiful and I'm happy to see its union + intersection types being adopted by Typescript. But honestly, I'm not going to lose much sleep over these particula…

> … Dart… have optional type systems… fyi "Dart’s type system is now sound" and "…types are mandatory". https://www.dartlang.org/guides/language/sound-dart

Wow great news! That makes Flutter even more exciting.

Re: The Java type system is broken

#87

> Everything is broken. Everything is fine. This is the correct conclusion. The people getting outraged over this are the same that will hold long and boring monologues about how everybody does REST wrong.

I liked the two sentences before those even more:

> Java’s type system has taken a beating by the desire for backward compatibility and the interaction of its growing list of features. It needs some love to get it back in shape.

Re: The Java type system is broken

#88

> Everything is broken. Everything is fine. This is the correct conclusion. The people getting outraged over this are the same that will hold long and boring monologues about how everybody does REST wrong.

Had a client just last month that were doing SOAP wrong somehow... Required a SOAP message, that contained no XML after the message tag, but instead the entire message body was to be a JSON, and responded with a JSON if something was wrong, and a fully formed SOAP message if things were Ok. That and the guys that handle your money use the Http status code as their personal error messages. Except when the error is on…

[deleted]

Re: The Java type system is broken

#89
post #4

From the examples: "String s = gridWrapper.get(0).get(0).get(0);" - Java type system is broken! Java is not perfect, but this looks to me like a broken code indeed ".get(0).get(0).get(0)". Could we rephrase the message of the article as "If you write really broken code in Java, you might be not guarded by the type system". And this is, well, uhm, well... acceptable?

In Java

  f.get(0).get(0).get(0)
typically is the way to write want in languages that allow operator overloading is written as:

  f[0][0][0]
You will rarely see that with three constants, but

  f[x][y][z]
isn’t uncommon.

Re: The Java type system is broken

#90

The mess that is the current Java type system makes me skeptical when proponents of languages like Go say not to worry, that generics can be added later. If Java had generics in the beginning, it would look a lot different and the type system would be more powerful and safe.

Unlike Java, Go doesn't have to worry about bytecode backwards compatibility. That was the main issue that had them reaching for type erasure. Take a look at C# which added it without many issues (because they were willing to break back compat of their bytecode). Go fits this model a whole lot better.

> added it without many issues

Except for the fact that all CLR languages must adopt the same variance model, enforced by the runtime (or choose not to interoperate well).

Post reply on HN