you are viewing a single comment's thread
view the rest of the comments
[–] 4 points 1 year ago (4 children)

What pattern should be used instead?

  • source
  • parent
  • hideshow 4 child comments
  • [–] 5 points 1 year ago (2 children)

    The rule I see is functions should be fairly atomic and almost obvious what they do in context of the code.

    At least for my small brain that's how I like it. I can understand some complex abstractions but rembering that actually this function behaves in three different ways depending on what flag is set is awful. It means you could look at one example and be totally wrong in another. Ideally you could guess the functions purpose even in a black box setting based on inputs outputs and the name should then make it obvious.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 4 points 1 year ago (1 child)

    The example that the other commenter gave did not require the user to input the flags. As far as I understand, they mean there would be a number of secondary functions that will call the other with the correct parameter.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 7 points 1 year ago

    "The one that makes sense"

    Patterns and principles are guidelines, not rules. You don't want to just apply them blindly.

    You need to balance principles. Over-applying the DRY principle can lead to more complex logic that's harder to understand than if you just wrote code in-line.

  • source
  • parent