Coding Horror

programming and human factors

The Great Dub-Dub-Dub Debate

Pop quiz, hotshot. Which one is the superior Uniform Resource Locator?

www.fakeplasticrock.com

or

fakeplasticrock.com

This is one of those intractable problems. Global wars have been fought over so much less. In hacker circles, this is sometimes referred to as a bikeshed discussion.

That said, I do have a few bits of practical advice that I think apply unilaterally, whatever your position is:

  • Pick one or the other form and stick with it. Once the URL is out there in the wild, you need everyone to link to the same form for link juice amplification purposes, if nothing else. If half your incoming links are split between the www and non-www forms of your URL, that will hurt you a heck of lot more than picking the "wrong" prefix. It's also a bad idea to decide a few years down the road that you want to switch teams – so choose wisely.

  • Make sure your site works with or without the leading www prefix. Regardless of your position on this critically important issue, your site should work either way. Serving up visitors who assumed you had a leading www prefix a 404 page is just plain bad internet citizenship, and borderline rude. Sure, encourage people to use the correct form of your URL but don't penalize them when they fail to respect your wishes. It's best if you implement URL rewriting rules that "fix" the error automatically and with no fuss for your visitors.

  • The www prefix is implicit and assumed outside the address bar. Even if you use it – and many of the biggest sites on the internet still do – nobody says the dub-dub-dub any more, and certainly you're not printing "www" on your logos and business cards and so forth.

  • Consider whether you plan to use other subdomains. If you plan to have, say, blog.* and mail.* and beta.* subdomain prefixes active on your domain, you might actually want the www as a disambiguator.

  • WARNING: If you pick the domain example.com, be aware that all cookies you store on that domain will be sent to all subdomains … forever. This is a major downside I didn't discover until years later, and it's big enough to make me regret choosing stackoverflow.com versus www.stackoverflow.com.

Beyond that, it's largely a matter of taste, though you could make a case that user-centered URL design should rule the day. If we're dropping the www prefix, why stop there? Why not drop the http:// protocol specifier before it, and the inevitable .com at the end, too?

For me, though, the great dub-dub-dub debate is mostly a source of amusement. Readable URLs are important, but you should be far more concerned about the content behind that URL than the URL itself. It's the kind of meaningless distraction that is parodied beautifully in the animated series Home Movies.

Melissa: You know, Brendan, you don't have to say dubya-dubya-dubya any more.

Brendan: What? Why?

Melissa: You can just say the website name without the dubya-dubya-dubya.

Brendan: No, no, no. That's how you type it in, Melissa. Dubya-dubya-dubya dot..

Melissa: I know that's how you type it, but you don't have to say it. If you said to me, moviewinnerorweiner dot com, I would know what you meant, without the double-u.. double-u.. double-u.

Brendan: So no w's, ever?

Melissa: OK, Brendan, for the sake of this conversation, you don't have to say dubyadubyadubya. Because I know what it is. And so does the rest of the world.

Brendan: dubya-dubya-dubya dot movieweinerorwinner dot com likes my stuff a lot, so they asked me to write some stuff.

Jason: you're writing a review for dubya-dubya-dubya dot movieweinerorwinner dot com?

Melissa: (shouting) You guys, you don't have to say dubya-dubya-dubya!

Brendan: But yet..

Melissa: I don't want to have this conerversation again!

Jason: What are you talking about, Melissa?

Brendan: You have to say it Melissa. You gotta say it.

Melissa: (exasperated sigh) You don't!

Brendan: You gotta say it.

Melissa: You don't, because everyone knows what it means!

Jason: How do you know it's a website?

Melissa: Because you say dot com.

Jason: Yeah, but how do you know it's dubya-dubya-dubya?

Brendan: Yeah, that's a good point!

Melissa: Because it's just one of those things that when something's around for a long enough time in society, you can just abbreviate it.

Brendan: Like what else?

Jason: Like what, like names? Names of people?

Brendan: That's what I was saying.

Melissa: (exasperated) All right, you know what? Say dubya-dubya-dubya, I don't care.

Jason: No, you know what I'm saying.

Melissa: No, forget it. You're right. In fact, don't say dubya-dubya-dubya, say "world wide web" every time you say a website.

