Live data from Hacker News

The Java type system is broken

wouter.coekaerts.be

161–168 of 168 posts

Re: The Java type system is broken

#161

Earlier quoted context omitted.

That's incorrect. It would have been possible to implement reified generics while preserving backward compatibility, Neal Gafter had actually a proposal to do just that. In the end, erasure won simply because it's the superior solution.

Erasure is superior to a system that would be typesafe? Please elaborate.

How is reification any more type safe than erasure?

Re: The Java type system is broken

#162

Earlier quoted context omitted.

That's incorrect. It would have been possible to implement reified generics while preserving backward compatibility, Neal Gafter had actually a proposal to do just that. In the end, erasure won simply because it's the superior solution.

Erasure is superior to a system that would be typesafe? Please elaborate.

Erasure is just as type safe as reification.

Erasure gives you a little less flexibility to express certain constructs than reification allows, but from a type safety standpoint, the two approaches are equivalent.

If you want widen the meaning of "type safe" a bit, I would argue that reification is "less" type safe in the sense that it allows you to perform additional runtime type checks / type casts, which basically means you are second guessing the compiler and invalidating all the type soundness that it has provided you by accepting to compile your code.

Re: The Java type system is broken

#163

Earlier quoted context omitted.

Erasure is superior to a system that would be typesafe? Please elaborate.

Erasure is just as type safe as reification. Erasure gives you a little less flexibility to express certain constructs than reification allows, but from a type safety standpoint, the two approaches are equivalent. If you want widen the meaning of "type safe" a bit, I would argue that reification is "less" type safe in the sense that it allows you to perform additional runtime type checks / type casts, which basically…

It would not have allowed one to seal the loopholes demonstrated in the article?

Re: The Java type system is broken

#164

Earlier quoted context omitted.

Erasure is superior to a system that would be typesafe? Please elaborate.

How is reification any more type safe than erasure?

Would it not have allowed one to seal the loopholes demonstrated in the article?

Re: The Java type system is broken

#165
post #152
post #108

Earlier quoted context omitted.

I prefer my type errors at compile time. You have to reason about types in any language because passing the wrong type to a function can result in errors. You have to do all of that mental work by yourself in a dynamic language because there isn't a system to do it for you.

There are tools roughly similar to C's "lint" that can warn you about suspicious-looking code. While compile-time checking can be nice, compiler-oriented languages often result in more verbose code. Verbosity introduces errors also. But the benefit weighing also depends on the kind of applications. I didn't mean to trigger a "holy war" of static versus dynamic languages.

> Verbosity introduces errors also.

The purpose of types is to introduce errors in the first place - at compile time, if you messed up.

Wrong code causes errors regardless. Annotating with types just moves this event from runtime to compile time.

Re: The Java type system is broken

#166
post #165
post #152

Earlier quoted context omitted.

There are tools roughly similar to C's "lint" that can warn you about suspicious-looking code. While compile-time checking can be nice, compiler-oriented languages often result in more verbose code. Verbosity introduces errors also. But the benefit weighing also depends on the kind of applications. I didn't mean to trigger a "holy war" of static versus dynamic languages.

> Verbosity introduces errors also. The purpose of types is to introduce errors in the first place - at compile time, if you messed up. Wrong code causes errors regardless. Annotating with types just moves this event from runtime to compile time.

I understand that, but I'm not sure the benefits exceed the drawbacks. In other words, verbosity introduces errors by making the code harder/longer to read. The type-related verbosity may reduce errors, but perhaps not enough to counter those caused by verbosity. In my experience, it's roughly a wash, but depends on a lot of other things, like frameworks used, skill of developers, QA techniques, etc.

Re: The Java type system is broken

#167
post #33

Earlier quoted context omitted.

> And this is, well, uhm, well... acceptable? It is not. The only purpose of a type system is to prevent broken code from compiling. When it fails to do so, it is broken.

Typescript with its explicitly unsound type system show that a "broken" type system is immensely valuable, especially when you get something in return for that [1] [1]: https://www.typescriptlang.org/docs/handbook/type-compatibil...

Well, sure, it's better than having an even worse type system! No one's saying java's type system is worse than not having anything.

Re: The Java type system is broken

#168

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.

Go doesn’t have an ABI? Does every library ship only as source code? I didn’t know that.

I was thinking of more fundamental changes to Java idiom and the standard library had generics been part of the design (e.g., how arrays work).

Post reply on HN