Vinen
God is dead
- 2,791
- 497
You win the internet for the day.Tenks is a Java boy so it's no surprise he's fuming behind the keyboard. Probably just ripped his raw denim jeans in half when the blood pumped to his dick
You win the internet for the day.Tenks is a Java boy so it's no surprise he's fuming behind the keyboard. Probably just ripped his raw denim jeans in half when the blood pumped to his dick
Its a valid concern with Java. Some languages disallow the use of null so it makes things a ton more elegant. Unfortuantely Java can't put that genie back in the bottle so now they can only recommend people construct their classes utilizing Optional instead of null (unlike Scala where it has to be Optional.)And if checking if something is null is the bane of your existence, you have it pretty easy. That sounds like a first world problem.
Its a valid concern with Java. Some languages disallow the use of null so it makes things a ton more elegant. Unfortuantely Java can't put that genie back in the bottle so now they can only recommend people construct their classes utilizing Optional instead of null (unlike Scala where it has to be Optional.)
Like
Is much easier to read/write than
Yeah but Android is in a weird state when it comes to Java so a lot of that still has to exist for me in the meantime. If Google can ever get full Java 8 implemented that would be good but I'm not going to hold my breath.The Stream library combined with Optionals takes away some of that verbose null checking
Tired of Null Pointer Exceptions? Consider Using Java SE 8's Optional!
You could also put your null checks in the getters to your member variables, and return a default/initialized value in the getter if the value is null.Try / Catch is extremely expensive and should never be used for something like null checking. If you do it for all your null checking in Java your program will crawl.
That is basically the point of Optional. The issue is Java never formally supported Optional beforehand so null often times meant the same as notPresent() but sometimes null also meant other things. That is why null is such a dangerous device.You could also put your null checks in the getters to your member variables, and return a default/initialized value in the getter if the value is null.
Sometimes null is valid for the reasons you described or like I said sometimes null is used to simply represent a default return. Like if I have some method and lets say for whatever reason if you supply an argument over 100 it returns null. It isn't that it failed and it isn't that you used it incorrectly it is just now it behaves. On the other hand lets say something goes wrong and you did in fact use the method incorrectly and it is coded up to return null in that case. Now you have received null from this API for two vastly different reasons. Again, it is why nulls suck in general but it is a common use of them even in well structured Java code.However, that really defeats the point, because if the value is null you really want to know about it and probably do something different than you would do if it's not null. Usually shit gets nulled out because something was not found in the db so whatever you expected to be populated isn't, or the user didn't input what you thought, etc; these are things you SHOULD be checking for. The fact that they're usually null in java just makes the "java null check" kind of a meme where in C/C++ you'd be checking them as well anyway, just for an in-bounds value rather than null.
Agreed. And modern IDEs will fill in much of the boilerplate for you anyways. Sometimes concise languages, IMO, are actually more difficult to read than verbose languages. You need to actually know the language to follow the syntax because there is so much sugar. With Java you generally can just read it logically and reason it out because it is so verbose -- which makes it very friendly for maintenance and onboarding.People cry about java way too much, there's some clunky shit but honestly I spent like 5% of my time actually writing code and most of my time writing requirements, bug squashing, testing, helping others... the relatively clunkiness of the language I was using didn't mean dick. And I developed professionally in C, Java, Rails, a bit of C++, mumps (have fun with that one)...
I did some horizontal add and shufb action a few days ago!Talk to me when you guys gotta develop in assembly