(pause)

Jason: No, that's a total waste.

Brendan: That's a waste of time.

My point exactly.

Discussion

Programmers Don't Read Books -- But You Should

One of the central themes of stackoverflow.com is that software developers no longer learn programming from books, as Joel mentioned:

Programmers seem to have stopped reading books. The market for books on programming topics is miniscule compared to the number of working programmers.

Joel expressed similar sentiments in 2004's The Shlemiel Way of Software:

But the majority of people still don't read. Or write. The majority of developers don't read books about software development, they don't read Web sites about software development, they don't even read Slashdot.

If programmers don't learn from books today, how do they learn to program? They do it the old-fashioned way: by rolling up their sleeves and writing code – while harnessing the collective wisdom of the internet in a second window. The internet has rendered programming books obsolete. It's faster, more efficient, and just plain smarter to get your programming information online. I believe Doug McCune's experience, which he aptly describes as Why I Don't Read Books, is fairly typical.

I lay part of the blame squarely at the feet of the technical book publishing industry:

  • Most programming books suck. The barrier to being a book author, as near as I can tell, is virtually nonexistent. The signal to noise of book publishing is arguably not a heck of a lot better than what you'll find on the wilds of the internet. Of the hundreds of programming books released every year, perhaps two are three are truly worth the time investment.
  • Programming books sold by weight, not by volume. There seems to be an inverse relationship between the size of a programming book and its quality. The bigger the book, somehow, the less useful information it will contain. What is the point of these giant wanna-be reference tomes? How do you find anything in it, much less lift the damn things?
  • Quick-fix programming books oriented towards novices. I have nothing against novices entering the programming field. But I continue to believe the "Learn [Insert Language Here] in 24 hours!" variety of books are doing our profession a disservice. The monomaniacal focus on right now and the fastest, easiest possible way to do things leads beginners down the wrong path – or as I like to call it, "PHP". I kid! I kid!
  • Programming book pornography. The idea that having a pile of thick, important-looking programming books sitting on your shelf, largely unread, will somehow make you a better programmer. As David Poole once related to me in email, "I'd never get to do that in real life" seems to be the theme of the programming book porn pile. This is why I considered, and rejected, buying Knuth's Art of Computer Programming. Try to purchase practical books you'll actually read, and more importantly, put into action.

As an author, I'm guilty, too. I co-wrote a programming book, and I still don't think you should buy it. I don't mean that in an ironic-trucker-hat, reverse-psychology way. I mean it quite literally. It's not a bad book by any means. I have the utmost respect for my esteemed co-authors. But the same information would be far more accessible on the web. Trapping it inside a dead tree book is ultimately a waste of effort.

The internet has certainly accelerated the demise of programming books, but there is some evidence that, even pre-internet, programmers didn't read all that many programming books. I was quite surprised to encounter the following passage in Code Complete:

Pat yourself on the back for reading this book. You're already learning more than most people in the software industry because one book is more than most programmers read each year (DeMarco and Lister 1999). A little reading goes a long way toward professional advancement. If you read even one good programming book every two months, roughly 35 pages a week, you'll soon have a firm grasp on the industry and distinguish yourself from nearly everyone around you.

I believe the same text is present in the original 1993 edition of Code Complete, but I no longer have a copy to verify that. A little searching uncovered the passage Steve McConnell is referencing in DeMarco and Lister's Peopleware:

The statistics about reading are particularly discouraging: The average software developer, for example, doesn't own a single book on the subject of his or her work, and hasn't ever read one. That fact is horrifying for anyone concerned about the quality of work in the field; for folks like us who write books, it is positively tragic.

It pains me greatly to read the reddit comments and learn that people are interpreting the stackoverflow.com mission statement as a repudiation of programming books. As ambivalent as I am about the current programming book market, I love programming books! This very blog was founded on the concept of my recommended developer reading list. Many of my blog posts are my feeble attempts to explain key concepts outlined long ago in classic programming books.

How to reconcile this seemingly contradictory statement, the love and hate dynamic? You see, there are programming books, and there are programming books.
The best programming books are timeless. They transcend choice of language, IDE, or platform. They do not explain how, but why. If you feel compelled to clean house on your bookshelf every five years, trust me on this, you're buying the wrong programming books.

