Talk:Yoda conditions

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

"unless the values evaluate to false – see below"[edit]

Not clear what the "below" reference refers to. I'll just drop this parenthetical unless someone explains :) --Rob* (talk) 22:39, 21 September 2014 (UTC)[reply]

More than four years later, the mysterious "see below" is still there. Does that mean that someone actually knows what it means? — Preceding unsigned comment added by 2607:FEA8:1CA0:40:CD1B:1A69:23D5:4BA3 (talk) 00:20, 29 December 2018 (UTC)[reply]
It used to say "unless they are null", see diff from September 2013, and this indeed made some sense with the given examples. – Tea2min (talk) 06:46, 29 December 2018 (UTC)[reply]

Use of straw-man argument[edit]

The only argument offered for Yoda form is the protection against assignment, which most compilers can warn about anyway. There are others. One nice obvious one is: compare

* 0 == strcmp(some->very.long(expression), other->multi.line(expression))
* strcmp(some->very.long(expression), other->multi.line(expression)) == 0

The function strcmp() returns zero if its two arguments are equal. Seeing "0 == strcmp(...)" it's clear to the reader right away that we're testing for equality (or, with "0 < strcmp(...)" for the first parameter to be larger; etc.). The crucial thing here is the juxtaposition of the function name and the comparison, rather than making the reader wade through all the parameters being passed before running into the comparison. (Have we exited all the nesting of parentheses we started since we mentioned what function we were calling ? Not sure, maybe ... and what function was that again, it's a few lines back now.) So the "Yoda" approach is also particularly useful - and an aid to readability - when comparing a function's return against a value: it juxtaposes the function name and the value it's compared against, without the (potentially huge) parameter list getting in the way. But we can't go mentioning this in a Wikipedia article, because there's no cited reference for it. — Preceding unsigned comment added by 91.237.34.118 (talk) 11:38, 13 November 2015 (UTC)[reply]

Not Yoda[edit]

if (myString.equals("foobar")) { /* ... */ }
1) the constant isn't on the left, that would look like this:-
if ("foobar".equals(myString)) { /* ... */ }
2) there is no use of the == sign to get confused with =
87.102.44.18 (talk) 03:28, 12 December 2016 (UTC)[reply]

Symfony?[edit]

Is the fact that Symfony uses Yoda conditions something that is truly noteworthy and relevant? If so, there are probably a large number of other software projects that should be listed here... Gustavus Magnus (talk) 19:08, 15 March 2019 (UTC)[reply]

This isn't inclusive of all human language[edit]

There are many languages that don't follow a strict object-verb-subject order, so this whole article could be read as offensive to many. Lucas' use of Yoda talking like an English_as_a_second_or_foreign_language speaker conjures musings of Romantic_racism. — Preceding unsigned comment added by Lwriemen (talkcontribs) 12:01, 10 May 2021 (UTC)[reply]

Please read the expression as a computer to dismiss this idea[edit]

From the article:

if (42 == $value) { /* ... */ }

// Reads like: "If 42 equals the value..."

What the code actually says is, "If the constant value 42 is equal to the value contained in the variable, "value".", which is definitely just as readable as, "If the value contained in the variable, "value", is equal to the constant value 42."

Maybe computer programmers should talk in the language in which they are writing code, rather than trying to turn the code into English. I would think if this "Yoda conditions" thing were really an impediment, then programmers would have much more problem with assignments. After all, they teach in school that "one plus one equals two", not "two equals one plus one". ;-) — Preceding unsigned comment added by Lwriemen (talkcontribs) 12:13, 10 May 2021 (UTC)[reply]