15
The IF/ELSE habit that finally clicked after 14 failed attempts
I kept writing these huge nested if chains to check user input. Last night I tried a switch statement for a simple menu in my practice app and it cut like 30 lines down to 12. It hit me that the problem was never the syntax, it was that I was treating every condition like it needed its own layer. Why did nobody tell me to just use a lookup table for the valid options first? Has anyone else had that moment where they realize they were overcomplicating basic flows for months?
1 comments
Log in to join the discussion
Log In1 Comment
emmap1613h ago
Oh man, that switch statement moment is the best feeling. But I gotta gently push back on the lookup table thing. Those are great for exact matches, sure, but they fall apart fast if you ever need to check ranges or do any sort of validation beyond "is this one of these five strings." I mean, I tried using one for a temperature converter once and ended up with more code than if I'd just written three if statements. Maybe it's just me, but I think the real win is knowing when each tool makes sense instead of forcing one pattern on everything. That said, congrats on the 30 line cut, that's a huge win regardless.
4