Re: C question for you old guys ;-)
Re: C question for you old guys ;-)
- Subject: Re: C question for you old guys ;-)
- From: Sujal Shah <email@hidden>
- Date: Wed, 11 Jun 2003 12:09:33 -0400
On Wed, 2003-06-11 at 11:00, Jay Vaughan wrote:
>
>Only in your opinion, which is not shared by many on this list.
>
>
>
>
That nobody else is arguing against "#define is ==" on this list only
>
means to me that nobody else is arguing against it, not that nobody
>
shares my opinion...
>
>
I've known plenty of programmers who have been fired for habits like
>
this, who have lost serious project responsibilities because their
>
'smartass use of macros to make things easier' cost countless weeks
>
of debugging and hassle at the expense of big, big projects. Any pro
>
programming shop worth its salt has programming guidelines that
>
outlaw this sort of behaviour; and for good reason!
>
I don't think anyone (even jcr) is disagreeing with you that macro abuse
is bad... I think we don't believe this is macro abuse. You have to see
a difference between a convoluted macro vs. the example you're
complaining about.
Maybe if the #define was "IS" instead of "is"? Easier to recognize as a
define.
Just FYI, this is the output from GCC for the problem you described (on
Linux, my powerbook is at home):
---------------------
#include <stdio.h>
#define is ==
void myfunc (int a, int b, int is);
int main(int argc, char ** argv)
{
myfunc(1, 2, 3);
}
void myfunc (int a, int b, int is)
{
printf("this is a bug %d", is);
}
------------------
[sujal@silent temp]$ gcc test.c
test.c:5: parse error before '==' token
test.c:11: parse error before '==' token
test.c: In function `myfunc':
test.c:13: parse error before '==' token
------------------
I think this is the best reason not to do it with an inexperienced team
of programmers, because defines "defang" the compiler and its warnings.
On the other hand, if I saw that in code it would take me all of 5
minutes to figure it out the first time, and after that it would be
cake. I switch between Perl, PHP, Java, JavaScript, Obj-C, C, and C++
so frequently in my daily life that picking up new symbols and mapping
them in my brain is hardly difficult anymore.
Sujal
>
Okay, so the sole hacker on the edge of the cocoa fringe can #define
>
his language into oblivion for all I care. But doing so in a
>
group-development situation is *dangerous*, and this is why I object
>
to Apple professionals promoting the habit among the cocoa-dev crowd
>
... If I see "(val is NULL)" in code from Apple in the future, I'm
>
gonna consider switching back to Windows! (just kidding, just
>
kidding, sheesh!)
>
>
>You might want to consider the case that he *does* understand the
>
>"problems" and found them to be outweighed by the advantages in this
>
>particular case. This is what is called an engineering trade-off,
>
>which is always involved, especially when using the pre-processor.
>
>
>
>
Look at it this way. I could never write code like this with
>
#define's such as yours around:
>
>
void sector_trans(int os, int is, int ts)
>
{
>
sector_copy_trans(is, os, ts, 512);
>
}
>
>
And before you change the subject to one of "bad names for C vars",
>
I'll note that a casual 'grep -ir " is;" *c' in a /usr/src containing
>
some 20 or so various untarballed projects from freshmeat/linux and
>
Apple themselves, including device drivers and media API's, yields
>
*plenty* of vars named "is" ... and not a single #define making "is"
>
= "==" ...
>
>
#grep -ir " is;" *.c
>
drivers/md/lvm-snap.c: lv_block_exception_t *be =
>
lv_snap->lv_block_exception + is;
>
drivers/isdn/isdn_ppp.c: rs->is = is;
>
drivers/isdn/isdn_ppp.c: ri = is;
>
drivers/isdn/isdn_ppp.c: mis = is;
>
drivers/isdn/isdn_ppp.c: mis = is;
>
drivers/sound/sa1100-audio.c: audio_stream_t *s = (cmd ==
>
SNDCTL_DSP_GETOPTR) ? os : is;
>
>
[etc...]
>
>
My point is: do "#define is ==" if you're lazy and like it, but it's
>
a bad habit, and you shouldn't promote it as a habit among fellow
>
programmers, especially if you are responsible for ensuring those
>
programmers are able to use C-based API's developed for and intended
>
for use by as wide a market as possible.
>
>
Anyway, as you said, this thread is getting 'embarrassing', so lets
>
just drop it and move along with some nice cocoa, eh?
--
---- Sujal Shah --- email@hidden ---
http://www.fatmixx.com
Now Playing: _Groove Armada_ - _Vertigo_ - 006 - Serve Chilled
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.