Andrew Ducker (andrewducker) wrote,
Andrew Ducker
andrewducker

Something I'd like to see in C#

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);



Original post on Dreamwidth - there are comment count unavailable comments there.
Subscribe

  • Interesting Links for 12-05-2021

    How To Do Everything You Need To Do With a Newborn When Your Partner's Gone Back To Work (tags: babies viaJane ) This illiberal Queen's Speech…

  • Interesting Links for 11-05-2021

    Scottish independence referendum to go ahead when Covid crisis 'stable,' says SNP (tags: Scotland independence pandemic ) How the transphobes…

  • Interesting Links for 10-05-2021

    Here's Britain's beloved royal family selling access to Putin (tags: UK monarchy Russia corruption ) Serious questions for the Electoral…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 17 comments

  • Interesting Links for 12-05-2021

    How To Do Everything You Need To Do With a Newborn When Your Partner's Gone Back To Work (tags: babies viaJane ) This illiberal Queen's Speech…

  • Interesting Links for 11-05-2021

    Scottish independence referendum to go ahead when Covid crisis 'stable,' says SNP (tags: Scotland independence pandemic ) How the transphobes…

  • Interesting Links for 10-05-2021

    Here's Britain's beloved royal family selling access to Putin (tags: UK monarchy Russia corruption ) Serious questions for the Electoral…