I wouldn't trade my programming bookshelf for anything. I refer to it all the time. In fact, I referred to it twice while composing this very post.

my-programming-bookshelf-small.jpg

I won't belabor my recommended reading list, as I've kept it proudly the same for years.

(Update: Tim Spalding kindly set up a LibraryThing account on my behalf – and members have already documented and entered every book pictured on these shelves. Impressive, and quite cool!)

But I do have this call to arms: my top five programming books every working programmer should own – and read. These seminal books are richly practical reads, year after year, no matter what kind of programming I'm doing. They reward repeated readings, offering deeper and more penetrating insights into software engineering every time I return to them, armed with a few more years of experience under my belt. If you haven't read these books, what are you waiting for?

Code Complete 2 Don't Make Me Think
Peopleware Pragmatic Programmer
Facts and Fallacies

It is my greatest intention to make stackoverflow.com highly complementary to these sorts of timeless, classic programming books. It is in no way, shape, or form meant as a replacement for them.

On the other hand, if you're the unfortunate author of Perl for Dummies, then watch your back, because we're definitely gunning for you.

Discussion

Building Your Own Home Theater PC

I've kept a PC in my living room for the past three years as my primary home theater interface, and I heartily recommend it. It's shocking how cheap and easy it is to build a home theater PC these days.

I've been pondering an upgrade to my creaky old home theater PC, and rave reviews of the new integrated AMD platform at Tech Report, Silent PC Review, and Tom's Hardware finally pushed me over the edge.

CPU AMD Athlon X2 4850e 2.5 GHz (45w) $60
Mobo Gigabyte GA-MA78GPM-DS2H Micro ATX $100
RAM Kingston 2GB DDR2 800 $39
PSU Seasonic ECO 300W $55
DVD Lite-On 20X DVD±R SATA $29

I didn't buy the PSU because I already have that particular model, but I bought everything else on this list for a grand total of less than 250 bucks. (You can save a bit on the power supply, but I don't recommend it, particularly if you plan to leave your HTPC running 24/7. Efficient power supplies not only save you money on electricity in the long run, but also tend to be of generally higher quality, and quieter to boot.)

The new AMD 780G platform is striking in its simplicity. Just pop in the RAM and the low-power Athlon X2 CPU and you have an (almost) complete ultra low-power home theater PC. Just check out the awesome array of rear panel connections:

We have the expected stuff (4x USB, gigabit ethernet), but the exciting part is DVI, VGA, and HDMI video out! Not to mention optical digital out for beautiful, pristine digital audio direct to your receiver. Those are the key connections for a home theater PC. We even have an eSATA port and firewire thrown in, which is always nice.

