OO code can provide modularity which can greatly improve the ability to make changes without breaking other code. On the other hand, when applied poorly it can have they opposite effect.
It's not the concepts, it's how they are applied.
OO code can provide modularity which can greatly improve the ability to make changes without breaking other code. On the other hand, when applied poorly it can have they opposite effect.
It's not the concepts, it's how they are applied.
Languages that make it easy to define "local" functions that operate on implicitly captured state can help --- e.g., C++, Lisp, sometimes Java --- but only where it makes sense. I don't believe in splitting functions solely because they're too long.
You don't even need that. In many languages, you can have {}-delimited blocks which cause variables inside of them to go out of scope when control flow exits them. I've used that to great effect in Perl to keep intrinsically large functions maintainable.
this is a problem with the architecture, not a problem with small functions.
Very short functions, I've found, encourage this kind of over-testing and just add friction to code changes without actually improving system reliability.
You're better off testing at major functional boundaries, and if you do that, the length of functions matters less than the interface major modules provide to each other.
Otherwise known as integration testing, which is far more useful than unit testing because bugs, especially regression bugs, more often occur in the system, than in specific functions.
You can have as many unit tests as you want, but until you have integration test, you have zero coverage for the really complex part of your code.
Unit tests are great for algorithms though.
I think the real reason people don't like small function is simply code navigations - which honestly is a poor excuse. That's an editor/IDE problem
Agreed that you should never split functions due purely to length, but a super long function smells bad because it suggests poor separation of concerns (if a function's super long then it's probably doing a lot more than one thing). Sometimes this is a problem, sometimes (like the case of Carmack's big main loop function) there's just a lot of small things to do sequentially and one big function is as good a way to represent that as any other.
Aside from separation of concerns when you make many, many functions, you have to come up with So Many Names.
add 10 ; add 10 to accumulator.
becomes int AddTen(int x) { return(x+10);}