Skip to Content.
Sympa Menu

freetds - Coding style digression

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Lowden, James K" <LowdenJK AT bernstein.com>
  • To: "'TDS Development Group'" <freetds AT franklin.metalab.unc.edu>
  • Subject: Coding style digression
  • Date: Thu, 13 Jun 2002 15:25:31 -0400


> From: Brian Bruns [mailto:camber AT ais.org]
> Sent: June 13, 2002 12:31 PM
>
> > for( i=0; i < x; i++ ) {
>
> C++ style...ugh. I particularly hate, 'int* i;' vs. the
> proper 'int *i;'

'int* i;' is a bug in waiting. It would be fine, if

int* i, j;

defined two pointers-to-int, but the compiler knows better, so to speak.

[total digression follows. a)bort, r)etry, i)gnore?]

My first paying C job was with DOS 3.0 on an honest-to-goodness IBM AT with
an 80286 processor and 2MB RAM (most of which was a virtual disk). I used a
four-pass compiler from C Innovations (IIRC), ported directly from Unix, I
later decided, the best feature of which was, well, actually, it had no good
features.

There were no functional prototypes in 1984, there was no protected memory,
and we had no debugger, symbolic or otherwise, save DOS DEBUG, which we
never used except to dump files. I wrote a special form of printf that
bypassed the file system and wrote directly to the parallel port hardware,
the better to see our debug output. I thought that was the sort of thing
you had to do to write working programs.

You can't write Hello World in C without a pointer, and the bane of our
existence was wonky pointers, far more than today. It was nothing to mix up
pointers and non-pointers. Forgetting a '*' or '&'? Ha! That was for
babies! Lots of functions take (char *s, int len), but we didn't have any
convention, so we wrote plenty that took (int len, char *s), always an
adventure. The compiler never minded, but of course the CPU knew the
difference, in a way.

"You had a 1? We had to type the letter 'l'" -- Dilbert

(Hmm. My Courier font is so determined to emulate Smith-Corona that 1 and l
are pixel-for-pixel identical. I hope that doesn't ruin the joke for you.)

Once bitten twice shy. Consequent to that "learning experience", I prepend
all pointer names (except proper strings) with "p", hence 'int *pi;'. I
don't say it's right; I'd forgive you if you thought that might mean '3'. :)
But I like my pointers to keep their hands in the air where I can see 'em.

Later, much later, I came across a language I could never stop mocking,
called Visual Basic (it's really Manual Basic with a GUI form designer) that
used some tortured syntax to pass strings to libraries using the C call
stack convention. Far from having some meaningful way to express the
'char*' nature of the thing it was passing, you had to call it a "local
string" or a "static string" or somesuch, and the tool thereby knew you
meant "char*", and you were off and crawling. I muttered to the guy sitting
next to me that I like my pointers explicit thank you very much; he nodded
and we're still friends.

So, no, the purpose of a name is to name the purpose, and 'int* i' is a good
bad example. Name well your pointers, and go home before midnight.

[end digression. Your bandwidth is hereby restored.]

Thank you for the soapbox. I feel better now.

Regards,

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page