apocryph.org Notes to my future self

26May/081

Getting latest XP x64 ATI Catalyst drivers for Mobility Radeon hardware

I just repaved Wyoh with Windows XP Professional x64 Edition, since I wanted a 64-bit OS and there’s no fucking way I’m running Vista on my primary dev laptop. I’ve been running XP x64 at work for a while, but my work box has shit on-board graphics so I never had to seek out the latest ATI drivers for a 64-bit XP install. Wyoh on the other hand has an embedded Radeon Mobility X1800 graphics board that really needs ATI’s latest drivers.

Apparently the OEMs that license the Mobility Radeon chips don’t like ATI providing the latest and greatest Catalyst bits online, since dumb users could download them before the OEMs have a chance to verify them, thus marring the user experience and (more importantly) costing said OEM a support call. Lame!

Fortunately, there’s a workaround. Download the normal non-mobility Radeon drivers from ATI, then run the Mobility Modder against them, which somehow munges the INF and MSI files so what used to be desktop Radeon drivers are now mobility Radeon drivers. You see, it’s one set of driver binaries for the entire Radeon line; ATI just munges the installer so it won’t install on Mobility Radeon chips to placate the goddamned OEMs.

I just went through these steps, and though it’s bullshit to have to jump through this sort of hoop to get drivers, I’m glad the guys over at DriverHeaven went to the trouble to build Mobility Modder in the first place, else I’d be totally fucked.

22May/082

PHP Sucks

My work on a tool to migrate Drupal content to WordPress’ eXtended RSS (‘WXR) led me into some dusty corners of the WordPress codebase, and I’ve been meaning to write a grumpy post about how much I hate PHP (in which WordPress is written), but Jeff Atwood at Coding Horror beat me to it with his own PHP sucks lament. Like me, Jeff wonders at the success of PHP given what a dreadfully sucky software engineering tool it is, and scratches his head at the many major Internet properties (Wikipedia, Digg, and WordPress among them) which are successful notwithstanding an implementation in a language a VB6 programmer might reasonable call “shit”.

Interestingly, though, Jeff and I arrived at two different conclusions on the matter. Jeff surmises:

Some of the largest sites on the internet — sites you probably interact with on a daily basis — are written in PHP. If PHP sucks so profoundly, why is it powering so much of the internet?

The only conclusion I can draw is that building a compelling application is far more important than choice of language. While PHP wouldn’t be my choice, and if pressed, I might argue that it should never be the choice for any rational human being sitting in front of a computer, I can’t argue with the results.

You’ve probably heard that sufficiently incompetent coders can write FORTRAN in any language. It’s true. But the converse is also true: sufficiently talented coders can write great applications in terrible languages, too. It’s a painful lesson, but an important one.

Hmm. I came to a different conclusion. Though I don’t know any of the programmers at the major PHP-powered properties, I have looked at some of their code, and I must say it does not look like the product of talented software engineers making due with a shit language; it looks like cruft bodgered together until it works, as though the last twenty years of hard-won software engineering advancements never happened.

To take but one example, I am working on some code that exports a Drupal site in WordPress’ WXR format, which is basically RSS with some additional WordPress-specific elements thrown in. Of course the format isn’t documented at all, so I set up a simple WordPress site, wrote some test posts with attachments and comments and whatnot, exported the site to WXR, and used the resulting WXR file as an example upon which to base my own implementation. I’ve mostly got it to work now, but I ran into some troubles along the way due entirely to the poor construction of at least the WXR import portion of the WordPress codebase.

To start with, WXR, like RSS before it, is an XML format. XML, having been around for over a decade now, is a very well-understood format. One of the fundamental principles of XML is that whitespace doesn’t matter. You can put text right after a start tag, or on the next line indented with a tab, or after several blank lines, and it will parse just the same (some exceptions but bear with me). I foolishly assumed that since RSS uses XML, and WXR extends RSS, that I needed only produce XML that was structurally identical to the WXR sample I had, without regard for whitespace. When I imported the first WXR file from my tool, WordPress didn’t complain but I noticed none of my content was coming through. WTF?

