25
Pro tip: Used to write code all in one go now I write it broken into small functions
Back when I started coding 3 years ago I would cram everything into one giant block of code like a maniac, but now I split it all into tiny functions one at a time and test each piece as I go - which camp are you in and when did you flip?
3 comments
Log in to join the discussion
Log In3 Comments
taylor_flores1d ago
ryang77 nailed it with the debug thing - small functions are a lifesaver when something breaks. I used to have this one script for scraping data where everything was in a 200-line monster, and finding a typo in a variable name took forever. Now I'll break it down like: fetch_page(), parse_html(), clean_data(), save_csv(). That way when parse_html() fails because the site changed its layout, I only have to fix 10 lines instead of hunting through 200. The key is testing each tiny piece right after you write it, not waiting until the whole thing is done. Once you get used to it, it feels weird to go back to big blocks.
7