Concatenating Strings in Django Templates

Huh? Django templates seriously can't handle string concatenation in any manner that could possibly be considered sane?

All I want to do is give some HTML elements IDs of the form doodad_1, doodad_2, etc. I want to do this so that these elements are easier to find with Javascript/jQuery. I also want to generate some of these elements (e.g. select elements) with sub-templates. I can't do both of these things at the same time without resorting to something ugly. Am I missing something here?

I managed to work around this, but it's cramping my style and I don't see any particularly good reason for it.

Deus Ex and Warhammer 40000: A Tale of Two Games

Deus Ex: Human Revolution and Warhammer 40000: Space Marine are both good games, but in completely different ways, which I will attempt to explain here.

Deus Ex: Human Revolution

Deus Ex: Human Revolution

Deus Ex: Human Revolution takes place in the near future, when cybernetic technology is really starting to take off. Adam Jensen is the head of security for Sarif Industries, a cybernetics corporation that has breathed new life into a Detroit ravaged by the collapse of the auto industry and the demise of oil as a viable fuel source. Sarif Industries HQ is attacked by several cybernetically-augmented mercenaries, their star research team (including Adam's fiancée) is killed, and Adam is very nearly killed. At the insistence of David Sarif, Adam is extensively rebuilt with cybernetic technology. The game is centered around the search for the people behind the attack.

Like its famous predecessor, Deus Ex, Human Revolution is quite a bit different from most other games. One of the most striking differences is in the control scheme. By default, "take cover behind the object in front of you" is bound to the right mouse button. This is because this action is very important in this game, and not just to avoid enemy fire. Human Revolution is not billed as a stealth game, but it really is. Trying to "run and gun" will end very badly for Mr. Jensen. Avoiding detection is essential. There are also quite a few options for interacting with the environment. For example, automated turrets and security bots can be hacked, allowing them to be shut down or turned against their former allies. Quite a bit of clutter can be picked up, repositioned, or thrown at enemies, especially after obtaining the strength upgrade. All this combines to make gameplay pretty fluid. There are usually several ways to handle any given situation, and it's fairly easy to make Adam carry out whatever plan you've concocted.

There are a wide variety of cybernetic upgrades Adam can obtain over the course of the game, some more useful than others. Some improve his stealth capabilities (like the absolutely indispensable cloaking device), while others improve his offensive capabilities (like the Typhoon system, which destroys everything near him). Others make hacking easier or provide resistance to environmental hazards. Unlike in the original Deus Ex, there are no weapon-specific upgrades; Adam can use any weapon effectively from the start. Some people think this makes the game a shooter with RPG elements instead of an RPG with shooter elements, but I think it makes sense. After all, Adam is a former SWAT officer. It would be a bit strange if he was no good at handling an assault rifle.

My primary gripes with Human Revolution are Adam's behavior in cutscenes and the ending. The decision to expand on Adam's character in pre-rendered cutscenes needed to be handled delicately, since in-game conversations gives the player ample opportunity to do so, and if the two come into conflict, the player feels like the man in the cutscenes is a different character. In my case, it seemed that Mr. Jensen lost about 50 IQ points in the cutscenes, falling for really stupid traps and generally being unaware of his surroundings. Since these pre-rendered cutscenes are pretty rare, this isn't too big an issue. In fact, they're more like comical intermissions than exposition. My gripe with the ending is this: at the end of the game, the player is presented with four buttons. These are the only things that have any bearing on the ending whatsoever. It's a bit anticlimactic, but after suffering through the massive WTF that was Mass Effect 3's ending, it doesn't really bother me that much. Plus, the four endings are fairly different from each other, unlike Mass Effect 3. Ugh. Just thinking about Mass Effect 3's horrible ending pisses me off. By contrast, the biggest problem with Human Revolution's endings in and of themselves is that the moralizing is a bit heavy-handed. Again, not a huge issue.

In conclusion, Deus Ex: Human Revolution is an excellent game, and I wholeheartedly recommend it.

And now for something completely different.

Warhammer 40000: Space Marine

Warhammer 40000: Space Marine

Warhammer 40000: Space Marine takes place in the grim, distant future of the Warhammer 40000 tabletop games. Humanity is spread across the stars and beset on all sides by a variety of violent aliens such as the brutish Orks, the monstrous Tyrannids, and the vile Necrons. As if that weren't bad enough, the forces of Chaos residing in the alternate reality known as the Warp constantly plot against us. While Mankind has very advanced technology, the knowledge of how to use it is limited, and engineering involves religious rituals. In fact, nearly everything involves religious rituals, as Mankind lives under a rather rigid and intolerant theocracy revolving around worship of the Emperor, a man of immense psychic power who founded the Imperium of Man. Ironically, the Emperor, nearly comatose in an elaborate life-support device, is horrified by this. Unfortunately for Mankind, the theocracy is definitely the least of the many evils they face. The mightiest forces Mankind has to fight back are the superhuman Space Marines.

Space Marine puts the player in the boots of Captain Titus of the Ultramarines, the mightiest of the Space Marine chapters. Captain Titus is sent to an industrial world to hold the line against a massive Ork invasion until a liberation fleet can arrive. As such, the battles involve wading through hordes of Orks. The control scheme places quite a bit of emphasis on melee combat, and for good reason: the melee weapons are the most effective way to deal with the swarms. The damage system reflects this, too. Titus has a regenerating shield and non-regenerating health. To regain health, he has to stun an enemy and then perform a brutal "execution" move on them. The ranged weapons are most useful in special situations, like when enemies are perched on high ledges.

My biggest gripe about the game is the difficulty curve. It starts out OK, but later in the game, it REALLY ramps up. I played on the easiest difficulty setting, and there were several sections that took me many attempts to get past. I'm pretty sure my attempt count went into the double digits on at least one of them.

My second-biggest gripe is the final boss fight. It's a sequence of quick-time events! It ends with a mind-numbingly long sequence of "press left mouse button to punch bad guy in face" followed by "press space bar to dodge counterattack." Yahtzee would throw a fit over this. Personally, I'm just going to call it very jarring and anticlimactic.

Overall, I found Space Marine entertaining, and I would recommend it, but only to people with a decent tolerance for violence and gore, since there's a lot of both in this game.

Prometheus: Huh? What?

I saw Prometheus on Friday. It had some very nice visuals. It had some very nice action. However, the more I think about the plot, the less sense it makes. My current best explanation for the events of the movie requires every major character to be unprofessional, mildly retarded, a sociopath, or some combination of the three. So confused...

For more details, see Howard Tayler's review (warning: comments section is full of spoilers). His opinion is a bit more charitable than mine, but it's in the same vein.

Recipe: Chicken Hash

Chicken Hash

Note that the following is my best attempt at formalizing the rather haphazard way I cooked this dish tonight. Following the recipe precisely may have disappointing results, so pay attention to what you're doing! I typically cook things "until they're done", not some predetermined amount of time. I will update this recipe after I cook this dish a few more times.

Ingredients

  • 4 chicken breasts
  • 1/2 red onion
  • 5 red potatoes
  • 1 green bell pepper
  • 1 red bell pepper
  • 1/4 cup pine nuts
  • olive oil
  • water

Serves 4.

Preparation

  1. Cut the peppers vertically into thin strips and cut each strip in half.
  2. Peel the potatoes and cut them into think strips.
  3. Slice the onion into thin slices and cut each slice in quarters.
  4. Place the chicken in a microwave-safe dish with a lid along with 1/8 cup of water.
  5. Cover chicken and microwave for 12 minutes at 70% power (assuming 1100 watt microwave).
  6. Heat 2-3 tablespoons of olive oil in a skillet at medium heat.
  7. When skillet is hot (oil should flow quickly when skillet is tilted), add potatoes. Depending on the size of the skillet, it may be necessary to cook potatoes in two batches.
  8. Transfer potatoes to a pot. Add onion, peppers, and 1/8 cup water. Cover and cook on medium heat for 10 minutes.
  9. Meanwhile, shred chicken (two forks work well for this) and transfer to skillet. Add 1/8 cup water, cover, and cook for 5 minutes or until fully cooked.
  10. Add chicken to pot and cook uncovered until water has boiled away.
  11. Cook pine nuts with 1-2 tablespoons of olive oil at medium heat until lightly browned.
  12. Add pine nuts to pot, stir and serve.

Variations

My original plan was to include lime juice and cilantro, but I forgot them this time. I think I will try adding the lime juice and cilantro when cooking the chicken in the skillet next time.

Hot peppers can be added to give it more of a kick. I would suggest cooking hot peppers in the skillet with the chicken.

For a more savory flavor, rosemary and thyme, and basil can be added. These should probably be cooked in the skillet with the chicken, but it may be worthwhile to add them to the potatoes, too.

WTF Reentrancy

System.Windows.Forms.dll!System.Windows.Forms.Control.OnPaint(System.Windows.Forms.PaintEventArgs e) + 0x73 bytes   
System.Windows.Forms.dll!System.Windows.Forms.Control.PaintWithErrorHandling(System.Windows.Forms.PaintEventArgs e = {ClipRectangle = {System.Drawing.Rectangle}}, short layer, bool disposeEventArgs = false) + 0x9a bytes 
System.Windows.Forms.dll!System.Windows.Forms.Control.WmPaint(ref System.Windows.Forms.Message m) + 0x1d4 bytes 
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x33e bytes 
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x10 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes  
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 15, System.IntPtr wparam, System.IntPtr lparam) + 0x5a bytes  
[Native to Managed Transition]

