Random coding advice: Avoid Duplication

A lot of code I see from new coders shows a thought process like this:

— I’ve got a bunch of matches the player can burn
— after a match is burned, it is moved to a container for used matches; that way I can count how many matches have been burned by writing “the number of matches in the used matched depository”.
— after writing that enough times, I get tired of the verbosity and want to be able just to write “the number of burned matches”. Okay, I’ll also give the matches a “burned” property when I use them up!

Now the burning code looks something like this:

 Instead of burning something with a match:
     [other stuff];
     move the second noun to the used match depository;
     now the second noun is burned.

and other places in the code uses both “number of matches in the used matches depository” and “number of burned matches” to refer to (what the author hopes is) the same information.

This is asking for trouble. Sooner or later you’ll move the object but not set the flag, or change the way the multi-process destruction procedure happens in one place and not in the other. As soon as you do, there will be bugs.

So here’s the advice:

Do not put the same information into your world model twice.

Continue reading “Random coding advice: Avoid Duplication”

Two From the List

mimic-threatenI’ve been playing with a few things on the enormous to-be-played list from a few days ago, though of course there are so many things on there that it will take quite some time to get through.

Braid: I have now finished. It’s of course a masterpiece in the game-play area, and doesn’t need me to say so. I usually have a really hard time getting through platformers, since I don’t have the right combination of patience and skill. As advertised, Braid minimizes the amount of frustration involved in playing a platformer while offering a diverse range of genuinely interesting puzzles; and while there were still a handful of these that were too finicky and that I would have been happy to skip, nonetheless it was the best time I’ve ever had with the format.

As far as storytelling goes, it’s a bit more confused: there is some really intriguing material in the final level, in which the meaning of events is revised and reinterpreted in a way that naturally connects to the gameplay itself; and even before that point, many elements of the game are framed so that the play is metaphorically significant.

But what I get out of all that is not really a story (good luck finding two people who even agree on what happens in Braid) so much as a series of meditations on some of the common problems in relationships and self-definition. Some of it’s thought-provoking, some a little on the obvious side. Admittedly I usually find this kind of content under ask.metafilter’s human relations tag rather than in a game, and I’m generally encouraged when a game branches out to incorporate new material. So hooray for that.

Nettestadt Troll was recommended to me as an example of good Ren’Py work, and I’m afraid I didn’t get nearly as far with that. The premise is uncomfortable to start with: girl gets abducted and raped but discovers she kind of likes it and/or falls in love with her captor. This is a fantasy to be found in many forms of literature from Menander to a certain genre of 1970s romance novel, but it’s something that would need to be handled with a fair amount of psychological sensitivity in order to be a story I want to read. Otherwise, what you have is basically porn for a specific audience.

I wasn’t crazy about the art or the prose quality, either, and the pacing left me kind of bored during the first few chapters; as for the world-building, it’s extremely vague and careless, featuring both alchemists and telegrams, feudal hierarchies and shops with “receptionists”.

I did stick with it for a while, though, in case this was a case of poor writing craft combined with a strong storytelling sensibility. Unfortunately, once there started to be choices to make, they were often on the level of random and incidental choice: e.g., what dish do I make for my supper while waiting for the troll to come home and rape me again? It’s a bit less inane than Dream Day Wedding, but the choose-your-own whatever aspects display the same lack of significant agency that I complained about there.

Recent Playing

tobin_asmallfavor_titleA Small Favor. A point-and-click adventure that I found particularly engaging. My mileage varies a lot with these kinds of games: sometimes I like them a lot, sometimes the frustration level is just too high for me to tolerate. But this one worked for me pretty well. I only had to look at a hint for one thing, and in retrospect it was a completely fair puzzle that I was just failing to think through right. It is as far as I can tell impossible to make unwinnable.

Minim. It’s a set of 35 mathematical and spatial puzzles, very simple but elegantly presented. No story or anything here, but I liked this one a lot — though I think the game isn’t very well laid-out in terms of escalating difficulty, because I got really stuck for a long time on one of the middle levels and then found the rest of them pretty easy. Maybe I’m unusual, though — to judge by the JIG comments, other people had problems with other puzzles in the list.

Spirited Heart. By the author of Heileen and co-author of Summer Session, Spirited Heart bills itself as a “fantasy life sim”, sort of similar to Kudos but with demons and elves and magic. The aesthetic style will, I’m sure, immediately select for a limited audience — my eyebrows kind of went up at their own accord at the sight of the demoness character with her gown cut down to her navel and little decorative bat-wings, who nonetheless has an adorable schoolgirlish face. It’s that sort of thing. Beyond that, though, it’s reasonably smooth and well-constructed in its genre, but there aren’t enough options to make for very diverse and interesting gameplay, and it’s possible to run into a lot of random bad luck that keeps you from getting anywhere. Story elements drop into the game at random if you’re hanging out in the right places; and while this is better than having no story at all, it’s still too arbitrary to make for a compelling narrative.

I’ve also started Braid, now that it is (hooray!) available for the Mac. It is really clever, but even with the ability to rewind time, I suck at platformers. We’ll see how this goes.