I then cracked open the import code at wp-admin/import/wordpress.php. Once there I stared in horror as I realized what they were doing. Rather than parsing the WXR file with, you know, an XML parser, the author of this particularly craptastic bit of code used a regular expression to find certain tag pairs, hard-coding the namespace prefix and assuming no whitespace between the start tag, content, and end tag. Super!

Not content merely with a gobsmackingly vile solution to a problem solved 10 years ago by the XML DOM, the code does neato things like injecting local variables into the local namespace non-obviously with calls to helper functions, and performing what amounts to zero error handling. For example, there was a bug in my stuff that migrated blog posts with a type attribute of blog, when it should have been post. Strangely, the import into WordPress ran without error, but none of the migrated blog posts showed up. Curious, I looked inside the WordPress MySQL database, and found all of my missing posts there; they just weren’t showing up. Rather than sanity-check the WXR input, the import logic just sucked it dutifully in, so future queries for type='post' would happily skip over my content without so much as a peep.

While I do have some sympathy for those unfortunate bastards who must work with a shit tool like PHP, I know for a fact that it’s not impossible to engineer quality code with it. If you doubt me, download the source tarball for Gallery 2 and find out how the MVC pattern, unit testing, and object orientation are indeed possible in PHP.

So what to make of this? I don’t think software engineering quality has anything to do with the success of a piece of software. Pristine, gleaming, perfectly coherent code doesn’t seem at all correlated with success, and clumsy bodgered-together cruft seems the rule and not the exception at the top of the software pile. Can you find well-engineered software that was successful? Sure. Can you point out spectacularly monstrous code that failed? Even easier. But explain to me how crufty software like Mediawiki and WordPress can be such runaway successes while Gallery and Drupal remain relatively obscure, if software engineering quality is so critical to success?

Now don’t get me wrong. I’m not one of those backward types who doesn’t see the point in unit testing, thinks object orientation is too complicated, and wouldn’t know a bad code smell from roadkill. I take the practice of software engineering seriously, and strive to build the best software I can within the constraints of our business. In this regard I’m more like the second stonecutter in Peter Drucker’s Three Stonecutters parable:

A favorite story at management meetings is that of the three stonecutters who were asked what they were doing. The first replied, ‘I am making a living.’ The second kept on hammering while he said, ‘I am doing the best job of stonecutting in the entire country.’ The third one looked up with a visionary gleam in his eyes and said, ‘I am building a cathedral.’

The third man is, of course, the true ‘manager.’ The first man knows what he wants to get out of the work and manages to do so. He is likely to give a “fair day’s work for a fair day’s pay.”

It is the second man who is a problem. Workmanship is essential; without it no business can flourish; in fact, an organization becomes demoralized if it does not demand of its members the most scrupulous workmanship they are capable of. But there is always a danger that the true workman, the true professional, will believe that he is accomplishing something when in effect he is just polishing stones or collecting footnotes. Workmanship must be encouraged in the business enterprise. But it must always be related to the needs of the whole.

… The tendency to make the craft or function an end in itself [in future] will therefore be even more marked than it is today. … The new technology will need both the drive for excellence in workmanship and the consistent direction of managers at all levels toward the common goal.”

I don’t accept that disciplined software engineering is equivalent to “stone polishing”, but I think the point is that past a certain qualitative point (which is different for each activity and each situation) improvements in workmanship don’t contribute meaningfully to value in the marketplace, and if undertaken at the expense of other activities which could have increased value can actually result in a net loss of productivity.

From the success of WordPress and Mediawiki and Youtube, I think it’s hard to make the case that more time and resources should’ve been spent architecting and writing better PHP code, but I don’t know how one can determine a priori where the productive labors stop and the stone polishing starts. If PHP has one thing going for it, it’s that it makes anything but the most cursory stone polishing so clumsy and uncomfortable that only the most pedantic of programmers would bother. Make of that what you will.

18May/080

New Windows Media Center System

For a few months now I’ve been running Vista and Windows Media Center on prospertine, hooked up to a nice widescreen LCD monitor mounted to the wall in my bedroom. Whenever I want to watch movies or TV shows and I’m not working in my office, I play them on ‘prospertine’ over my GigE network from my NAS box. I even have the Vista IR remote control, and a nice little wireless keyboard complete with a trackball. I can sit back on my bed and watch my media and even do basic web browsing.

