T
18

My first project went from 200 lines of messy code to 40 clean ones in one afternoon

I was working on a little weather app for a school project and had this huge block of if/else statements covering every possible condition. A buddy from a local meetup looked at it and showed me how to use a dictionary lookup instead. It took me maybe 3 hours to rewrite it and I couldn't believe how much simpler it was to read and add to later. Has anyone else had a refactor moment that made you feel like you leveled up?
2 comments

Log in to join the discussion

Log In
2 Comments
david_rivera4
oh man that reminds me of this guy I know from a coding forum I lurk on. he had this huge project for a local pet shelter where he was tracking animals coming in and out. the original code was like this massive switch statement with a case for every possible pet type. like case "dog": do this, case "cat": do that, case "hamster": do something else. it was getting ridiculous. then he found out about using an object map with functions as values. he mapped each pet type to a function like { dog: processDog, cat: processCat } and it cut his code from almost 400 lines to maybe 80. he told me it felt like unlocking a cheat code for his brain.
5
henry_martinez
Man that's a great story @david_rivera4. Nothing like the rush of realizing you can cut your code down to a fifth of what it was. I've been there with some old projects and it honestly feels like you leveled up as a programmer.
6