Live data from Hacker News

The Java type system is broken

wouter.coekaerts.be

31–40 of 168 posts

Re: The Java type system is broken

#31
post #10

Welcome to the world of enterprise-ready complex applications. I agree that these cases should be covered by the compiler but man, there are mainstream languages that don't implement generics just because they're complex and pretend that they're not helpful. It would be nice of you to compare Java generics with equivalents instead of just criticizing it. It doesn't help anyone writing "this is broken" not offering an…

C# is a similar language in it's goals and architecture. LINQ to Objects type system will throw an error if you try to return conditionally different types from a lambda expression, so it is doable.

Re: The Java type system is broken

#32
post #18
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?

Is it? The whole point of a type system is that it gives you guarantees over your code. Certain bugs should be inexpressible within the language.

I don’t think that is true anymore. There are languages like typescript that don’t provide anything near that guarantee but are still seen as very useful.

Re: The Java type system is broken

#33
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?

> 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...

Re: The Java type system is broken

#34
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?

What's the point of strong typing if it only saves you most of the time?

So a type-system that does the right thing in 99.999999% of the cases is completely useless according to you?

Re: The Java type system is broken

#35

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.

The point is not that you can do explicit casts, it's that because you can form a (fake) instance for impossible types you can do invalid type conversions without doing anything that looks unsafe.

In Haskell you can certainly achieve the same thing with various common extensions ( http://okmij.org/ftp/Haskell/impredicativity-bites.html ). Possibly not in vanilla Haskell '98, at the price of being not a very nice language to work in. (A total language like Idris should permit GADT-like functionality without allowing this kind of issue).

Re: The Java type system is broken

#36
post #10

Welcome to the world of enterprise-ready complex applications. I agree that these cases should be covered by the compiler but man, there are mainstream languages that don't implement generics just because they're complex and pretend that they're not helpful. It would be nice of you to compare Java generics with equivalents instead of just criticizing it. It doesn't help anyone writing "this is broken" not offering an…

> It doesn't help anyone writing "this is broken" not offering any alternatives or suggesting ways to fix the problem.

Clearly stating and detailing problems is absolutely helpful. We can't solve problems if we don't understand them.

Re: The Java type system is broken

#38
post #10

Welcome to the world of enterprise-ready complex applications. I agree that these cases should be covered by the compiler but man, there are mainstream languages that don't implement generics just because they're complex and pretend that they're not helpful. It would be nice of you to compare Java generics with equivalents instead of just criticizing it. It doesn't help anyone writing "this is broken" not offering an…

>It doesn't help anyone writing "this is broken" not offering any alternatives or suggesting ways to fix the problem.

Actually identifying a problem is of very much help, even without a solution.

For one, it lets people know of the problem, so they can get to an eventual solution.

Second, it lets people know of the problem, and avoid those areas, even if there's no solution available.

Re: The Java type system is broken

#39
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?

>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"

The very idea of the type system is that it makes "broken code" of a certain type a compile error.

Re: The Java type system is broken

#40
post #34

Earlier quoted context omitted.

What's the point of strong typing if it only saves you most of the time?

So a type-system that does the right thing in 99.999999% of the cases is completely useless according to you?

I think the question is rhetorical.
Post reply on HN