"Continue" usage

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

    #31
    Re: "Continue& quot; usage

    Nick Keighley wrote:
    is clearer. For a start it avoids an inverted test.
    I don't write predicates with "not" in the name.
    I don't think that's a fair criticism; I thought Richard's
    `complexConditi onNotMatched` was a standin for whatever
    expression was required, with the `Not` showing intent,
    not the actual presence of a `Not` in the name.
    So
    I would have coded your original example as
    >
    while(n--){
    if (!complexCondit ionMatched(n))
    continue; /* not interested. Check the next if there is one. */
    >
    /*do processing of things we are interested in*/
    }
    >
    there is some evidence (if forced to cite I'll try "The Psychology
    of Computer Programming") that human beings (including computer
    programnmers) prefer positive to negative logic.
    I think there are subsequent studies in that direction, but I
    don't have a cite to hand. One of my rantettes is against languages
    that don't have an `unless`.

    --
    'It changed the future .. and it changed us.' /Babylon 5/

    Hewlett-Packard Limited registered office: Cain Road, Bracknell,
    registered no: 690597 England Berks RG12 1HN

    Comment

    • CBFalconer

      #32
      Re: "Continue& quot; usage

      Chris Dollin wrote:
      >
      .... snip ...
      >
      I think there are subsequent studies in that direction, but I
      don't have a cite to hand. One of my rantettes is against
      languages that don't have an `unless`.
      How about:

      unless (x) if (y) z;
      -->
      if (!x && y) z; /* for C */

      --
      [mail]: Chuck F (cbfalconer at maineline dot net)
      [page]: <http://cbfalconer.home .att.net>
      Try the download section.

      Comment

      • Ben Pfaff

        #33
        Re: &quot;Continue& quot; usage

        CBFalconer <cbfalconer@yah oo.comwrites:
        How about:
        >
        unless (x) if (y) z;
        -->
        if (!x && y) z; /* for C */
        I suppose one could
        #define unless(conditio n) if (!(condition))
        but I would not advocate it.
        --
        Ben Pfaff

        Comment

        • Richard Bos

          #34
          Re: &quot;Continue& quot; usage

          Ben Pfaff <blp@cs.stanfor d.eduwrote:
          CBFalconer <cbfalconer@yah oo.comwrites:
          >
          How about:

          unless (x) if (y) z;
          -->
          if (!x && y) z; /* for C */
          >
          I suppose one could
          #define unless(conditio n) if (!(condition))
          but I would not advocate it.
          In other words, if you want PERL, you know where to find it.
          (A sentiment which I heartily endorse.)

          Richard

          Comment

          • Chris Dollin

            #35
            Re: &quot;Continue& quot; usage

            Ben Pfaff wrote:
            CBFalconer <cbfalconer@yah oo.comwrites:
            >
            >How about:
            >>
            > unless (x) if (y) z;
            >-->
            > if (!x && y) z; /* for C */
            >
            I suppose one could
            #define unless(conditio n) if (!(condition))
            but I would not advocate it.
            Much as I like `unless`, I would not advocate this either. Dinking
            around with control-structure macros is, I believe, a good way to
            confuse the other programmers who might be working on your code.

            /Sometimes/ you get enough ROI for it to be worthwhile, when the
            macro(s) hide enough details in the right kind of way. I'm willing
            to pay the !() price of an unless-less C; but any imperative language
            I design has an `unless` conditional (and an `until` loop).

            --
            'It changed the future .. and it changed us.' /Babylon 5/

            Hewlett-Packard Limited Cain Road, Bracknell, registered no:
            registered office: Berks RG12 1HN 690597 England

            Comment

            • Ben Pfaff

              #36
              Re: &quot;Continue& quot; usage

              Chris Dollin <chris.dollin@h p.comwrites:
              Much as I like `unless`, I would not advocate this either. Dinking
              around with control-structure macros is, I believe, a good way to
              confuse the other programmers who might be working on your code.
              >
              /Sometimes/ you get enough ROI for it to be worthwhile, when the
              macro(s) hide enough details in the right kind of way.
              My favorite example of a worthwhile control structure macro is a
              macro for iterating through linked lists constructed in clever
              ways, so that code like

              for (node = list; node != NULL; node = node->next) {
              struct data *d = container_of(no de, struct data, member);
              ...do something with d...
              }

              (or often much worse than that) can be condensed to something
              like

              struct data *d;
              LIST_FOR_EACH (d, struct data, member, list) {
              ...do something with d...
              }

              which personally seems more readable.
              --
              char a[]="\n .CJacehknorstu" ;int putchar(int);in t main(void){unsi gned long b[]
              ={0x67dffdff,0x 9aa9aa6a,0xa77f fda9,0x7da6aa6a ,0xa67f6aaa,0xa a9aa9f6,0x11f6} ,*p
              =b,i=24;for(;p+ =!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
              2:{i++;if(i)bre ak;else default:continu e;if(0)case 1:putchar(a[i&15]);break;}}}

              Comment

              • Antoninus Twink

                #37
                Re: &quot;Continue& quot; usage

                On 22 Sep 2008 at 21:48, CBFalconer wrote:
                Simply use goto. Note that this has the significant advantage that a
                short search of the code source shows you the destination.
                More fantastic advice for the C newbie from CBF...

                Comment

                Working...