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

In-case people haven't made the link, working memory is why cyclomatic complexity is so important in software development.

For each increase in cyclomatic complexity, you need to keep one additional bit of state in your head.

Usually you can ignore high level state bits when you are down low, so cyclomatic complexity isn't a one-to-one mapping to working memory, but one notes that the old shorthand of "working memory is 7 +/- 2" is close to the "cyclomatic complexity > 10 is too hard" rule.



I really like early returns for this reason.

if (someEdgeCase) {

  return SpecialValue;
}

const normalCase = a + b ...

It allows you to drop a case from working memory as early as possible. I believe this would be a +1 in cyclomatic complexity, but it shouldn't be. Cyclomatic complexity is not the whole story (nor do I think it tries to be).




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

Search: