Want cleaner code? Use the rule of six
davidamos.dev
Want cleaner code? Use the rule of six
1–10 of 352 posts
Re: Want cleaner code? Use the rule of six
#2But I do agree on keeping individual lines, if not entire statements, small and simple. The ruby chainsaw is a great tool for that. I find a chain of simple statements arranged in a flow to be more readable than using lots of intermediate variables.
Re: Want cleaner code? Use the rule of six
#3Re: Want cleaner code? Use the rule of six
#4in the example given, I started with 10 things to keep in working memory. now that we've added a named function or a named variable, we have 11. I suggest it is at least as important to name things well (or add comments) as it is to break lines up.
So, it's easier to remember the three numbers 34, 765, 812 than the eight numbers 3, 4, 7, 6, 5, 8, 1, 2.
Refactoring code into separate functions with descriptive titles is probably a lot like combining numbers.
---
† Well, the article says 4–6; I'd always heard the average was around 7.
Re: Want cleaner code? Use the rule of six
#5Re: Want cleaner code? Use the rule of six
#6Re: Want cleaner code? Use the rule of six
#7This seems like an interesting heuristic for anything that could automatically either generate or "format" code - a little more semantic than just relying on a text parser