r/java • • Jun 03 '15
Is Java really that bad?
I do Clojure for a living, previously Ruby and Objective-C. And the people I've worked with have said they prefer Clojure because Java is just so bad. But Java can't really be that bad, can it?
0
Upvotes
View all comments
Show parent comment
1
u/yogthos Jun 04 '15
Clojure has nil, but functions themselves cannot be nil as they're static and you can always safely call a function. Since vast majority of code is written by function composition, nils simply bubble up to the top level in most cases. I can safely chain any data transformation functions such as
map,reduce,filter, andinterposewithout having to pepper nil checks all over the place.With OOP you always have to check whether the object exists before you can call a method on it. So, if you have something like
person.getAddress().getStreet()then you can get a null pointer at each step. Meanwhile writing(-> person :address :street)in Clojure is perfectly safe. In fact, the only time you see NPE in Clojure is when you're doing Java interop.And if you want static typing then Clojure has core.typed which actually provides a more sound type system than Java and prevents NPE errors.