Small pleasures of programming (2020)
terrycrowley.medium.com
terrycrowley.medium.com
I recently had the pleasure of reusing some old code I wrote for a previous puzzle. I pulled the code out into its own module, added some docs, rethought some decisions, and got it working better. I learned how implementing protocols works and made it work with all the built in Enumerable functions. This is one of the first times in my life I looked at year-old code and thought "hey, this is actually useful!"
The project has been an awesome learning experience and entirely self directed. I pulled in a cool graph library for one puzzle in 2020. I wrote custom mix task for generating puzzle skeletons. It even downloads the puzzle input automatically now! I learned to use a benchmarking tool to satisfy some curiosity about differences between two different implementations. I've gotten way better at using recursion to solve problems. Today, I cloned the Elixir source code to get a better understanding of a particular language feature.
None of this stuff was necessary, and indeed it's not even technically useful - these puzzles are toy code, and I'm sure my implementations could be better. But I've just been enjoying the hell out of Elixir and going the extra mile doesn't feel like work, just more fun to be had.
I’d set the direction flag as part of programming the palette registers and forgot to clear it before the loop that displayed the text.
As a result of the “wrong” direction flag all my text appeared backwards.
I added a CLD instruction to clear the direction flag, “costing” one byte, reassembled and re-ran the code and found that it worked as-expected.
Then I got the idea to go remove the CLD (getting my byte back) and just reversed the text strings in the source. Then, when displayed with the “wrong” direction flag the text appeared “right”.
I still giggle about the simple pleasure that brought me, 26 years later.
Those CPU are very simple, you have like a dozen instructions, 4 or 5 addressing modes, that's it. You can infer the cycles count from each instruction by the addressing mode, mostly.
The machines those CPU run are a bit more complex than just the CPU, but after some time you get to know them perfectly. You can think about an algorithm in your shower or on the way back from work, and code it like a robot, directly from your brain, you figured everything out to the last detail just in your head.
That's very, very rewarding. I've never got this kind of feeling while playing those coding games, like Zachtronics's, although I've enjoyed some of them. I played Factorio for hundred of hours, that's very pleasant, but the UI gets in the way and you know the problem already has been solved.
I very much encourage you to try assembly on 8bits computers, coding graphical effects and demomaking stuff and all. That is, if you don't have kids and all, that takes time :)
My most recent experience was when I was learning Next.js. As a distributed database engineer, I nearly have no knowledge of web development, but I really want to show some database demos on the Web. So one night, I began to learn Next.js from scratch - I tried to connect to the database, query the result and then render the chart. After I deployed the application on Vercel, two hours had passed.
I felt tired but very excited. I believe this is the pleasure of programming :-)
In past, all we could do was fire. Later light. Now we can make them store, process and present information.
Not everybody can do it, just programmers.