Hacker News new | ask | show | jobs
by DanielHB 421 days ago
> 1. Enforce some level of code complexity. Best practice is 40 lines per function and no more than 4 parameters per function. Epic probably shouldn’t shoot for that, but a 100 line limit and 6 parameters per function would already be a huge improvement.

If I were to enforce some kind of arbitrary code complexity threshold for functions I would put a cap on the limit of possible of branching combinations based on parameters within the code. Like around 16 (branching combinations are exponential).

For example a function with 20 parameters but only one if statement is fine. A function with 5 parameters but several nested if statements is not.

2 comments

Like cyclomatic complexity? https://en.wikipedia.org/wiki/Cyclomatic_complexity

My previous company had a step in the CI/CD that would fail if the nesting level of a function got too deep. (Like, "an if statement, which contains a foreach loop, which contains another if statement, which contains...")

Yes exactly, I was forgetting the name of that.
This is why microservices are great. It is impossible to reacharound by flipping a private function to public and call it. An API change is required, which is hard to hide, and it needs to be carefully deployed since it can have visible load/operational impact.