Jun. 15th, 2015

andrewducker: (Default)
It's quite common to end up writing methods that take booleans to say whether certain functionality should be switched on or off. It would be nicer to use enumerations, not least because that way you couldn't end up getting them the wrong way around.

Something like:
void DoSomething(Thing thing, bool withLogging, bool withRollBack){}
which would then be called with:
DoSomething(myThing, true,false);

Looking at that, it's hard to tell whether it's logging without rollback, or rollingback but not logging.

However, the overhead of creating additional enumerations is enough that it puts people off of creating them most of the time. If there was a simple inline declaration format then this would be greatly simplified, and much more likely to be used:
void DoSomething(Thing thing, enum logging{Yes,No}, enum rollBack{Never, OnFailure}){}
which would then be called with:
DoSomething(myThing, logging_Yes, rollback_Never);

Which I think we can all agree is a lot clearer than:
DoSomething(myThing, true,false);
andrewducker: (Default)

August 2025

S M T W T F S
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 9th, 2025 06:18 pm
Powered by Dreamwidth Studios