Skip to main content
added 73 characters in body
Source Link
alephzero
  • 1.3k
  • 1
  • 8
  • 8

IMO the root of the problem is that this piece of code shouldn't even exist.

You apparently have three independent conditions, and three independent actions to take if those conditions are true. So why is all that being funnelled into one piece of code that needneeds three Boolean flags to tell it what to do (whether or not you obfuscate them into an enum) and then does some combination of three independent things? The single responsibility principle seems to be having an off-day here.

Put the calls to the three functions where the belong (i.e. where you discover the need to do the actions) and consign the code in these examples to the recycle bin.

If there were ten flags and conditionsactions not three, would you extend this sort of code to handle 1024 different combinations? I hope not! And ifIf 1024 is too many, 8 is also totoo many, for the same reason.

IMO the root of the problem is that this piece of code shouldn't even exist.

You apparently have three independent conditions, and three independent actions to take if those conditions are true. So why is all that being funnelled into one piece of code that need three Boolean flags to tell it what to do (whether or not you obfuscate them into an enum) and then does some combination of three independent things?

Put the calls to the three functions where the belong (i.e. where you discover the need to do the actions) and consign the code in these examples to the recycle bin.

If there were ten flags and conditions not three, would you extend this sort of code to handle 1024 different combinations? I hope not! And if 1024 is too many, 8 is also to many, for the same reason.

IMO the root of the problem is that this piece of code shouldn't even exist.

You apparently have three independent conditions, and three independent actions to take if those conditions are true. So why is all that being funnelled into one piece of code that needs three Boolean flags to tell it what to do (whether or not you obfuscate them into an enum) and then does some combination of three independent things? The single responsibility principle seems to be having an off-day here.

Put the calls to the three functions where the belong (i.e. where you discover the need to do the actions) and consign the code in these examples to the recycle bin.

If there were ten flags and actions not three, would you extend this sort of code to handle 1024 different combinations? I hope not! If 1024 is too many, 8 is also too many, for the same reason.

Source Link
alephzero
  • 1.3k
  • 1
  • 8
  • 8

IMO the root of the problem is that this piece of code shouldn't even exist.

You apparently have three independent conditions, and three independent actions to take if those conditions are true. So why is all that being funnelled into one piece of code that need three Boolean flags to tell it what to do (whether or not you obfuscate them into an enum) and then does some combination of three independent things?

Put the calls to the three functions where the belong (i.e. where you discover the need to do the actions) and consign the code in these examples to the recycle bin.

If there were ten flags and conditions not three, would you extend this sort of code to handle 1024 different combinations? I hope not! And if 1024 is too many, 8 is also to many, for the same reason.