The Connection Between Programming and Writing
While working on my Spotify algorithm project yesterday, I ran into some trouble. I previously created two functions:
- Weighted_artist_pop
- Weighted_track_pop
These functions iterate through a CSV to find popularity metrics and use probability to standardize the values.
But this time, I wanted to do the same thing without standardizing them. So I copied the code and made some tweaks.
That’s when I realized a mistake I made earlier.
If you look at the image below, you’ll see a for loop that iterates through the given CSV file and searches for a column that starts with the string ‘Artist_Popularity.’ That’s cool and all until I remembered the file I’m iterating through only has one function that starts that way.
This means the two weighted popularity functions got through two time-consuming steps for no reason.
So I went through my Python script to optimize my code.
Once I finished making changes, I saw a major connection between programming and writing.
In case you didn’t know, I’m a writer at heart. I’ve written:
- A 90,000+ word novel
- A weekly newsletter sharing personal stories
- A weekly newsletter about movies and marketing
- Thousands of tweets and threads over a four months
And now I’m here, writing multiple times per week for Dorky Data.
If that’s not enough to make me a writer, I give up. I’d have to trash my website and toss my laptop in the trash.
Jokes aside, here’s what the connection I made…
A majority of the writing process involves editing. Often, it’s best not to edit right after writing. Waiting 12-24 hours before returning to your work allows you to come back with a fresh mind and review what you’ve written from a new perspective.
The same works with programming.
Sometimes, you need to let your work marinate for a few hours before coming back to optimize it. If I had created my raw popularity functions directly after creating the weighted popularity ones, I wouldn’t have noticed my mistake since I would have copied and pasted my code from one function to another.
But returning the next day with fresh eyes helped me spot my mistake and ensure my code is (almost) as efficient as possible.