Re: programi parsing question

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

    Re: programi parsing question

    Chris Torek <nospam@torek.n etwrites:
    <fjblurt@yahoo. comwrote:
    >>There is a discussion about the stylistic advantages and disadvantages
    >>of the following two snippets:
    [...]
    >>void foo_set_and_tes t (void) {
    > int fd;
    > if ((fd = open(...)) < 0) {
    > fail();
    > }
    >>}
    [...]
    >>void foo_init_and_th en_test_separat ely (void) {
    > int fd = open(...);
    > if (fd < 0) {
    > fail();
    > }
    >>}
    [...]
    I have a slight preference for foo_init_and_th en_test_separat ely()
    myself, but this is a matter of taste. There is even a third
    option:
    >
    void foo_set_and_the n_test_separate ly(void) {
    int fd;
    >
    fd = open(...);
    if (fd < 0) {
    fail();
    ...
    }
    ...
    }
    [...]
    Again, though, all of this is largely a matter of taste. Arguing
    about it is like arguing whether raspberry ice cream is superior
    to peach ice cream.
    The last (two) variant(s) has(ve) the advantage that the value
    assigned to fd can be inspected and possibly changed by a human using
    a 'suitable tool' (debugger) before the program acts on it.
  • Phlip

    #2
    Re: programi parsing question

    Rainer Weikusat wrote:
    Chris Torek writes:
    > int fd;
    > fd = open(...);
    >Again, though, all of this is largely a matter of taste. Arguing
    >about it is like arguing whether raspberry ice cream is superior
    >to peach ice cream.
    The last (two) variant(s) has(ve) the advantage that the value
    assigned to fd can be inspected and possibly changed by a human using
    a 'suitable tool' (debugger) before the program acts on it.
    I suspect there are style guidelines saying "always initialize every variable".
    Maybe they only apply to C++, and C is exempt.

    --
    Phlip

    Comment

    • santosh

      #3
      Re: programi parsing question

      Phlip wrote:
      Rainer Weikusat wrote:
      >
      >Chris Torek writes:
      >
      >> int fd;
      >> fd = open(...);
      >
      >>Again, though, all of this is largely a matter of taste. Arguing
      >>about it is like arguing whether raspberry ice cream is superior
      >>to peach ice cream.
      >
      >The last (two) variant(s) has(ve) the advantage that the value
      >assigned to fd can be inspected and possibly changed by a human using
      >a 'suitable tool' (debugger) before the program acts on it.
      >
      I suspect there are style guidelines saying "always initialize every
      variable". Maybe they only apply to C++, and C is exempt.
      That cannot be, unless C forbids initialising every variable, which it
      doesn't. In the dim and distant past I suppose variable redundant
      initialisations were avoided due to efficiency concerns. These no
      longer matter now, but some still prefer to avoid redundant
      initialisations as an aesthetic choice.

      Comment

      • Willem

        #4
        Re: programi parsing question

        Phlip wrote:
        ) I suspect there are style guidelines saying "always initialize every variable".
        ) Maybe they only apply to C++, and C is exempt.

        On the other hand, explicitly not initializing variables give static code
        analyzers the chance to find uses of uninitialized variables. (As opposed
        to uses of default-but-wrong-initialized values).


        SaSW, Willem
        --
        Disclaimer: I am in no way responsible for any of the statements
        made in the above text. For all I know I might be
        drugged or something..
        No I'm not paranoid. You all think I'm paranoid, don't you !
        #EOT

        Comment

        Working...