F
23

I thought writing my own functions was a waste of time

For months, I just copied and pasted the same few lines of code over and over in my Python scripts. My friend pointed out a 50-line script I wrote that could be just 10 lines with one function. Seeing that side-by-side finally clicked for me. Anyone have a good example of a simple function that saved them a ton of typing?
3 comments

Log in to join the discussion

Log In
3 Comments
andrew_shah
Yeah I was the same way, always telling myself it wasn't worth the extra step. What got me was formatting dates for my kids' school calendars. I had this ugly block of code repeating strftime stuff a dozen times. Wrapping it in one function called clean_date() cut out so much clutter and fixed my mistakes in one spot.
3
tessalane
tessalane9h ago
My roofing estimates used to be a mess of repeated math. Wrote a tiny function that takes square footage and pitch, spits out material costs. Went from checking the same calculator fifty times to one clean line of code. Feels like cheating now.
2
nora_murphy
Ever try that with your grocery list math?
-1