I've been slowly making my way back into the world of C and C++ lately; consequently I'm filled with angst at what I perceive to be failings in the design of the languages. Just a rant.
I can't really get over why the language was designed to overload
the meaning of *
as a type and an operator. int * intPtr
is a
type specifying intPtr
points to and integer, cool, sure,
whatever. Ah, but then in an expression: foo = *intPtr
is
dereferencing the pointer to get the value directly. Wait, what?
Why? Why use it for two things! Why couldn't we have had another
operator or keyword? Something like foo = deref intPtr
would have
been more than sufficient to clarify. If nothing else, at least Forth
got this sort-of right with set and fetch (!
and @
, which I could
actually rename if I decided I hate the syntax — good luck doing that
in C).
*
Go?I can finally begin to commiserate with the authors of Go and gofmt
for building a code formatter into the language after facing the
classic (inevitable) conundrum: "How do I prefer to style my pointer
type declaration?"
int *intPtr; // these are all the same
int * intPtr;
int* intPtr;
Sign me up for "things I never wanted to bother worrying about". Worse still is the extent to which this choice permeates across projects. I would have much preferred a type keyword instead, which would leave no room for this kind of syntax silliness:
int pointer intPtr;
This still doesn't solve the oddity of needing to read type declarations from right to left to make any sense of them. I'm not really clear yet why a single character was used for what seems to be a fundamental type. Maybe it is explained somewhere in K&R.
Finally getting back into C with more experience in other languages has me appreciating how small a language it really is. I can't say why, but I've been procrastinating on finishing K&R for a couple years at this point, what finally got me back into it was Essential C, which I can recommend.
Now that I finally know what I'm talking about, I can (almost) coherently explain just what I never liked about C++ as a language. Pity my coworkers and friends now.