Re: need help..
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Sun, 03 Apr 2005 00:00:20 GMT
dot@xxxxxxx writes:
> On Sat, 02 Apr 2005 20:00:39 GMT, Keith Thompson <kst-u@xxxxxxx> wrote:
>
>>>>3) Quality compilers warn about the ``if (foo = 0)'' construct.
>>>
>>> It should be a syntax error.
Please don't snip nested attributions.
>>In a different language, sure. In C, an assignment is an expression
>>that yields the value assigned; changing that would break too much
>>existing code.
>
> If the compiler can detect it sufficiently to warn, it can hand out an
> error, stop compilation and force you to fix it. And how many perfectly
> good programs have come crashing down over this one simple error? Even
> worse when comparisons ( < and > ) are single characters... it's confusing.
You can't make "=" not yield a value without breaking existing
programs. Making an assignment invalid in a condition but valid
elsewhere would be an ugly wart.
I don't find the fact that '<' and '>' are single characters confusing
at all. They match mathematical notation.
> Frankly, it would have made more sense to have the testing done on a single
> =, & or | marks and use the doubles for assignment along with >> and <<
> which are used for bit shifts.
>
> Think about it... 1 letter: compare, 2 letters: perform an operation. (or
> visa versa) It would be totally consistent. As it is now the rule is 1
> letter does an operation EXCEPT for bit shifts, 2 letters does a test EXCEPT
> for less and greater. It's inconsistent and when learning I found it
> confusing as all get out.
I've never assumed that the number of characters in an operator has
any significance. I just learned what each one means.
> So I have a little header I use with a bunch of defines...
>
> #define is ==
> #define lt <
> #define gt >
> #define ne !=
> #define or ||
> #define and &&
> #define shiftl <<
> #define shiftr >>
> etc.
>
> Gives me syntax like this:
>
> if (x and (y lt 7))
>
> if ((x lt y) or (y is 7))
>
> No more silly mistakes.
If I were going to do something like that, I'd use "eq" rather than
"is" for equality. (Some languages distinguish between equality and
identity, and use "is" for the latter.) I'd also use the symbols in
<iso646.h> whenever possible, and try to be consistent with them
otherwise.
But I'd much rather just learn the language and use it. If I'm going
to read your code, I have to undertand the language *and* the macros
you've chosen. For this:
if (x && (y < 7))
if ((x < y) || (y == 7))
I just have to know the language.
You can use your macros if you like, but I guarantee they'll make it
more difficult for anyone else to read or maintain your code.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- References:
- need help..
- From: slickn_sly
- Re: need help..
- From: Martin Ambuhl
- Re: need help..
- From: CBFalconer
- Re: need help..
- From: Nils Weller
- Re: need help..
- From: Keith Thompson
- need help..
- Prev by Date: Re: Confirm this is Standard code
- Next by Date: Re: need help..
- Previous by thread: Re: need help..
- Next by thread: Re: need help..
- Index(es):
Relevant Pages
|