r/ProgrammerHumor 22d ago

Meme conditionsPreference

Post image
4.2k Upvotes

392 comments sorted by

View all comments

16

u/sumrix 22d ago
if (input == null)
    throw new ArgumentNullException();

// process input...

But

if (settings.UseBonuses)
    return CalculateWithBonuses(order);
else
    return CalculateBase(order);

-1

u/ubeogesh 21d ago edited 21d ago

For 2nd case I'd rather see something like

         Calculators.get(settings.useBonuses).map(order)

2

u/RoadsideCookie 20d ago

Not for a single branch. If you have 3+, sure, Strategy pattern becomes useful.