Yoda Conditions

Noun · Hacker Culture

Definitions

  1. Writing conditions with the constant on the left side: 'if (42 == answer)' instead of 'if (answer == 42)'. Prevents accidental assignment in C-like languages. Reads like Yoda: 'Forty-two the answer is.'

    In plain English: Writing comparisons backwards — 'if 42 equals answer' instead of 'if answer equals 42.' It reads oddly but prevents accidental bugs where you type = instead of ==.

Related Terms