I simply dropped the new motherboard and DVD in my existing transparent acrylic Micro-ATX PC case, replacing the old stuff. (If you're thinking of going this route, I can recommend the Antec Minuet Micro-ATX case for $100, which conveniently comes with an efficient power supply, too -- but be aware of the half-height expansion slots.)

new-htpc-mobo-installed.jpg

I kept my existing hard drives (a small 2.5" boot drive for low noise / power consumption, and giant capacity 3.5" drives for long-term storage and recording), and my Hauppauge PVR-150 dual analog PCI tuner card, which I love to death.

For the longest time, integrated graphics was synonymous with craptacular graphics. That's not the case for this new AMD 780g chipset. The integrated graphics are fully DirectX 10 compliant, comparable to the latest entry-level discrete video cards. Gaming isn't our goal, though this would be perfectly adequate for many games. More importantly for a HTPC build, the integrated graphics support the full suite of H.264 and WMV video playback acceleration.

new-htpc-windows-experience-updated.png

I know a WEI graphics score of 3.5 doesn't sound like much, but brother, let me tell you -- this is light years ahead of anything else on the market at this power consumption point.

Update: I had a hardware failure of my own causing (don't ask) and I needed to replace this motherboard. Fortunately, there is a new version of this motherboard with 128 MB of dedicated "sideport" DDR3 graphics memory on board. With the addition of dedicated video memory the WEI graphics score went from 3.5 / 3.6 to 4.0 / 4.0!

My old Pentium-M single core struggled to play back 1080p videos. The Athlon X2 4050e CPU I chose is one of AMD's low power dual core models, far from top of the line. The testers at SilentPCReview found any modern dual core chip is more than enough for the most strenuous of video playback tasks:

Gradually underclocking the CPU, we found that the Blu Ray disc began to stutter at about 1.1Ghz, while audio glitches were detected in the WVC1 clip at 1.4Ghz. 1.5Ghz was the lowest clock speed that would smoothly play back all our clips. This was a fantastic result as the lowest clocked X2 on the market is 2.0 Ghz.

AMD is a better choice for a home theater PC because their idle voltage and multiplier throttling -- the marketing term is "Cool n' Quiet" -- is outstanding. (I'm also glad to have the opportunity to support AMD because I'm desperately afraid of a world where Intel is the only CPU vendor. And you should be too.) This variant of the Athlon 64 X2 chip is so new that CPU-Z doesn't quite recognize it by name. But as you can see, at idle, it clocks down to a miserly 1 GHz and reduces its power consumption to barely over one volt.

new-htpc-cpuz.png

My old highly optimized HTPC build consumed just under 80 watts at idle, up from around 65 before I began upgrading it to make it more Vista friendly. Guess how much this new HTPC platform build, which is more than twice as powerful, consumes at idle? Let's whip out our handy dandy kill-a-watt and find out:

new-htpc-watt-reading.jpg

FORTY. SIX. WATTS.

That is flippin' amazing. We're talking about a powerful modern PC here, with quite a bit of additional hardware you wouldn't find in most PCs, including a dual TV tuner PCI card and three hard drives. Granted two of those drives are in sleep mode most of the time, but still. 46 watts -- twice the power at almost half the energy consumption! Incredible! Silence and efficiency were nowhere near this easy three or four years ago.

Needless to say, I'm pretty excited about this particular $250 upgrade, and I can sell my old parts to underwrite it.

On the software front, as I mentioned at the top, I've been a fan of Windows Media Center since the first version; it's one of the best products to come out of Redmond in years, and the version of Media Center bundled with Vista (well, Ultimate and Home Premium, anyway) is the best yet. With a hardware setup this compelling, I'm sure you'll have no problem at all mating it with your favorite HTPC software.

If you do end up running Windows and connecting your HTPC to a DVI or HDMI capable television, beware. Getting an exact, pixel-for-pixel connection between your HTPC and your TV isn't easy. For example, I had trouble getting the ATI Catalyst graphics driver to accept 852x480, the standard resolution of our old plasma EDTV. Sure 800x600 worked fine, but the aspect ratio was totally off. That's where PowerStrip comes in.

PowerStrip advanced timing options

PowerStrip will let you achieve that ideal pixel-for-pixel perfect connection between your graphics card and your television. I selected the built in EDTV preset as a custom resolution, and all was well. PowerStrip is the go-to utility for tweaking home theater display output.

We use our home theater PC every day. It's silent, draws very little power, and it's small enough to tuck away cleanly in our living room decor. It plays anything through a slick 10-foot UI, and offers unrestricted access to the web at any time. Putting a great one together today is almost ridiculously easy. If you haven't considered building your own home theater PC -- why not?

UPDATE: since people asked, here's a complete from-scratch build list for a home theater PC.

CPU AMD Athlon X2 4850e 2.5 GHz (45w) $70
Mobo Gigabyte GA-MA78GPM-DS2H Micro ATX $100
RAM Kingston 2GB DDR2 800 $40
DVD Lite-On 20X DVD±R SATA $30
Case/PSU Antec Minuet w/80plus certified PSU $100
HDD Western Digital quiet 500 GB $90
Tuner Hauppauge low profile analog cable/TV $76
Remote Standard Media Center IR $17
$523

If you plan to use Vista Media Center, add a Vista Home Premium SP1 license for $110. I also saw that Blu-Ray internal drives (read only) are down to $130 as of the time I'm writing this.

Discussion

The Problem with Software Registration

As a person who has spent a significant part of his professional life getting paid to write software, I believe it's important for me to regularly pay for software, too. Our programmer salaries don't come from magical money trees. They come from customers laying down cold, hard cash for the software we've built. That's why every month I try to put into action what I described in Support Your Favorite Small Software Vendor Day:

Check your hard drive, and I'm sure you, too, will find some bit of software written by a small software development shop, maybe even a single developer. Something you find incredibly useful. Something you rely on every day. Something you recommend without reservation to friends and peers. Something that makes using the computer that much more enjoyable. Or at least less painful.

Stop reading this post right now and buy that software. If it's not commercial software, don't let that stop you. Share the love by sending money to the person/shop/organization that created it.

As I encounter apps that I find helpful and use regularly, I go out of my way to support them by either donating, or registering and buying a license. It's just plain good karma. There's nothing more effective than voting with your wallet. As I see it, if you don't vote, you aren't entitled to have an opinion.

But here's what I find deeply troubling: often, registering software leaves me with a worse experience than not registering. Allow me to illustrate with an example.

I've been transferring our podcast files back and forth to blog.stackoverflow.com via FTP, so I reinstalled SmartFTP. Now, I've used SmartFTP quite a bit over the years, but never bothered to pay for it. They've done a great job of regularly improving and enhancing it every time I use it again. That's exactly the kind of useful, living software project I want to support.

Until I register, I'm presented with this little nag screen every time I start SmartFTP. It's mildly annoying, but tolerable -- and it prominently features a convenient "buy me" button. Hey! That's what I want to do!

SmartFTP license reminder

I click that button and get whisked away to a website where I'm now confronted with a choice: home or professional?

SmartFTP product editions

Gee, I don't know. I'm conflicted. Now I have to think about what features I want, and how much I'm willing to pay for said features.

This is already starting to be kind of a drag.

I now feel like I'm being gamed. There's a name for this game, and unfortunately it's not something fun and cool like Grand Theft Auto IV -- this particular game is called capturing consumer surplus.

Let's do this. Instead of charging $220, let's ask each of our customers if they are rich or if they are poor. If they say they're rich, we'll charge them $349. If they say they're poor, we'll charge them $220.

Now how much do we make?

Notice the quantities: we're still selling the same 233 copies, but the richest 42 customers, who were all willing to spend $349 or more, are being asked to spend $349. And our profits just went up! from $43K to about $48K! NICE!

Any resemblance between this and Windows Vista Kenny Loggins edition is, I'm sure, purely coincidence. I finally decide I'm a "home" FTP user, whatever the heck that means. I suspect it's a sneaky marketing weasel synonym for "cheap bastard".

As a reward, now I get to play another game called fill out the giant order form. You've played this one before. Note that in this particular game, you can score bonus points for trying to route this form through your complex corporate payment system.

SmartFTP order form

After all that, I manage to pay. It's a sort of unavoidable flat tax on effort for any form of online commerce. Eventually, I receive this in my email inbox:

SmartFTP license email

Now I have three choices. None of which make a whole lot of sense on my initial reading. It looks like there's some kind of key file I'm going to need? I'll try the middle link to download it. I don't really want another executable of unknown provenance on my system. After downloading the license file, I use the help menu to install it:

SmartFTP license installation

Et Voil! In only sixteen fun and easy steps, I have registered this software and voted with my wallet!

But that registration is only the beginning of my problems:

  • I now need to keep track of a license file.
  • The license is probably tied to a particular computer, so if I reinstall the OS, or upgrade the hardware, that license might break.
  • If I lose my license, I need to remember my login credentials on the vendor's website to retrieve them.
  • My license is only valid for one year. When that year is up, I need to go through these motions and re-license the software yet again.

Now-- and here's the kicker-- multiply all this licensing pain by the number of applications and people in your organization.

Even for a solo user like me, it's bad. I have apps I've registered and paid for that I somehow never got license keys for, such as WinRAR. I have apps that I simply don't use because I'm too lazy to re-register them on my new install, such as EditPad Pro. I've long since lost track of what versions of which apps I have valid registrations for. You can imagine the kind of fun that awaits me at the end of any new system build, a virtual jamboree of re-registrations.

Now let's compare that with the process of "registering" the open source FTP tool FileZilla:

  1. Download FileZilla
  2. Donate $36.95 to the project

Oh, and step three? There is no step three! I never have to think about registration, licensing, or any of that other crap again. Ever!

There's no doubt that SmartFTP is the superior FTP client. I'm more than happy to register and reward them for their years of development work. But in the future, I think I'll be voting with my wallet for the registration process that makes my life easier, not harder.

Discussion

Behold WordPress, Destroyer of CPUs

Lately I've been delving into the WordPress ecosystem, as it seems to be the most popular blogging platform around at the moment. I've set up two blogs with it so far. In the process, I've gotten quite comfortable with the setup, interface, and overall operation of WordPress.

  1. blog.stackoverflow.com
  2. www.fakeplasticrock.com

I've been thoroughly impressed with the community around WordPress, and the software itself is remarkably polished. That's not to say that I haven't run into a few egregious bugs in the 2.5 release, but on the whole, the experience has been good bordering on pleasant.

Or at least it was, until I noticed how much CPU time the PHP FastCGI process was using for modest little old blog.stackoverflow.com.

WordPress CPU Usage, Before

For context, this is running on a Windows Web Server 2008 virtual machine with a single core of a 2.13 GHz Xeon 3210 entirely dedicated to it.

This is an incredibly scary result; blog.stackoverflow.com is getting, at best, a moderate trickle of incoming traffic. It's barely linked anywhere! With that kind of CPU load level, this site would fall over instantaneously if it got remotely popular, or God forbid, anywhere near the front page of a social bookmarking website.

For a bare-bones blog which is doing approximately nothing, this is a completely unacceptable result. It's appalling.

As evidence of what a systemic problem this is, there's an entire cottage industry built around shoehorning better caching behavior into WordPress. Take your pick: WP-Cache, WP-Super-Cache, or Bad Behavior. The caching add-ins don't work very well under IIS because they assume they're running on a *NIX platform, but they can be coerced into working.

Does it work? Does it ever. Here's what CPU usage looks like with basic WP-Cache type functionality enabled:

WordPress CPU usage with WP-Cache

I'm not alone; just do a web search on WordPress CPU usage or WordPress Digg Effect and you'll find page after page of horror stories, most (all?) of which are solved by the swift and judicious application of the WP-Cache plugins.

It's not like this a new issue. Personally, I think it's absolutely irresponsible that WP-Cache like functionality isn't already built into WordPress. I would not even consider deploying WordPress anywhere without it. And yet, according to a recent podcast, Matt Mullenweg dismisses it out of hand and hand-wavingly alludes to vague TechCrunch server reconfigurations.

A default WordPress install will query the database twenty times every time you refresh the page, even if not one single element on that page has changed. Doesn't that strike you as a bad idea? Maybe even, dare I say it, sloppy programming?

I understand that users may have umpteen thousand WordPress plugins installed, all of which demand to change on every page load. Yes, the easiest path, the path of least resistance, is to mindlessly query the database every time you're building a page. But I cannot accept that a default, bare-bones WordPress install hasn't the first clue how to cache and avoid expensive, redundant trips to the database.

It's frustrating, because caching is a completely solved problem in other programming communities. For example, the .NET framework has had page output caching and page fragment output caching baked into ASP.NET for years.

I sure am glad I started this blog in Movable Type way back in 2004. Their classic static rendering blog engine approach may be derided today, but I shudder to think of the number of times the Coding Horror webserver would have been completely incapacitated over the years by the naive -- no, that's too tame -- brainlessly stupid dynamic rendering approach WordPress uses.

What I just don't understand is why, after all these years, and all these documented problems, WordPress hasn't folded WP-Cache into the core. If you're ever planning to have traffic of any size on a WordPress blog, consider yourselves warned.

Update: Matt Mullenweg kindly responded to this post and offered his recommended MySQL configuration optimizations. I definitely agree that the Query Cache is extremely important to performance, and for some reason it defaulted to off (zero size) on my installation. You may also want to look into innotop and mysqlreport to ensure that all your MySQL caches are functioning at appropriate levels. Also, thanks to a few commenters for letting me know that one of this year's Google Summer of Code projects is integrating caching into the core WordPress code. It is badly needed.

Discussion