DEV Community

Cover image for A musical lesson on learning hard things, and a polite game of tic-tac-toe
coding-titan
coding-titan

Posted on

A musical lesson on learning hard things, and a polite game of tic-tac-toe

I have a programming nemesis: Python dictionaries. I don’t know why, but for some reason they never clicked for me. Lists, no problem. Tuples, sure. Even more complex stuff like classes - you got it, pal.

But dictionaries, for some reason, are the ungodly spawn of all my bad karma. I just can’t wrap my head around them.

Growing up, I learned to play the piano by myself. I got quite good - I even got in to a music-specialised high school. There, I finally got myself a teacher. Come first class, we played around a bit to give her a feel for how well I played (she assessed me as a level 3 of 3, thanks for asking), and then she gave me some homework.

I went home, energized by my recent ranking. This should be no problem for a level 3 guy like me!

I sat down at the piano, looking properly at it, and… well, it was hard. I mean 8-keys-pressed-at-once-with-no-discernible-system-over-and-over hard. I tried a few times, then went back to playing stuff I already knew. Screw that.

Before I knew it, a week had passed and it was time for my second lesson. I dreaded going - I hadn’t so much as gotten through the first couple of chords. When I got to the lesson, sullen and silent, the teacher chirped “How did the homework go?”. I was devastated – I had been exposed as a fraud, who couldn’t even play the first homework assigned to me.

“You didn’t do it, did you?”, she said. I replied that I hadn’t.

“I knew that you wouldn’t. That’s why I gave it to you! When I heard you play, I could tell right away that you like to stick to what you know, playing what’s already comfortable. That’s not how to get really good at something. You have to do things that are uncomfortable. So, for the foreseeable future, we will work on fixing that.”

I was surprised, and felt quite dumb.

“For this week’s homework, I want you to play just the first 4 measures of the song” (ergo the first couple of seconds). “We’’ll start working on it here in class, and then you can continue at home. OK?”

I agreed, and as the weeks went by we slowly progressed through what turned out to be a quite pleasant Bossa Nova tune. After a few months, I could play the whole thing without hiccups, and we moved on to less hardcore material. I forget what.

But I never forgot the experience with the Bossa Nova challenge.

Image description

Right now, I’m not learning how to play the piano. I’m learning Python. When deciding what to build for my next practice project – crafted to perfection, useful to nobody – I went the classic tic-tac-toe. I made a quick plan, based on a grid system, and then got to coding. I started off by making a couple of lists, and figured that the easiest way would be to move coordinates between three lists - one for available coordinates, and one for each player’s placed circles and crosses.

Then I remembered the Bossa Nova lesson, and realized I was doing the same thing all over again - sticking to what’s comfortable. I came to a realization - I needed to make the game dictionary-based. Not because it necessarily is the best way to make a tic-tac-toe game, but because I felt a resistance there. I didn’t want to do it, because I was not entirely sure how to do it. In fact, I wasn’t even sure how to script the logic for winning the game.

After some initial frustration, I got it working. Having gone through the uncomfortable-ness of manually creating a coordinate system in a dict, I rewarded myself with adding some creative writing to give the game some personality.

You can find it here.

I’m realizing that coding, like learning any skill, requires you to be uncomfortable - doing things you’re not sure how to do, staying patient and working through it. It may provide som initial resistance, but when you get to the finish line - whether that means a catchy tune or a text-based tic-tac-toe game nobody is going to play - it feels so much more worth it. Just remind yourself of that, and keep going - oine measure, or dictionary, at a time.

P.S. Would love any feedback on the code!

Top comments (0)