mscorlib.dll!System.Threading.ReaderWriterLock.AcquireReaderLock(int millisecondsTimeout) + 0x5 bytes

If you see a stack trace like that (perhaps with Monitor.Enter in place of ReaderWriterLock.AcquireReaderLock), .NET/Win32/COM just gave you the finger. You made the mistake of acquiring a lock on the GUI thread (or any STA thread) in a .NET program. Doing that can hang the GUI...or at least, that's what would happen in a world that makes sense. Unfortunately, you left that world behind when you started writing .NET/Win32 software.

Let's back up a bit here. The first thing to note is that the "GUI thread" in .NET (i.e. the thread that everything happens in unless you explicitly request otherwise) uses the STA threading model. For an explanation of threading models, see Larry Osterman's post on the subject. The short version is that COM objects (What, you thought you left COM behind when you switched to .NET? Silly fool!) basically need to run in a STA thread. However, STA threads are required to pump messages. Thus, acquiring a lock (which can block message pumping indefinitely) is a Bad Thing.

.NET tries to be helpful here by ensuring that messages get pumped, even while waiting for a lock. This means that your GUI thread can do work while waiting for a lock. Awesome, right? Well, it's not so awesome when that work involves calling the method in which you attempted to acquire a lock. If you're lucky, you will get a deadlock. If not, you will see something completely inexplicable at some point down the line. I call this "WTF Reentrancy" because those are the two words that rise to the surface of any sane mind that sees a reentrant method call from the same thread. This is, by the way, the very thing that makes POSIX signals suck. I have seen this most often with locks acquired in Win32 control paint methods (Yes, I know that's a very bad place to acquire a lock.) and methods called from there. It gets even more fun when things like OpenGL get involved. And by "fun" I mean "sanity-devouring".

Now, since we're already doing something questionable, it's OK for things to go wrong sometimes. I understand that. However, brief hangs or deadlock caused by lack of message pumping would be much, much easier to diagnose than WTF Reentrancy, especially since the latter can break things in subtle ways far from the source of the problem, while the former breaks things immediately in a fairly obvious way. Whoever thought this "feature" up clearly didn't think hard enough.

Somehow, I don't think you thought your cunning plan all the way through.

Oh, and here is an explanation of how COM fits in.

Programming Advice

A while back, I stumbled across this blog post by Eric Lippert of Microsoft. It has some nice tips for anybody doing any sort of serious programming. However, the first comment, by one Mike Dunn, caught my eye:

Always write code as if the maintenance programmer were an axe murderer who knows where you live.

If only every programmer had that attitude...

C# Brain Damage

//Works fine
short foo = 3;
short bar = foo;

//Failure: cannot implicitly convert int to short
short foo = 3;
short bar = -foo;

ARGH!

The Avengers

Go see The Avengers. ASAP. You will not regret it.

What, you want reasons? Fine. There's lots of great action, with more than a few good laughs. The humor tends toward slapstick and sarcastic wordplay, but this is a movie based on comic books, so that's to be expected. It dragged a little bit near the middle, but that didn't last long. If you don't want to take my word for it, take Howard Tayler's word for it. Or the general movie-going public's word.

Mass Effect 3

Mass Effect 3 starts with the Reaper invasion beginning in earnest. All Hell breaks loose, and it's up to Commander Shepard to pull a rabbit out of a hat and somehow win a war against a massive fleet of giant, super-advanced, genocidal machines.

Note: Mass Effect, Mass Effect 2, and Mass Effect 3 will hereafter be referred to as ME1, ME2, and ME3.

I bought ME3 out of a sense of obligation. I played the first two games, so I figured I might as well see how it all ends, even though I was pretty sure it was going to suck. I installed the game (via EA's Origin, which is a damn sight better in its early days than Steam was), started it up, played it...and much to my surprise, I enjoyed it. There is once again a wide variety of weapons and upgrades to find or buy. In fact, there's even more variety than in ME1. The storyline is more believable than ME2's. There are great opportunities to direct the course of the narrative. Fun characters from the previous games return. Big conflicts get resolved (for better or for worse, depending on Shepard's actions). This is what ME2 should have been.

In ME1, getting a new weapon meant dealing more damage or firing more accurately. In ME3, some weapons behave completely differently from the others. For example, the Scorpion is a pistol that shoots mini-grenades. Neat! There sure wasn't anything like that in ME1. Most weapons can now be upgraded with a scope, which actually produces a zoom-in effect when aiming. No weapon upgrade in ME1 changed a weapon's mechanics like that. Additionally, character class no longer restricts Shepard's choice of weapons. However, the classes that rely heavily on abilities need to carry as few weapons as possible, since weapons have weight, and more weight means longer ability cooldown times. It's a nice dynamic that adds depth to the game, letting the player make tradeoffs between firepower and finesse as needed.

My only complaint about the weapons was, again, the use of disposable heatsinks as limited ammunition by another name. Do we really have to ape Halo/Call of Duty/whatever? Really? I already beat this drum in my ME2 review, but I think it bears repeating. They introduced a new gameplay mechanic that conflicts with established lore (and occasionally makes no sense whatsoever) for no discernable reason other than aping the competition. Shameful, EA. The fact that reloading uses the same key as "throw grenade" in ME1 doesn't help, although ME1 is arguably The Real WTF there for using the R key for "throw grenade". WTF were you thinking, Bioware? Fortunately, though, I never found myself short of "ammo", even when using a shotgun, so it wasn't quite as obnoxious as in ME2.

Abilities still don't progress as smoothly as in ME1. You need to save up a bunch of points in order to advance to a new level of an ability. However, there are two more levels for each ability than in ME2, and the abilities seem to have a bit more "punch" than in both previous games, which is definitely a plus. Also, each level above 3 offers two different choices, usually offering a tradeoff between brute force and area of effect or between various extra effects (e.g. increased damage to armor vs. increased damage to shields for grenades).

Melee combat has also been reworked: Shepard now has a "heavy melee" attack, which is a biotically-enhanced punch for biotic characters and a stab with a large blade hastily fabricated by Shepard's omni-tool for other character classes. It takes a second or so to "warm up", but it definitely comes in handy from time to time. Shepard can also grab an enemy on the other side of a short wall and instantly kill them, but I never found an opportunity to do so outside of the scripted event that demonstrates the move.

Enemies are more varied this time, too. The Reaper's ground forces (hideously mutated members of various species) are a lot more varied, both in appearance and combat behavior, than the Collectors, and Cerberus has a nice variety of soldiers, including some particularly obnoxious pricks with impenetrable SWAT-style shields. They're definitely more interesting than ME2's collection of mercenaries differentiated by little more than the color of their armor.

The Paragon/Renegade system also got an overhaul. There are now two scores that affect the player's options: a Morality score and a Reputation score. Reputation basically increases the effects of Shepard's moral position and opens up more opportunities for dialog or missions. Morality, as before, opens up different dialog paths, allowing Shepard to persuade or intimidate people into acting differently. Some actions grant Paragon + Reputation, some grant Renegade + Reputation, and some grant pure Reputation. I think it works a bit better than the more simplistic systems in the previous games. In particular, I think it would have worked quite well in ME2, where killing the thresher maw could have granted pure Reputation instead of a large number of both Paragon and Renegade points, which never really made sense to me. Paragon and Renegade interrupts make a comeback, and I dare say they have a bit more punch this time around. I intended to play as a pure Paragon character (as usual), but there were some Renegade interrupts I just couldn't resist. That's a first. One in particular was the single most satisfying experience of the entire Mass Effect series.

The story is again fairly well-told, and the characters are colorful. The new squad member, James, initially comes off as a meathead lunk better suited to a much less intellectual series, but even he proves to be more complex than meets the eye. One of the main villians is basically a physical embodiment of anime, which annoyed me, but he's a villian, so I got to take it out on him eventually, and it helped distinguish him from the other assorted jerks out to foil Shepard. Depending on your actions, you may encounter characters from the previous games, and they have some impact on the story. It's usually nothing particularly earth-shaking, but it helps flesh out the tale. Only some of them are recruitable, though; most have moved on since ME2. I must say, though, that the decision to have Shepard basically under house arrest for several months between the two games so that members of his team from ME2 have the opportunity to move on seems a bit contrived. At least they explained it with an entire DLC for ME2.

One of the most memorable throwbacks to the previous games involves Conrad Verner (of course). It plays out as a series of increasingly improbable coincidences, and it got a good laugh out of me. It even earned me a war asset (i.e. got me closer to a...better...ending). Oh, Conrad, you priceless idiot...

There are also a few missions that are time-critical, where time is measured by progression through the main mission sequence. If you don't do them before certain other missions, bad things will happen. Fortunately, it's almost always obvious which missions are the time-critical. I only got burned by this once, and that was because I completely forgot about the "mission" in question (it's not an official mission; you just have to meet up with someone on the Citadel). The only consequence was the death of a character I didn't particularly care for anyway. Whatever.

My biggest gripe with the story (okay, second biggest gripe; I'll get to the biggest one later) is the part where it forces you to play though Shepard's PTSD dreams. While escaping Earth, Shepard fails to save a little boy. The kid gets killed by a Reaper. Every so often throughout the main mission sequence, you have to chase this kid in slow motion through a burnt forest. Eventually, the kid catches fire and Shepard wakes up. If it happened just once, that would have been OK. It doesn't. It happens several times. By the end of the game, I wanted to shoot the damn kid. Yes, Shepard failed to save an innocent little kid. I get it. Enough already!

Unfortunately still AWOL is the planetary exploration from ME1. Yes, the Mako's "shopping cart in a bouncy castle" handling was obnoxious, but it made the game world feel big and open. Unlike ME2, there is at least a decent excuse for it now: with the Reapers all over the galaxy, driving a light tank around on a planet's surface isn't particularly wise. The lack of planetary exploration is somewhat compensated for by the scale of the missions. They're still very linear, but that linear path is typically longer, which makes it feel more expansive. The background scenery is also quite well-done, especially in the war-torn urban environments. It gives a sense of the suffering the Reapers have caused, which we didn't see quite as much with the Collectors in ME2 or even the Geth and Sovereign in ME1. It adds emotional impact to the story.

In fact, the game world is even more constrained than in ME2: the only place you can get out and roam about freely is the Citadel. I was surprised to find that this didn't really bother me; again, with the Reapers all over the place, it makes sense that the Citadel would be pretty much the only safe haven left in the galaxy. It also helps that the Citadel is a lot bigger than in ME2.

Fortunately now AWOL is ME2's tedious planet scanning/mining. The Normandy can now emit a scanning pulse that detects everything interesting within its range all at once. The one caveat is that it also gets the attention of nearby Reapers. Get too much attention, and the Reapers will come to investigate, forcing you to flee the system. Scanning finds such goodies as credits, fuel, and war assets.

As icing on the cake, the most egregious bugs from ME2 are fixed. I'm pretty sure the prologue has Shepard drop off ledges several times just to prove that they fixed that damn "stuck floating in midair" bug that was the bane of my existence in ME2. Load times are quite reasonable, and I don't recall the game ever randomly deciding to make loads take a really long time for no reason. On the other hand, it takes a frankly unreasonable amount of time for the main menu to load when the game starts up, apparently because it needs to connect to some server somewhere. Also, the EA logo video at startup consistently gets interrupted by some Origin-related thing. Once the game gets going, though, it's smooth sailing.

Overall, I had a lot of fun with Mass Effect 3.

Then I got to the end. Holy shit. In the last five fucking minutes of gameplay, the story goes completely off the rails and tumbles headlong into the Gorge of Insanity. As soon as I saw that platform rise up into a beam of white light, I thought to myself, "This is going to be stupid, isn't it?" I could not possibly have imagined just how stupid it was about to get. All of a sudden, this game that had been pretty much straight sci-fi starts throwing all this semi-mystical bullshit at me. The tone changes completely. It's like shifting without a clutch. As shitty icing on this shitty cake, the ending also more or less invalidates Shepard's every accomplishment over the course of the entire series. I could rant for hours about this, but I'll keep it short. I honestly can't imagine anybody thinking this ending was good, and I find it quite difficult to believe that this was the best they could do in the time they had: it took me all of about 15 minutes to think up a better set of endings. Thus, I simply cannot ascribe this to incompetence. This has to be intentional trolling. Fuck you, EA.

After playing, I watched the alternative outcomes for the major events in the game on Youtube, and that left me feeling even more disappointed! Specifically, what had been my favorite Renegade interrupt in the entire series turned out to have very little impact on the outcome of the scene. I felt robbed. Again.

In short, Mass Effect 3 is like a pedophile who lures children into his van with promises of candy and then, surprisingly, actually makes good on his promises before the molestation begins. If you liked ME1 or ME2, go ahead and play ME3. If you didn't particularly care for ME2, slog through it anyway so you can have a better ME3 experience. Just watch out for the Bad Touch at the end.