However, prospertine is four years old, and has some serious thermal issues which cause the ICH6R chipset to ‘forget’ about one of the drives in its RAID 0 volume from time to time, which causes the system to crash. I then have to turn it off and let it cool before it will work again. So, I set about to upgrade my HTPC without spending alot of money.

As luck would have it, around the time I started contemplating this project, I ran across a post on Coding Horror covering just this subject. Jeff Atwood put together a nice AMD-based HTPC with DirectX 10 graphics, HDMI output, and low power consumption for around $500 bucks. I already had a hard drive, keyboard, IR remote, and various audio bits, so I just did an incremental build. I put together a shared wishlist on NewEgg with the details.

Anyway, I bought the mobo, AMD CPU, case, DVD drive, and 4GB of DDR2 800 RAM (Jeff spec’d out 2GB but it’s so cheap I couldn’t resist). Grand total: $380. I slapped it all together, powered it up, and that was it. The Vista Experience scores Jeff posts are for real; once I installed the chipset drivers I got a 3.5 Experience score, compared to 1.0 on prospertine. I’m not a huge fan of the Aero Glass eye candy bullshit, but it’s good to know I have the option.

I still haven’t figured out how to get hardware-accelerated x.264 decoding working, and even w/ a reasonably powerful dual-core machine Media Player Classic has trouble decoding 720p x.264 HD video without skipping or artifacts, though VLC managed ok. As Jeff has noted, codecs are the new DLL Hell, so I’m sure I have some penance to do before it’s working properly.

I also love that the Gigabyte mobo has all the connections I need on board. For the first time I’m using the optical S/PDIF port on my audio receiver, and placebo effect or not it sounds great! I use a LCD monitor with DVI input for my display, but the board also has HDMI out for proper TVs. The box is silent as far as I can tell, and certainly uses less power. I am reusing a 350GB 3.5″ Seagate Baracuda 7200.10 SATA drive, so that’s more noise and power than I would’ve liked, but it’s such an improvement over what I had before that I don’t really notice it.

If you’re thinking about going the HTPC route or upgrading one you have, you simply must check out this build. For the money it’s the most featureful, quiet, and efficient config I’ve seen.

16May/080

IPSC Results In

Last month I shot my first IPSC match at the NRA range. The scores have finally been posted.

There were a total of 30 shooters in all classes, out of which I placed 17th with 49.48% of the highest scoring shooter. In my class (Limited) I placed 4th. I didn’t get DQ’d, shoot myself, or score the lowest, so I’m pleased with my performance. It sucks I missed the signup for this month’s shoot; hopefully I’ll make it in June.

16May/080

Not Thinking Forfeiture Anymore

A while back I noted the appallingly tone-deaf BATFE procurement of “Always Think Forfeiture” leatherman tools. Today I received an unsolicited email from the offices of Congressman Bill Sali of Idaho, containing a press release announcing Congressman Sali’s success persuading BATFE management to stop distributing the coveted “Always Think Forfeiture” Leathermans. I don’t know anything about Congressman Sali or his politics, but anyone who reality-checks the BATFE is OK in my book.

13May/086

Worst C/C++ Gotcha Yet

Today I ran smack into what is easily the nastiest C/C++ gotcha of my entire software engineering career. From the early 90s reading Sam’s Teach Yourself C in 21 Days with a shitty freeware C compiler from a local BBS, through to today, I have been bit by just about every imaginable C and C++ gotcha, but this one takes the cake.

If you see what’s wrong with this code, you’ve been bitten by this before:

UINT32 x = 0x80000000;
UINT32 y = 2;
UINT64 z = x * y;
cwout << L"x*y=" << std::hex << z << std::endl;

If you think this code will output 0x100000000, you’ve not been bitten by this before.

You see, 2 times 0x80000000 is 0x100000000, which is 2^32 in hex. Unfortunately, since both x and y are 32-bit unsigned integers, the result is a 32-bit unsigned integer as well, implicitly cast to a 64-bit unsigned integer only after the computation is performed. And since 0x100000000 is too big to represent as a 32-bit quantity, the low 32 bits of the value (or, 0x00000000) are all that’s preserved. That’s right; this code prints 0 for the value of z.

