Some Kind of Pythonic Magic

I’ve been tinkering with my nascent Python “game”. Each time I expand on it, it’s to learn a bit more about Python, or some feature or module that seems appropriate. To that end, I’ve heard that Python comes with “batteries included”. Meaning the standard suite of tools that come with a typical install of Python is extensive.

To that end, it feels like the built in libraries are somewhat magical in how well they handle things. I’m comparing to C, whose idea of standard libraries feels unbelievably spartan in comparison. Different tools for different jobs, I suppose. There are really weird, simple pleasures in programming in Python. Consider:

import os from pathlib import Path scoreboard = Path(os.environ.get("XDG_DATA_HOME") + "/guessing-game/scores.txt") if scoreboard.exists: with"a+") as scores: // Game code here

This is delightful. I don’t have to do stuff like count to see if the return from Path is greater than 1 to indicate existence of a file, like I have to in JS when selecting elements, Path comes with a ready-made exists method that does exactly what it says on the tin. Oh, and the whole thing figures out the path on POSIX vs Windows path styles. Scrumptious!

I know my little honeymoon phase with my incredibly basic script will probably come crashing down when I want to do stuff more complicated, like have a high-scores list, but I’m enjoying it while it lasts.


Python Games

Yesterday, I posted about being generally uninterested in programming. Burnout is a pretty common case, and add on my preexisting condition, and you’ve got yourself an issue. In order to combat that, I decided to take up learning a very popular language: Python. I’ve always admired Python from afar. It seemed like a well-organized language with some interesting components. There is a module for everything and while performance isn’t quite as fast as C, it’s interpreted, so it’s to be expected.

To that end, I began writing a small game. Just guess a randomly chosen number in a range. You get a couple of attempts. Nothing hard, nothing that I’d have to dig too deep into learning how the whole thing works. A test to see if I enjoyed it.

I did enjoy it. For the most part. Learning (or relearning) the Python grammar after being embedded in C-styled languages for so long was a little bit of a hurdle. Overall, I was able to get things put together pretty well. I think I’m going to continue to extend and learn more about the deeper functions and modules available in core.

I’m not unfamiliar with programming, though, I’m sure Gordon Ramsay is not far off, eying my bread for a little sandwich making.

Idiot Sandwich

If you want to follow along, you can check out the edits and commit history I’ve posted to the repo. I may even enable issues to allow people to chime in where I might have done something wrong.


Broken Programming

I think something is wrong with me. I have, in the past, been an avid programmer. Programming was something I could do and it made me happy because I was able to affect change in the world, even at a small level. I spent many-a-year debating text editors, programming languages and generally being in it.

I don’t anymore. What I mean by that is that I don’t care for, or find programming fun or satisfying anymore. Even with this blog, I’m using the default twentytwenty theme with some modifications for color and other minor tweaks. I used to write my own themes and build my own components. I would labor endlessly over the smallest details, and tweak things until it was made “correct” in my eyes.

Now? Now I can’t be bothered to even open a text editor except out of novelty. I banged out a couple of lines of code that I modified from Kev for old posts, I dropped in some CSS to make it look okay and I was done. Opening a modern theme is like wading into a jungle of templates, CSS, JavaScript, Node.js, build systems and more. Even with IDEs like PHPStorm, I just can’t muster the energy to work on it.

I think I’m broken. Or at least I’ve broken my desire to code. I wonder if I wore it out, or if it’s a “young man’s game” and I’ve just past my prime. I don’t think that is the case, since I threw together a 500-line collection script for work that I was plenty interested in a week or two ago. No, I think my problem is it’s all so complicated now. The barrier to entry is high. Really high. You need to have gigabytes of compilers, build tools and linkers to just even bang out a “Hello World”. I feel like we’ve built this digital Tower of Babel and it’s looking a little creaky at this height.

Back in My Day!

The wonders that modern-day systems have brought is amazing. When I was a kid, using computers meant you knew something. It was a talent. Most people either did basic data entry on it or were programmers. Anything in between was hard to find. I guess that makes me an old man yelling at a cloud.

A screen grab from a Simpsons episode. A hand is holding a cut out from a news paper. On the clipping, a picture can be seen of an old man shaking his fist and yelling angrily at a cloud. The article is entitled "Old Man Yells at Cloud"
Back in my day, clouds were just clouds, not other people’s computers!

Maybe I should pick up C, or Python and kick around some simple programs. Get an idea for something and work on it until completion. A sort of hobby project. I’m fighting for time less with video games as of late, so I might be able to squeeze in something like that.


Powershell: Love it or Hate it

Powershell is in a weird place. For me, at least. It bills itself as a great cmd.exe replacement with greater scripting abilities than it. While the scripting components are drastically better, it still just… sucks as a shell. This is especially glaring when you have tools like WSL and Cygwin which can provide real, battle-tested CLI interfaces that work surprisingly well on a foreign environment like Windows.

That all being said, it is a fantastic environment to write scripts in. It seems like every release has more integration into the environment. The function naming around verbs makes it very discoverable and, with few exceptions, it’s actually easy to understand. There are still weird places where you have to invoke some .Net tomfoolery, but even that seems well integrated. Honestly, if you need to automate something for Windows, Powershell is what you need.

The Windows Factor

The key word in that last paragraph was “Windows”. This all works great if you are running Windows. The same cannot be said of the open source Powershell core that is available on Mac and Linux. While many of the tools work in much of the same fashion, shelling out to any existing tools makes the experience feel… frustrating. Unix-style utilities deal in text. While that means you often have some somewhat fragile scripts that have to manipulate that text, it’s always going to be text. Powershell deals in objects. This is great when working, because you can get properties easily, hand off data to other scriptlets and everything sort of handles it. Except when you deal with text.

Powershell doesn’t do text very well. I mean, it handles much of the basics fine, but if you want to script something in Powershell on a *nix, then you’re going to have a bad time. Which brings me around to the whole idea of Powershell being on non-Windows platforms. Why?

Powershell, but Why?

I get that “Microsoft <3 Linux/Open Source” or whatever. I also understand that in theory Powershell should make it easier to manage Windows systems remotely without having to RDP into a system, but none of this seems to work the way it’s supposed to. I don’t think anyone is running PS Scripts on *nix for their own automation, and if they need to manage Windows systems, they’re often using a Windows already. I dunno, it feels like a solution waiting for a problem.


Children, Behave!

Thanks to a handy post by Kev Quirk, I was able to wrap my head around a bunch of stuff I had been meaning to get to with this blog. The big one was making custom edits to the theme template. Now, with WordPress, if you update your theme, any material edits you made to those files will be overwritten. To counteract this, WordPress implemented a concept known as “child themes“. These are skeletal themes that inherit most of the parent’s look, feel and functionality, but layer new stuff non-destructively. The advantage is that you can hack away at the child theme, making it into what you want, and when a theme update comes out, everything is still cool.

Initially, I just wanted to add the informational banner that Kev had implemented. That was simple enough. Looking through my very old posts, though, I noticed that my Garrett Quotes had the banner on them in addition to regular posts. While it’s not a detriment to the quote, it is an incorrect eyesore. So I began work on exempting certain categories. That lead me to updating and tweaking the theme, bit by bit.

In working on all this. I rekindled my desire to code and to organize with git. I implemented git flow in this repository and began tracking defects and hot-fixes and releases. It’s actually kind of fun to code, again!

While I’m no master codesmith, I am however tempered by my previous work. I strive to be more clear with the code I write. I comment everything. I also try to adhere to a more rigid standard style. While this may slow me down, it also means that I can look back on code and understand it more easily.