From: Seebs on
On 2010-04-26, cbcurl <cbcurl(a)gmail.com> wrote:
> On Apr 24, 12:03�pm, spinoza1111 <spinoza1...(a)yahoo.com> wrote:
>> Peter (and you), if you think you are professional programmer should
>> AVOID idioms such as fallthrough which are unique today to C, and use
>> switch() in a structured form. This is because you're responsible to
>> program maintainers who because they are smarter than you and have a
>> work ethic, have troubled to learn languages like C Sharp and Java.

*snerk*

(This is funny for several reasons, one of which is that I am one of the
only people at $dayjob who has bothered to learn Java at all.)

> I think it is widely agreed that C's default fallthrough behavior is
> not desirable, but I fail to see the harm in making use of this
> feature as long as you use an explicit comment to indicate that it is
> intentional and not an accident. Most C compilers now can generate
> warnings/errors for fallthrough lacking an explicit comment, so as
> long as you have enabled this behavior in your compiler you should be
> safe from this particular type of error.

I've never seen a compiler which provided spurious diagnostics for
the case where there are multiple consecutive case labels without intervening
statements, though, which is what Nilges is whinging about.

There is actually a real example of fallthrough in pseudo, because there's
a large set of cases all of which share common code, and 6 of which share
an additional three lines of setup code.

> Of course, if you really knew Java yourself, you would have known that
> it copied C's fallthrough behavior and suffers from the same issues.

Heh.

> C# does not fallthrough by default, but does let you jump to other
> case statements using goto, which is even more general.

And even more vulnerable to non-obvious code flow. At least with C's
switch, you never have to worry that something else in the code will
have jumped to a given case.

-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: Seebs on
On 2010-04-26, blmblm myrealbox.com <blmblm(a)myrealbox.com> wrote:
>> > > switch (msg->op) {
>> > > case OP_FCHOWN: /* FALLTHROUGH */
>> > > case OP_FCHMOD: /* FALLTHROUGH */
>> > > case OP_FSTAT:
>> > > prefer_ino = 1;
>> > > pseudo_debug(2, "%s %llu [%s]: ", pseudo_op_name(msg->op),
>> > > (unsigned long long) msg->ino,
>> > > msg->pathlen ? msg->path : "no path");
>> > > break;
>> > > default:
>> > > pseudo_debug(2, "%s %s [%llu]: ", pseudo_op_name(msg->op),
>> > > msg->pathlen ? msg->path : "no path",
>> > > (unsigned long long) msg->ino);
>> > > break;
>> > > }

He cheats, of course, by stripping the comment line immediately above the
switch():

/* debugging message. Primary key first. */

>> The two calls to pseudo_debug2 do the same thing, and one of them
>> appears to get the parameters out of order!

Actually, no. As part of its general pattern of paranoia and resilience,
the pseudo client attempts to provide the server with two separate kinds
of identification of each file:
* its inode number (a raw entry on the disk allowing you to
identify a distinct file)
* its path name

For most operations, the path name is the "dominant" key, and the inode
number is there only for sanity checking. However, for three operations
(fchown, fchmod, fstat), the original program will have been working on
the raw descriptor for an already-opened file; this file could be renamed
after being opened, or we may never have found the name of the file, so
the inode becomes the primary key and the path the secondary key. Thus,
I swap the order of the two arguments to display the more significant
one first.

>> if (msg->op == OP_FCHOWN || msg_op == OP_FCHMOD || msg_op == FSTAT).
>> prefer_ino = 1;
>> pseudo_debug(2, "%s %llu [%s]: ", pseudo_op_name(msg->op),
>> (unsigned long long) msg->ino,
>> msg->pathlen ? msg->path : "no path"); //
>> If this, indeed, is the right order

This is a noticably less maintainable piece of code (consider what
happens if the list expands beyond three items). C's switch is used
in these cases for a good reason.

>> Even if it is possible to call pseudo_debug in one case with an
>> unsigned 64 bit second parameter, and a string in the other, if for
>> some reason the code in pseudo_debug supports this polymorphism, it is
>> simply unacceptable.

> To me it seems likeliest that pseudo_debug is a variadic(?) function,
> taking arguments similar to those passed to fprintf. That second
> parameter looks very much like a printf-style format string, and the
> remaining parameters seem to me to match up fine with its conversion
> specifiers.

Exactly. This is a standard idiom. And thanks to a mildly non-standard
extension, gcc is providing type checking for these arguments, comparing
them to the format string appropriately.

-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: Gus Gassmann on
Seebs wrote:
> On 2010-04-26, cbcurl <cbcurl(a)gmail.com> wrote:
>> On Apr 24, 12:03 pm, spinoza1111 <spinoza1...(a)yahoo.com> wrote:
>>> Peter (and you), if you think you are professional programmer should
>>> AVOID idioms such as fallthrough which are unique today to C, and use
>>> switch() in a structured form. This is because you're responsible to
>>> program maintainers who because they are smarter than you and have a
>>> work ethic, have troubled to learn languages like C Sharp and Java.
>
> *snerk*
>
> (This is funny for several reasons, one of which is that I am one of the
> only people at $dayjob who has bothered to learn Java at all.)

Seebs,

I generally agree with most of what you write, but could you please
refrain from using the phrase "one of the only". It should be "one of
the few".

Thank you.
From: Peter Flass on
Patrick Scheible wrote:
> cbcurl <cbcurl(a)gmail.com> writes:
>
>> On Apr 25, 3:43=A0am, Patrick Scheible <k...(a)zipcon.net> wrote:
>>> spinoza1111 <spinoza1...(a)yahoo.com> writes:
>>>> That's what the code looks to a professional programmer.
>>> No, that's what the code looks like to a programmer who's a bit green
>>> or rusty on C and doesn't pick up on its idioms.
>>>
>>> "Professional programmer" is a meaningless phrase as there is no
>>> professional certification comparable to doctors or lawyers.
>> "Professional programmer" just means you get paid to program and
>> largely make a living doing so. Just like "professional musician",
>> "professional golfer", etc. The more you get paid, the more
>> "professional" you are. ;-)
>
> Was Bernie Madoff a professional investment adviser? He got paid for
> it pretty well...
>
He was certainly a professional _something_.
From: spinoza1111 on
On Apr 27, 12:33 am, Gus Gassmann <horand.gassm...(a)gmail.com> wrote:
> Seebs wrote:
> > On 2010-04-26, cbcurl <cbc...(a)gmail.com> wrote:
> >> On Apr 24, 12:03 pm, spinoza1111 <spinoza1...(a)yahoo.com> wrote:
> >>> Peter (and you), if you think you are professional programmer should
> >>> AVOID idioms such as fallthrough which are unique today to C, and use
> >>> switch() in a structured form. This is because you're responsible to
> >>> program maintainers who because they are smarter than you and have a
> >>> work ethic, have troubled to learn languages like C Sharp and Java.
>
> > *snerk*
>
> > (This is funny for several reasons, one of which is that I am one of the
> > only people at $dayjob who has bothered to learn Java at all.)

I don't think you have. You haven't learned how to use C, and I say
this because of your queue.C Coding Horror alone, which has many more
problems, such as out of order parameters. So spare us your Java.

Besides, you need to get over to the Delete case in process for the
Herb Schildt article at wikipedia, and post your opinions. I wouldn't
want your voice not to be heard.
>
> Seebs,
>
> I generally agree with most of what you write, but could you please
> refrain from using the phrase "one of the only". It should be "one of
> the few".
>
> Thank you.