What’s worse is I can compile this code using Microsoft Visual C++ 2008 with warnings cranked up to max, and the compiler has absolutely nothing to say. No friendly warnings about possible truncation, nothing. And this from a compiler that won’t let a constant in a conditional slip by with without making a snide remark.

In case you’re wondering, the correct way to implement this multiplication is to cast one or both of the 32-bit integers to 64-bit, which will trigger implicit type promotion and treat the whole expression as the product of two 64-bit integers.

It’s also worth noting that the equivalent C# code:

uint x = 0x8000000;
uint y = 2;
ulong z = x * y;
Console.Out.WriteLine("x*y={0:x}", z);

produces the correct result without explicit casting. Reason number 0xbadc0de why C# is better than C/C++. exact same result. DOH!

UPDATE: Daren pointed out I had one less zero in the C# example.  Contrary to my previous results, the C# version of the test app behaves the same way.  So I owe C++ an apology; in this regard it only sucks as much as C#, and not more.

9May/080

Dick Saslaw is a real..erm..dick!

Well, news of the open carry dinner has finally hit the AP wire. Considering it’s an AP story it’s astonishingly balanced, with no obvious bias either way. As usual, State Senator Dick “Banjo” Saslaw (D) was quoted in full Prick mode:

Saslaw said he’s not necessarily surprised that VCDL found restaurants in the region that would allow them to dine while armed. But he said that carrying guns is simply not normal behavior in this area.

“What normal person walks around with a gun on your hip? Something’s wrong in your life” if you feel compelled to carry a gun as part of your daily routine, he said.

So over 150,000 Virginians with concealed handgun permits are not “normal” and have something “wrong in [their] live[s]“? God, but that Saslaw is a real dick! Many of us at the dinner would rather not openly carry our guns for all the world to see, but politicians like Saslaw and Timmy Kaine force us to do so by refusing to pass a restaurant ban repeal.

To those of you in Saslaw’s district, can someone please explain what the hell you people see in this guy? Do you like that he repeatedly slanders one of the most law-abiding groups in the Commonwealth at a time when his party is trying desperately to shake the mantle of Gun Control? What were you thinking!?

9May/082

Need AR-15 Receiver Laser Etch Ideas

Now that those JBTs down at BATFE have destroyed Cav Arms (remember kids, Always Think Forfeiture), the two CavAid 2008 stripped lowers I ordered probably won’t ever come. Thus, I need to find another source of lowers, and I’ve settled on Anvil Arms.

Anvil makes mil-spec stripped lowers just like everyone else, but they also throw in laser engraving on the mag well for free. They have a gallery of some of the cooler things people have had engraved here. I need ideas for what to etch on a couple of lowers for my upcoming AR builds. My ideas so far:

  • the Simon Jester grinning devil icon from The Moon Is A Harsh Mistress
  • “ultima ratio regum” (Last Argument of Kings), said to be inscribed on the cannons of King Louie XIV
  • AR15.com bolt face logo
  • “Molon Labe” or “Come and Get Them”, King Leonidas’ response to Xerxes’ demand that the Spartans surrender their weapons, according to Plutarch’s history of the event
  • “Always Think Forfeiture”, the motto silkscreened onto a large order of Leatherman tools for BATFE’s asset forfeiture group responsible for the theft of property from those such as Cav Arms not accused of any crime
  • One of the American Revolution battle flags, http://americanrevwar.homestead.com/files/flags.htm. I especially like the Culpeper flag of the Culpeper Virginia Minutemen
  • A line drawing of a lamb carrying an AR-15, in the style of the Lamb Triumphant, as a subtle reference to the famous Ben Franklin quote (misattributed unfortunately)
  • The image and motto (Sic Semper Tyranis, or “Thus Always to Tyrants”) of the Virginia flag
  • DEXA (ΔΕΞΑΙ in the Greek alphabet), Greek for “Take That!”, carved into stone projectiles used by Greek slingers (Note: some Internet articles claim dexa means “catch!”, but according to Warry’s Warfare in the Classical World and the appropriate entry in William Smith’s A Dictionary of Greek and Roman Antiquities, “Take That” or “Take This” is the correct translation, which is supported by this Biblical concordance entry)

Delicious Bookmarks

Recent Posts

Meta

Current Location