3
vane
3y

bool values in function arguments

Comments
  • 1
  • 3
    bool 🐂
  • 0
    I’m definitely not a fan either, unless they’re named.
  • 0
    I guess I see what you mean
  • 2
    What?
  • 0
    Booh!
  • 3
    you have method foo() then cause you’re lazy and you think saving couple bytes can improve shit storm that’s coming, decided to not copy foo code you add foo(isfucked=false) and next year it becomes foo(isfucked=false, isreallyfucked=false) cause someone modified isfucked logic in the meantime cause isfucked due to business requirements is now isnotfucked then it’s indeed really fucked, from maintainability and design stand function should have one purpose but number of bool arguments exponentially multiply this purpose and makes code unmaintainable in the long run
  • 2
    @vane Swiss army knifes are indeed hard to maintain if not well-covered by unit tests.

    Often, a swiss army knife is the most practical solution for dealing with real world constraints (rules imposed by law or management for example). Then it might be still better to pass pure functions to the swiss army knife instead of bools and have shortcut functions covering the most common cases.

    But sometimes, just adding one well-named bool arg or maybe even two (but three is really pushing it) actually can be the right eay to do it...
  • 1
    If you're in the OOP realm, you could always be passing it an object containing properties about said booleans. This way, the method's own signature won't risk exponential growth once the fucked up logic degenerates further.
  • 1
Add Comment