4 ms·
> You still end up getting hit with null pointers and invalid argument errors. Those are not the kinds of problems a type system is intended to solve. Those ar
by twblalock 10y ago
> You still end up getting hit with null pointers and invalid argument errors.
Those are not the kinds of problems a type system is intended to solve. Those are problems of data, not of types.
The amount of boilerplate in a Java program is pretty low if you aren't trying to abuse or work around the type system. It certainly is not 10x what you end up with in Ruby or Python. Java 8 has made significant improvements, but it wasn't that bad before in many cases.
Instead of trying to work around Java's type safety, you should learn to use it properly. Good programmers think about types whether or not they are forced to by the language, so the restrictions imposed by Java should not be burdensome -- in general, you should already be mentally applying some of those restrictions to your code so you can avoid passing the wrong types around.
- hibikir 10y agoThey are problems type systems are intended to solve: It just happens that Java's is too weak to deal with it well: They best you can do is use an option type, but even then, Java's Option type is far weaker than in other languages. Languages where null doesn't exist are far nicer. Java's boilerplate comes from lacking type inference and from having a type system that is too weak, not one that is too strong: I'd argue that people's love for dynamic languages without type systems is cause by how people's idea of what types are, and what they do for you, come from Java and old C++, as opposed to something more powerful.
- jay-anderson 10y agohttp://types.cs.washington.edu/checker-framework/ http://types.cs.washington.edu/checker-framework/ - there is work going on in the java world to deal with nulls in the type system.
- twblalock 10y agoNulls are not a problem type systems are intended to solve -- they are a feature of type systems that was created on purpose. You might not like them, but that doesn't mean they constitute an oversight or omission on the part of the designers of the type system -- they wanted them there. They are useful. Many people misunderstand the option type in Java. It was created to make stream processing easier. It was not intended for general use, as in other languages. Regarding illegal arguments, they are unavoidable in any type system. Suppose you defined a function that splits a string into an array of n-grams, to which you pass the string as well as int n. If you pass an n which is greater than the length of the string, no type system will help you figure out what to do. It's just an invalid/illegal argument, and you will either have to decide what to return for that case (maybe an empty array, or even... null), or throw some kind of exception.
- Decade 10y agoThe inventor of the null pointer considers them to be a mistake: https://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare https://www.infoq.com/presentations/Null-References-The-Bill...
- twblalock 10y agoSo what? He's wrong.
- meddlepal 10y agoThat quote gets pulled out of thin air every time this argument comes up and it's pretty silly. I think more specifically, nullable by default might have been the bigger mistake not that null is inherently a mistake.
- twblalock 10y agoThe fact that most of these replies mention esoteric langiages that have no traction in industry kind of proves my point.
- junke 10y agoThe mistake is Null being a member of all (reference) types. This is not the case in all languages that have a nil value. In Common Lisp if you declare an argument to be a string, it is an error to pass NIL. You have to declare the type to be "(or string null)". That's exactly what the Option type provides.
- twblalock 10y agoThat is not how Lisp works. You are just wrong.
- deleted 10y ago[deleted]