2 ms·
The problem is not the office, but you having a method that takes 6 boolean. A method should not even take one boolean ever. A boolean simple means you need t
by segmondy 8y ago
The problem is not the office, but you having a method that takes 6 boolean. A method should not even take one boolean ever.
A boolean simple means you need to split the method.
- inertiatic 8y agoThat function was an atrocity but you're taking things a bit too far. There are occasions where a longer method makes things more readable. And "a method should not even take on boolean ever"? So you split that method into two methods, and then every call site needs to have a conditional check. Or you hide that under a method that checks and calls your 2 methods. That new method, takes a boolean. Oh...
- e12e 8y agoQuite. 6 booleans can just be a way to represent 6 flags - it might be modeled as a state-machine - but depending on the language and code base passing in 6 booleans to a function (or procedure) might be a fine way to isolate the entry point. Now given that you have such a function, you need to be able to concentrate in order to refractor it. I've recently untangled some hairy old front-end js code that takes in parameters from an "advanced" search form in order to validate the input, and construct a proper search. Basically the same thing, but with much more than six inputs. After squinting at it for an hour and trying a few things, it boiled down to a few simple checks and a map() over the remaining parameters.
- segmondy 8y agoI'm not disputing that a longer method is fine. But booleans going into a method makes it hard to tell what the method is doing. Every call needs to call explicitly what it needs. Every method needs to also tell exactly what it does. State is the enemy of understanding what code does, the deeper the state lies, the harder it is to unravel.
- trhway 8y agohe probably would have seen it himself if he were able to concentrate...