Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Every if statement is a chance of a bug because the code has two or more paths to follow

This is known as the cyclomatic complexity of a program: https://en.wikipedia.org/wiki/Cyclomatic_complexity

A corollary to this is that it is also beneficial to converge separate paths as quickly as possible (e.g. using non-nullable types and default values) or converge them all to the same place (e.g. nonlocal exception handling).



I often abbreviate that to "Psychosomatic Complexity" because more complex code is likely to give the programmer a headache.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: