Yoda Condition

Why Trust Techopedia

What Does Yoda Condition Mean?

A “Yoda condition” is when a piece of computer syntax is
inverted or swapped around, for example, where instead of declaring a variable
equal to a constant, the programmer declares a constant equal to a variable.
A key characteristic of Yoda conditions are that they do not impair the function
of the code in any way.

Advertisements

Techopedia Explains Yoda Condition

Inconsequential changes in code syntax are called Yoda conditions
because of the beloved Star Wars character who is known for inverting English
language syntax. Instead of saying something like “you will try,” Yoda says “try,
you will.” By the same token, Yoda conditions take a conventional piece of code
syntax and flip its parts around; the constant/variable change is one of the
most common. For instance, over the evolution of computer programming,
programmers have gotten used to saying things like “x = 5.” However, the
computer is just as comfortable with “5 = x.” But humans oftentimes are not – they see it as a confusing syntax change. Yoda conditions may serve no
real purpose other than being confusing, or in some cases, they may be
motivated by some perceived utility. This type of thing can also be called “Yoda notation.”

Advertisements

Related Terms

Margaret Rouse
Editor

Margaret jest nagradzaną technical writerką, nauczycielką i wykładowczynią. Jest znana z tego, że potrafi w prostych słowach pzybliżyć złożone pojęcia techniczne słuchaczom ze świata biznesu. Od dwudziestu lat jej definicje pojęć z dziedziny IT są publikowane przez Que w encyklopedii terminów technologicznych, a także cytowane w artykułach ukazujących się w New York Times, w magazynie Time, USA Today, ZDNet, a także w magazynach PC i Discovery. Margaret dołączyła do zespołu Techopedii w roku 2011. Margaret lubi pomagać znaleźć wspólny język specjalistom ze świata biznesu i IT. W swojej pracy, jak sama mówi, buduje mosty między tymi dwiema domenami, w ten…