DEV Community

Discussion on: Code style rules that are actually useful

Collapse
 
ericcurtin profile image
Eric Curtin

I only really write functions when I want to de-duplicate code or unit test a specific few lines. Don't believe in using a function just to give a block of code a name, a comment can do that. When code gets very nested is another time I start using functions, so I'm not like 4 tab lengths in. Putting code in 10 line functions for the sake of it can actually kill readability as you have to keep navigating around the code-base to read.

Collapse
 
vonheikemen profile image
Heiker

Hasn't been a problem for me yet. Code is still fairly readible.

Guess I'm just trying not to repeat the mistake that I see in the legacy apps the I have to mantain at work. In the codebase that I deal with daily is actually common to see methods that have more than 500 lines, and that's just wrong. People are actually scare to touch one of those methods.

The goal is to write functions that anyone can read and have the confidence that they can change stuff, make it better, or delete the whole thing if it's no longer necessary.