Pedants

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts

  • Richard Bos
    Guest replied
    Re: Pedants

    Kaz Kylheku <kkylheku@gmail .comwrote:
    Casting malloc is just fine.
    Casting malloc() is a grave mistake, as bad as making a bottle of apple
    juice carry a dangerous substance sign.
    In fact, it's useful in a C compiler to have C++-style type checking
    for void *: that is to say, implicit conversions from void * to some
    other pointer type being diagnosed.
    No, it's not. In C, those conversions are correct, and with good reason.
    Getting spurious warnings for them is a bother, and makes you ignore
    real warnings. Casting away those spurious warnings is also a bother,
    and makes you a. ignore real casts and b. cast away other, important,
    warnings.
    The rationale for /not/ casting malloc is outdated, based on the idea
    that compilers allow functions to be called without a prior
    declaration, without issuing a diagnostic.
    That's only part of the rationale, and not the most important part.
    Code reviewers have to look not only for bugs, but for adherence to
    coding conventions (and be pedantic about that just as much as
    language issues).
    And to look for dangerous code.

    Spurious casts are dangerous. Not always to the program - but nearly
    always to the program_mer_. That's the real reason to avoid them. Casts
    should make you sit up and think "Hey, a cast! What is going on here?",
    not "Oh, *yawn* another cast, must be more C++-avoidance hackery".

    Richard

    Leave a comment:


  • Walter Roberson
    Guest replied
    Re: Pedants

    In article <4869ef20.15549 25150@news.xs4a ll.nl>,
    Richard Bos <rlb@hoekstra-uitgeverij.nlwr ote:
    >roberson@ibd.n rc-cnrc.gc.ca (Walter Roberson) wrote:
    >In article <g4asrm$au7$2@a ioe.org>, santosh <santosh.k83@gm ail.comwrote:
    >Nick Keighley wrote:
    >int i = NULL;
    >Is there any reason at all to assign a null pointer constant to an int?
    >Why would anyone do this instead of using 0?
    >Confusion with the NUL character perhaps?
    >Why? Would you normally do
    int i='\0';
    >rather than
    char c='\0';
    int i=0;
    void *p=NULL;
    Someone might (but *I* probably wouldn't), if i represented a character.
    For example,

    int i='\0';
    if (somecondition) {
    i = getchar();
    }
    if (i == EOF) {
    /* whatever */
    }

    That is, Best Practice is to use an int to store any value that
    is a char that has to be read in by getchar(), getc() or fgetc()
    (because you need to be able to post-check against the int value EOF).
    If someone were initializing that int and they wanted to emphasize the
    char-in-int's-clothing nature of the variable, they just might
    choose to initialize with '\0'... or might get confused about the
    meaning of NULL and try to initialize with that.
    --
    "After all, what problems has intellectualism ever solved?"
    -- Robert Gilman

    Leave a comment:


  • pete
    Guest replied
    Re: Pedants

    Richard Bos wrote:
    pete <pfiland@mindsp ring.comwrote:
    >For
    > char *a = {STRING};
    >in a context of doing something
    >like what the ctype functions do,
    >do you prefer
    > if (a[x] 0)
    >or
    > if (a[x] '\0')
    >?
    >
    No, but in that case, a[x] _is_ a char, not an int. The discussion was
    about assigning NULL (or the NUL character) to an int, not to any kind
    of integer including the rather special char.
    .... and it was about pedants, before it was about that.

    Now, I want to talk about some code that I've written:

    I used
    if (a[x] '\0')

    --
    pete

    Leave a comment:


  • Richard Bos
    Guest replied
    Re: Pedants

    pete <pfiland@mindsp ring.comwrote:
    Richard Bos wrote:
    roberson@ibd.nr c-cnrc.gc.ca (Walter Roberson) wrote:
    In article <g4asrm$au7$2@a ioe.org>, santosh <santosh.k83@gm ail.comwrote:
    >Nick Keighley wrote:
    >>int i = NULL;
    >Is there any reason at all to assign a null pointer constant to an int?
    >Why would anyone do this instead of using 0?
    Confusion with the NUL character perhaps?
    Why? Would you normally do

    int i='\0';

    rather than

    char c='\0';
    int i=0;
    void *p=NULL;
    >
    For
    char *a = {STRING};
    in a context of doing something
    like what the ctype functions do,
    do you prefer
    if (a[x] 0)
    or
    if (a[x] '\0')
    ?
    No, but in that case, a[x] _is_ a char, not an int. The discussion was
    about assigning NULL (or the NUL character) to an int, not to any kind
    of integer including the rather special char.

    Richard

    Leave a comment:


  • pete
    Guest replied
    Re: Pedants

    Richard Bos wrote:
    roberson@ibd.nr c-cnrc.gc.ca (Walter Roberson) wrote:
    >
    >In article <g4asrm$au7$2@a ioe.org>, santosh <santosh.k83@gm ail.comwrote:
    >>Nick Keighley wrote:
    >>>int i = NULL;
    >>Is there any reason at all to assign a null pointer constant to an int?
    >>Why would anyone do this instead of using 0?
    >Confusion with the NUL character perhaps?
    >
    Why? Would you normally do
    >
    int i='\0';
    >
    rather than
    >
    char c='\0';
    int i=0;
    void *p=NULL;
    For
    char *a = {STRING};
    in a context of doing something
    like what the ctype functions do,
    do you prefer
    if (a[x] 0)
    or
    if (a[x] '\0')
    ?

    --
    pete

    Leave a comment:


  • Richard Bos
    Guest replied
    Re: Pedants

    roberson@ibd.nr c-cnrc.gc.ca (Walter Roberson) wrote:
    In article <g4asrm$au7$2@a ioe.org>, santosh <santosh.k83@gm ail.comwrote:
    Nick Keighley wrote:
    >
    int i = NULL;
    >
    Is there any reason at all to assign a null pointer constant to an int?
    Why would anyone do this instead of using 0?
    >
    Confusion with the NUL character perhaps?
    Why? Would you normally do

    int i='\0';

    rather than

    char c='\0';
    int i=0;
    void *p=NULL;

    Richard

    Leave a comment:


  • Kaz Kylheku
    Guest replied
    Re: Pedants

    On Jun 28, 2:51 am, "Serve Lau" <ni...@qinqin.c omwrote:
    "Kaz Kylheku" <kkylh...@gmail .comschreef in berichtnews:1a9 07d38-8880-476d-9420-f0c458983d98@59 g2000hsb.google groups.com...
    On Jun 27, 3:03 pm, "Serve Lau" <ni...@qinqin.c omwrote:
    >
    "Richard Heathfield" <r...@see.sig.i nvalidschreef in
    A little care up front, and everyone wins.
    >
    Using 0 instead of NULL is a matter of opinion though, its both correct.
    That's true, and knowing this perhaps makes you more of a language
    pedant than your fake pedant.
    >
    as im sure you remember from the first post a pedant is:
    >
    1. a person who makes an excessive or inappropriate display of learning.
    I recall from the root article that a disjunction of three possible
    definitions was given. By the above branch, nobody is a pedant during
    a code review, because display of all pertinent learning is required.
    In that situation you're an expert, and as such you're being paid for
    what you know, and so you have to deliver.

    A commercial lint program can generate thousands of diagnostics even
    for a fairly small project. Many of those diagnostics are not useful
    in the given situation, so the tool has to be iteratively configured
    to improve its yield. People pay for tools like this and expect them
    to have a large diagnostic base.

    A pedant can also be configured that way. For instance, if I am told
    ``this code deliberately uses non-standard escape sequences in string
    and character literals, please ignore'', then I will no longer flag
    such uses.

    Leave a comment:


  • Walter Roberson
    Guest replied
    Re: Pedants

    In article <g4asrm$au7$2@a ioe.org>, santosh <santosh.k83@gm ail.comwrote:
    >Nick Keighley wrote:
    >int i = NULL;
    >Is there any reason at all to assign a null pointer constant to an int?
    >Why would anyone do this instead of using 0?
    Confusion with the NUL character perhaps?

    --
    "Allegories are in the realm of thoughts, what ruins are in
    the realm of things." -- Walter Benjamin

    Leave a comment:


  • santosh
    Guest replied
    Re: Pedants

    Nick Keighley wrote:
    On Jun 27, 11:06 pm, "Serve Lau" <ni...@qinqin.c omwrote:
    >"Kaz Kylheku" <kkylh...@gmail .comschreef in
    >>
    berichtnews:774 439aa-17e9-4a34-9689-571ba20859f7@26 g2000hsk.google groups.com...
    >
    I suspect this was supposed to be ``write NULL for 0''. For
    instance: int x = NULL;
    If this is in fact the case, the pedant is right to flag this
    idiocy.
    >>
    >The compiler would have flagged that long before it arrives there if
    >NULL is defined as ((void *)0)
    >
    Coincidentally, I'm just removing lots of
    int i = NULL;
    >
    from some legacy code I'm porting.
    Perhaps a tougher review on the original code
    would have saved me the trouble.
    Is there any reason at all to assign a null pointer constant to an int?
    Why would anyone do this instead of using 0?

    Leave a comment:


  • Nick Keighley
    Guest replied
    Re: Pedants

    On Jun 27, 11:06 pm, "Serve Lau" <ni...@qinqin.c omwrote:
    "Kaz Kylheku" <kkylh...@gmail .comschreef in berichtnews:774 439aa-17e9-4a34-9689-571ba20859f7@26 g2000hsk.google groups.com...
    I suspect this was supposed to be ``write NULL for 0''. For instance:
     int x = NULL;
    If this is in fact the case, the pedant is right to flag this idiocy.
    >
    The compiler would have flagged that long before it arrives there if NULLis
    defined as ((void *)0)
    Coincidentally, I'm just removing lots of
    int i = NULL;

    from some legacy code I'm porting.
    Perhaps a tougher review on the original code
    would have saved me the trouble.

    --
    Nick Keighely

    Leave a comment:


  • lawrence.jones@siemens.com
    Guest replied
    Re: Pedants

    Richard Heathfield <rjh@see.sig.in validwrote:
    >
    I don't know of *anyone* in this group who makes excessive or inappropriate
    displays of learning where the C language is concerned.
    Indeed, excessive or inappropriate displays of *ignorance* are far more
    common. ;-)

    -- Larry Jones

    Everybody's a slave to routine. -- Calvin

    Leave a comment:


  • Richard Heathfield
    Guest replied
    Re: Pedants

    Serve Lau said:
    >
    "Richard Heathfield" <rjh@see.sig.in validschreef in bericht
    news:XMKdnYcjAP 7tmfrVnZ2dneKdn ZydnZ2d@bt.com. ..
    >I don't know of anyone in this group who is a kung fu master. Neither do
    >I know of anyone in this group who has ever administered kicks to a
    >member of the species Equus asinus. So it's hard to see how relevant
    >your point is. But even if I'm to take it as an analogy, it seems
    >inappropriat e. If you can think of any C expert in this group who is not
    >prepared to be patiently informative and helpful to those who are ready
    >and willing to learn about C, you are probably being over-critical of
    >that C expert based on a poor sampling. I am constantly amazed by how
    >much time some people here spend on helping others to learn their
    >language, and by how much patience they show in the face of infantile
    >criticism by the ignorant.
    >
    Try to keep context. This is not about clc!
    Presumably it's about C, right?
    Showing some knowledge here is not inappropriate is it.
    I'm delighted to hear it.
    I was just reacting to somebody calling me a
    pedant because I know the difference between NULL and 0
    Don't bother reacting - it's a compliment, whether the person using it
    knows it or not.
    while I never
    spread the religion on what to use best and why.
    Those who do are zealots, not pedants. C is not about religion. It's about
    engineering. The laws of physics are not negotiable, so engineers tend to
    be pedantic where it counts. Unfortunately, the laws of computing very
    often /are/ negotiable (depending on how many platforms your code needs to
    run on), which is probably why we see so many foolish disputes in this
    newsgroup. Alas, there are still plenty of "All the World's a Vax"
    worshippers, although of course they are no longer quite so naive as to
    believe in Vaxen.

    --
    Richard Heathfield <http://www.cpax.org.uk >
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999

    Leave a comment:


  • Serve Lau
    Guest replied
    Re: Pedants


    "Richard Heathfield" <rjh@see.sig.in validschreef in bericht
    news:XMKdnYcjAP 7tmfrVnZ2dneKdn ZydnZ2d@bt.com. ..
    I don't know of anyone in this group who is a kung fu master. Neither do I
    know of anyone in this group who has ever administered kicks to a member
    of the species Equus asinus. So it's hard to see how relevant your point
    is. But even if I'm to take it as an analogy, it seems inappropriate. If
    you can think of any C expert in this group who is not prepared to be
    patiently informative and helpful to those who are ready and willing to
    learn about C, you are probably being over-critical of that C expert based
    on a poor sampling. I am constantly amazed by how much time some people
    here spend on helping others to learn their language, and by how much
    patience they show in the face of infantile criticism by the ignorant.
    Try to keep context. This is not about clc! Showing some knowledge here is
    not inappropriate is it. I was just reacting to somebody calling me a pedant
    because I know the difference between NULL and 0 while I never spread the
    religion on what to use best and why.

    Leave a comment:


  • Tor Rustad
    Guest replied
    Re: Pedants

    Serve Lau wrote:
    >
    "user923005 " <dcorbit@connx. comschreef in bericht
    news:b4c444e7-1182-4b9c-8e0a-08507cc713c3@26 g2000hsk.google groups.com...
    >For testing software and describing problems, there is *nothing*
    >better than a pedant.
    >
    I disagree totally. I have had a pedant as code reviewer and he always
    got stuck in language issues never finding real bugs.

    Code reviewers, are not primary there to track down your bugs. :)


    There are two orthogonal "groups" receiving your code: the compilers and
    other humans. For low-quality code, the code audit will not do much more
    than check:

    1. Q/A ensure code is accepted by compiler in conforming mode, with
    exceptions flagged with approval or rejection

    2. Q/A ensure code is following an in-house coding standard, and/or set
    of coding rules

    main point here is 2, and to validate that the source is easily parsed
    by humans. If code isn't readable and well-designed, it is rather
    useless.

    An audit should also include

    3. Q/A ensure consistency from functional requirements, through detailed
    design and test procedures.

    Things like I
    wasnt allowed to declare variables in the middle of a function or write
    NULL or 0. The software never got better
    If some cowboy C programmers vaste my time, by sending a module to Q/A,
    _before_ the module even compile, they will not like the response.

    For high-quality code, an audit may go far deeper, depending on what
    assurance level is targeted.

    --
    Tor <bwzcab@wvtqvm. vw | tr i-za-h a-z>

    Leave a comment:


  • Chris H
    Guest replied
    Re: Pedants

    In message <cf553$48652499 $541fc2ec$23305 @cache3.tilbu1. nb.home.nl>,
    Serve Lau <nihao@qinqin.c omwrites
    >
    >"user923005 " <dcorbit@connx. comschreef in bericht
    >news:b4c444e 7-1182-4b9c-8e0a-08507cc713c3@26 g2000hsk.google groups.com...
    >>For testing software and describing problems, there is *nothing*
    >>better than a pedant.
    >
    >I disagree totally. I have had a pedant as code reviewer and he always
    >got stuck in language issues never finding real bugs. Things like I
    >wasnt allowed to declare variables in the middle of a function or write
    >NULL or 0. The software never got better

    That is not language issues but coding standard issue.
    Very important and they do reduce bug count.
    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



    Leave a comment:

Working...