BEAUTIFUL CODE EXISTS,
IF YOU KNOW WHERE TO LOOK
A koder with attitude, KV answers your questions. Miss Manners he ain’t.
Dear KV,
I’ve been reading your
rants in Queue for a while
now and I can’t help asking, is there any code you
do like? You always seem so
negative; I really wonder
if you actually believe the
world of programming is
such an ugly place or if
there is, somewhere, some
happy place that you go to
but never tell your readers
about.
/*
* struct pmc_mdep
*
* Machine dependent bits needed per CPU type.
*/
FIGURE
1
struct pmc_mdep {
uint32_t pmd_cputype; /* from enum pmc_cputype */
uint32_t pmd_npmc; /* max PMCs per CPU */
uint32_t pmd_nclass; /* PMC classes supported */
struct pmc_classinfo pmd_classes[PMC_CLASS_MAX];
int pmd_nclasspmcs[PMC_CLASS_MAX];
A Happy Programmer
/*
* Methods
*/
Dear Mr. or Ms. Happy
While I will try not to take
exception to your calling
my writings “rants,” I have
to say that I am surprised
by your question. KV is a
happy, cheerful, outgoing
kind of guy who not only
has a “happy place,” but
also carries it with him
wherever he goes, sharing joy and laughter with everyone
around him and giving sweets to small children (cough).
Now that I’ve bleached my brain, I can answer a bit
more honestly. Yes, in fact, there are good systems and I
have seen good code, sometimes even great code, in my
time. I would like to describe one such chunk of good
int (*pmd_init)(int _cpu); /* machine dependent initialization */
int (*pmd_cleanup)(int _cpu); /* machine dependent cleanup */
Questions for Kode Vicious? E-mail him at kv@acmqueue.com—
if you dare! And if your letter appears in print, he may even
send you a Queue coffee mug, if he’s in the mood. And oh yeah,
we edit letters for content, style, and for your own good!
code right now. Unfortunately, it will require a bit of
background to explain what the code is, but please stick
with me. Perhaps you can relax by going to your “happy
place” first.
One of my recent projects has been to extend support
for something called hwpmc (hardware performance
monitoring counters) on FreeBSD, the operating system I
work on. As the name indicates, hwpmc is implemented
in hardware, and in this case hardware means on the
CPU. I don’t know if you’ve ever read CPU or chip documentation, but there is little in our industry that is more
difficult to write or less pleasant to read. It’s bad enough
that the subject is as dry as the surface of the moon,
but it’s much worse because the people who write such
documentation either don’t understand the technology