2 ms·
Cyclomatic complexity[0] is a decent proxy for indentation level all though not all indentation increases cyclomatic complexity and not all increase in cyclomat
by K0nserv 10y ago
Cyclomatic complexity[0] is a decent proxy for indentation level all though not all indentation increases cyclomatic complexity and not all increase in cyclomatic complexity increases indentation. However for the purpose of reducing complexity it is wonderful. The ruby community is fairly good at using Rubocop[1] to enforce number of lines in methods and cyclomatic complexity. I've found that limiting yourself to 10-20 lines per method and a cyclomatic complexity lower than 7-10 is very beneficial to code quality and perceived complexity. Those numbers obviously need to tweaked to suite the language, but work well for ruby.
Often this does involve pulling out blocks of code into a methods that's only called once, but as discussed elsewhere in the thread this is still an improvement in perceived complexity and readability.
0: https://en.wikipedia.org/wiki/Cyclomatic_complexity https://en.wikipedia.org/wiki/Cyclomatic_complexity
1: https://github.com/bbatsov/rubocop https://github.com/bbatsov/rubocop