S
20

My kid asked me why my code was so long and it made me stop and think

I was working on a simple number guessing game in Python last night, and my 10-year-old looked over my shoulder. She pointed at my screen and said, 'Why did you write all that? Can't it be shorter?' I had like 20 lines of if/else statements for the game logic. I realized I was just writing what I knew, not the best way. I spent an hour looking up loops and functions and cut it down to 8 lines. Has anyone else had a simple question make you realize you were overcomplicating things?
3 comments

Log in to join the discussion

Log In
3 Comments
thea_wood86
But what if longer code is easier to read later? I've gone back to my own short stuff months after and had no clue what I was thinking.
6
dylanmurray
Yeah @thea_wood86 has a point. Sometimes a few extra lines for clear variable names or a short comment saves so much time later. Like, writing "calculateTotalWithTax" is way clearer than "calcTT" when you come back to it. The goal is to write for your future self who forgot everything. Short, clever code can be a puzzle you gave yourself, and that's no fun to solve.
5
simonh74
simonh742mo ago
Totally, @thea_wood86, I read that same idea somewhere.
4