3 ms·
I come from the opposite camp. I detest functions that are five pages of boolean logic, which I guarantee you contain at least a dozen bugs, no matter how much
by jiggawatts 5y ago
I come from the opposite camp. I detest functions that are five pages of boolean logic, which I guarantee you contain at least a dozen bugs, no matter how much you think you've tested it.
Code coverage is like those skin creams that say "Scientifically tested!" on the label. Yeah, well, tested doesn't mean that it worked. It just means that there was a test.
Watch this video of Andrei Alexandrescu's talk in CppCon 2015: https://www.youtube.com/watch?v=LIb3L4vKZ7U https://www.youtube.com/watch?v=LIb3L4vKZ7U
I've done things like this in my career, and it's always worked out brilliantly. Bugs just evaporate when you let the compiler "combine" things for you, instead of just plopping everything into a bowl and mashing it together with your hands like some sort of animal.
Especially in today's C++ or Rust, you can "have your cake and eat it too". It's possible to build up these nice, single-purpose class hierarchies and combine them into complex, powerful constructs via templates / traits. The compiler takes care of the edge cases for you, because it never gets bored or distracted. There's no performance downside because of static dispatch, inlining, and aggressive optimisers.
- rmbyrro 5y agoBut having a function spanning five pages isn't smart practice, regardless of OOP or Functional style.
- marcosdumay 5y agoWell, usually the way to avoid a 5 pages function is by encapsulating concepts away into self-contained code. It is not by encapsulating it away into code colocated with state. OOP is not the answer here. Class hierarchies can be, as long as they are not OOP and "classes" are just synonym for "modules". Code and data colocation has its uses, but it's normally best fit for interface layers than internal code.