News for hackers. Stuff that matters.
Re:Yoda Conditions by brianwawok on Friday February 17, 2017 @10:56AM (#13669073)
Eh, I think it is good in Java in cases where Null input is possible.
Re:Yoda Conditions by paol on Friday February 17, 2017 @11:09AM (#13669226)
Yes, "foo".equals(bar) is useful in Java if bar can be null, but that's a different thing.
Re:Yoda Conditions by brianwawok on Friday February 17, 2017 @11:26AM (#13669402)
Not really different. In fact is is mentioned on the Wikipedia page.
Re:Yoda Conditions by megawatthours on Friday February 17, 2017 @12:26PM (#13669993)
I never got the Java argument. I would much rather fail early and noisily with an NPE than return false and let my program happily chug along when it wasn't expecting a null. If the value is intended to be nullable, I would use an optional.
Re:Yoda Conditions by brianwawok on Friday February 17, 2017 @02:29PM (#13670970)
Well for 95% of Java's live, there was no such thing as Optional.

So say untrusted user input.. many cases where it could be something or null. Yoda checking it was a nice way to save a null check.

Re:Yoda Conditions by xxs on Friday February 17, 2017 @12:37PM (#13670098)
Java8 optional is way slower (write a tree alike struct with optional for left/right/parent) and null checks are one of the free ones. (Hardware optimized)
Re:Yoda Conditions by PaulHoule on Friday February 17, 2017 @11:53AM (#13669683)
I think it is better than if(x!=null && x.equals("y")

You have to take bits of concision where you can find them in Java.