From: Seebs on
On 2010-03-06, Stefan Ram <ram(a)zedat.fu-berlin.de> wrote:
> Tim Streater <timstreater(a)waitrose.com> writes:
>>What about maintenance? Someone later will look at that and waste half a
>>day trying to see if there's some reason it's written that way.

> That would be in favor of such a construct as it indicates
> that it would help to find the incompetent code reviewers.

I wouldn't spend half a day on it, but I'd at the very least check the
rest of the code to see whether it used the same idiom.

Code reviewers who don't check out deviation from idioms are not being
careful enough, IMHO. It may be there's a good reason for it, but the most
common reasons I've seen are:

1. The person writing the code is not very familiar with standard idioms,
and may also make common mistakes that those idioms are designed to prevent.
2. The code DOES follow the idiom, and I misread it the first time.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Phil Carmody on
Richard Heathfield <rjh(a)see.sig.invalid> writes:
> pete wrote:
> <snip>
>
>> To count down through an array with N elements, I use
>>
>> size_t i = N;
>>
>> while (i-- != 0) {
>> array[i];
>> }
>
> Isn't this where we came in? Or was that another thread?

Oh, don't be such an idiom!

Phil
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1
From: Ersek, Laszlo on
In article <LeadnUHKaP2DCgzWnZ2dnUVZ8vxi4p2d(a)brightview.co.uk>, Tim Streater <timstreater(a)waitrose.com> writes:
> On 05/03/2010 22:29, Ersek, Laszlo wrote:
>> In article<lnmxymsesg.fsf(a)nuthaus.mib.org>,
>> Keith Thompson<kst-u(a)mib.org> writes:
>>
>>> Would you even consider writing '7 == x' rather than 'x == 7'
>>> if C's equality and comparison operators were more distinct?
>>>
>>> For example, consider a hypothetical C-like language in which the
>>> equality operator is spelled "=" and the assignment operator is
>>> "<-", and "==" is a syntax error. (Yes, that would quietly break
>>> "x<-1"; let's ignore that.)
>>>
>>> In such a language, would you ever write "if (7 = x)" in preference
>>> to "if (x = 7)"? If so, why?
>>
>> No, I would not have picked up the "7 == x" style in that case.
>>
>> For example, Pascal has := for assignment and = for equality (IIRC :)). Even
>> in C, I started out with "x == 7". I was occasionally bitten by
>> "if (x = 7)" typos. Not very frequently, and most of the time caught by
>> compiler warnings. However, on some forum somebody brought up "7 == x"
>> explicitly, and after giving the idea my unrelenting attention :) for a
>> minute or two, I liked it so much that I trained myself to it.
>
> What about maintenance? Someone later will look at that and waste half a
> day trying to see if there's some reason it's written that way.

You are right.

In a pro setting, I'll participate when the coding style is set, and
then I'll follow it. If no coding style is set at all, I'll have my
share of the guerilla development. I may hint at the necessity of a
coding style, but I won't fight for it, because I hate politics, and
some co-workers always take it as an attack on their authority. I help
with creating guidelines the best I can when I'm asked, but I'm no
enforcer.

In a hobbyist setting, like I've been coding C recently, I don't care.
(The word being "hobby", not "unpaid job". (Hobby doesn't imply low
quality (hopefully!), just that I'm my boss and my customer.)) I don't
code for users and I work alone. I code for myself and am happy if
others benefit too. (... Though it seems they can prod me into more
work.)

Cheers,
lacos
From: Richard Heathfield on
Ersek, Laszlo wrote:
> In article <LeadnUHKaP2DCgzWnZ2dnUVZ8vxi4p2d(a)brightview.co.uk>, Tim Streater <timstreater(a)waitrose.com> writes:
>> On 05/03/2010 22:29, Ersek, Laszlo wrote:

<snip>

>>> However, on some forum somebody brought up "7 == x"
>>> explicitly, and after giving the idea my unrelenting attention :) for a
>>> minute or two, I liked it so much that I trained myself to it.
>> What about maintenance? Someone later will look at that and waste half a
>> day trying to see if there's some reason it's written that way.
>
> You are right.

No, he isn't. :-) Anyone who wastes half a day on understanding 7==x is
not the kind of person you want maintaining C code in the first place.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
From: Seebs on
On 2010-03-06, Richard Heathfield <rjh(a)see.sig.invalid> wrote:
> No, he isn't. :-) Anyone who wastes half a day on understanding 7==x is
> not the kind of person you want maintaining C code in the first place.

Not "understanding 7==x". Figuring out whether it's been done that way for
a particular reason. And while "half a day" may be a bit much, I've certainly
seen fairly experienced coders lose an hour or more to something that was
written in a way that suggested a deeper meaning or intent when it was, in
fact, merely idiosyncratic.

If someone wrote:
for (i = 0; max > i; ++i)
I'd at least want to investigate briefly whether there was some non-obvious
reason for which the comparison was written backwards. If I couldn't find
one, I'd check every comparison in the code (and a lot of other stuff) more
carefully, for much the same reason that I check code more carefully if
there's trivial misspellings in the comments.

Sometimes, the effort's wasted, but so far, my experience has been that it's
right more often than it's wrong.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
First  |  Prev  |  Next  |  Last
Pages: 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
Prev: integer
Next: shared memory question