Article 7A3JF CodeSOD: Switched On Readability

CodeSOD: Switched On Readability

by
Remy Porter
from The Daily WTF on (#7A3JF)
Story Image

Jon has a team mate that has a coding quirk. They tend to write this pattern a lot.

switch (someEnum){ case EnumType::TargetValue: doStuff(); break; default: doOtherStuff();}

Specifically, they have these single branch switches. Usually when using enums, but they've even done it for booleans a few times, like:

switch(someBool){ case true: doStuff(); break; default: doOtherStuff();}

It's not 100% true that they eschew if statements, but they rarely use them. They write basically any condition via a switch. Why? No one knows. Not even them. "I just think it's easier to read."

[Advertisement] Plan Your .NET 9 Migration with Confidence
Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments