Principle Of Least Confusion

The coding guideline of not using unexpected or easily misunderstood constructions.


Example - in PythonLanguage, the AND and OR operators are somewhat more intricate than in other languages.

 X and Y
Actually means "if X then return Y". Likewise,

 X or Y
means "if not X then return Y". When using booleans, they are logically consistent with their namesakes, but can be used for odd shortcuts with other objects. Since testing for truth is usually testing for non-null or non-zero, the most bizarre shortcuts can be used by this system where a full, explicit if block would be appropriate. The canonical example of this confused power is:

 2/3 or 5 ==> 5
since 2/3 evaluates to 0.

PrincipleOfLeastConfusion states that, even though such code is sensible to someone with deep knowledge of the programming environment, one should stick to facilities that use the more conventional understanding of the system, or at least thoroughly comment the more obscure applications if they are necessary.


I consider such a poor design feature of the language, at least as a "corporate language" where team members come and go and use multiple languages. -t


See EgolessProgramming


EditText of this page (last edited February 10, 2014) or FindPage with title or text search