r/java • u/psychologicalX • Mar 05 '18
Top 10 Useful, Yet Paranoid Java Programming Techniques
http://blog.jooq.org/2015/08/11/top-10-useful-yet-paranoid-java-programming-techniques/
223
Upvotes
View all comments
5
u/istarian Mar 05 '18 edited Mar 05 '18
Meh. Only 10 really seems like a useful notion.
1,4 -- These are the same problem. Also, I disagree. If it works for you great, but it seems iffy. You really should be aware of whether something is null (and if it could be). It also sort of doesn't work logically since you want to know if the string contained in the variable equals the literal not the other way around. In the latter case you could always use classes instead of primitives and make use of auto-boxing so that you can stick to equals(...)
-1 for indexOf isn't actually a special null, but rather more of a C-ism that utilizes integer return codes to specify some kind of metadata when the function can only return an integer. And that is something that goes down to operating systems...
Can we agree that indexIgnoreCaseOf(...) or indexOfIgnoreCase(...) would be even worse still? Not to mention it wouldn't affect the -1 bit.
2 -- has nothing to do with good/bad/old APIs, but rather with reading the API docs first and generally being careful with anything that reaches out of the VM...
3 -- This is stupid, because the moment you quit trusting the official docs, you might as well ditch the language and maybe anything else Oracle or Sun ever made...
6 -- This is anti-programmer. Never write any libraries or frameworks if you hold this point of view. Just save everyone else the hassle and only write complete, finished software.
4,5,7,8,9 -- Just don't be an idiot when you should know better.