Programmers and Hardware

The other day I followed a reddit link to a blog post about forking on
GitHub. I didn’t find the post that interesting but I did find one of
the comments on reddit provocative. Chrisgseaton takes exception to
the notion that “real” programmers have to think about hardware1.
As far as I can tell he wants to think of his programs as running on a
virtual construct that implements a logical model but—ideally—with no
actual hardware underneath.

That’s often a useful model and I don’t consider programmers that
adhere to it “lesser programmers” but I do think that great
programmers always have the underlying hardware in mind. Not
necessarily the actual piece of hardware the program will run
on—because, really, how can you know—but at least some sort of
idealized piece of hardware2.

That sounds almost like the “logical model” that chrisgseaton wants to
think about but it’s really a bit more. Every architecture that I’ve
ever worked on has load, store, arithmetic, and some sort of logical
if commands. Their mnemonics and exact operation will differ, of
course, but to a first approximation they’re the same.

That means that as I code I can imagine—again to a first
approximation—what code will be generated. If you can do that, you can
make intelligent decisions between functionally equivalent ways of
coding an idea. If you can’t do that, I don’t see how you can hope to
produce the best code.

I may feel that way because most of my professional development was
done in C, which is often considered a “high level assembly language.”
On the other hand, I can mentally imagine the final machine code even
when I’m coding in a language like Lisp. Languages like Python are
harder because they’re running on virtual machines but even there it’s
possible to predict what “code” will be generated.

So for me, yes you do have to think about the hardware as you code.
Of course, that’s just me. What do you think?

Footnotes:

1

You may have expand all the comments to see his comment.

2

As a practical matter, though, the majority of developers will
have some sort of x86 architecture as a target. Those developers can
have a fairly specific machine model in mind.

This entry was posted in General and tagged . Bookmark the permalink.