On Thursday 27 May 2004 23:45 CET Kenneth Porter wrote:
> --On Thursday, May 27, 2004 10:32 PM +0200 "Malte S. Stretz"
>
> <[EMAIL PROTECTED]> wrote:
> > I'll change the rest of the "if (const = var)" to the more readable "if
> > (var == const)".
>
> Is that an Apache style thing? I always code constants on the left, to
> catch just the typo you made in your example.
No, code written the other way round is just butt ugly and insaneously hard
to grok. Maybe you can avoid the error of accidently assigning a var
instead of comparing it, but it makes reading and debugging code a tough
job which is worse than a bug in the first place. At least that's my
experience.
Especially because the "trick" with writing those the other way round just
works as long as you compare a const to a var. If you compare two vars, it
won't help so you must not rely on this cathing your typos.
Instead, current versions of gcc (and I guess Intel, Microsoft and Borland
compilers do so, too) do warn you if you write something like "if (var =
1)" -- you have to write "if ((var = 1))" if you really want to do that.
Which you shouldn't do anyway as it makes code harder to understand, too.
Better is "var = 1; if (var) ..." (in two lines of course).
Cheers,
Malte
--
[SGT] Simon G. Tatham: "How to Report Bugs Effectively"
<http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>
[ESR] Eric S. Raymond: "How To Ask Questions The Smart Way"
<http://www.catb.org/~esr/faqs/smart-questions.html>