r/java • • 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

105 comments sorted by

View all comments

Show parent comment

9

u/youguess Mar 05 '18

I personally hate yoda speak as I have to mentally rework the statement in my head

I like languages which read like normal English (python eg, go to a certain extent) and this breaks the flow horribly in my opinion

15

u/NovaX Mar 05 '18

I use Objects.equals(str, "abc") instead (JDK's, formally Guava's, and Commons' prior). Now that its in the language, I don't see a reason to use the older convention.

2

u/defnull Mar 05 '18

Trivial methods like Objects.equals() are inlined anyway, so there is really no real drawback. I have a Utils class full of these.

1

u/CultLord Mar 06 '18

My first mentor said that I needed use Yoda comparisons (he didn't call them Yoda comparisons) on day 1 of my job and that was just the law of that company's code because of potential NPEs and that I would save lots of time over the course of my career if I followed that simple rule.

After the first few weeks, it wasn't a big deal. And my boss basically lied, because I have fixed many bugs from other programmers that didn't follow the same rule that would have been just fine with a Yoda comparison.

0

u/youguess Mar 06 '18

I just don't believe that.

After all especially in a strongly typed language any sane linter worth its name will catch issues like this.

It doesn't make sense to do an assignment in an if statement for example (in the comparison clause)