Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #143213

Re: for ... else blocks

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: for ... else blocks
Date 2019-04-18 21:46 +0100
Organization A noiseless patient Spider
Message-ID <87sguf2g9y.fsf@bsb.me.uk> (permalink)
References (13 earlier) <QJItE.182616$a%2.84036@fx30.am4> <q99j3f$j3i$1@dont-email.me> <lR2uE.366976$coJ.297861@fx36.am4> <87a7gn3y1y.fsf@bsb.me.uk> <vV4uE.518314$iiB1.184802@fx08.am4>

Show all headers | View raw


(comp.lang.c++ trimmed)

Bart <bc@freeuk.com> writes:

> On 18/04/2019 20:36, Ben Bacarisse wrote:
>> Bart <bc@freeuk.com> writes:
>>
>>> ... If writing C, then every so often you have to stop and work around
>>> the problem of C having only single-level breaks.
>>
>> This is a case where what you call a work-around, I call an improvement.
>>
>> I like to reason about code, and the label helps a lot.  I often ask,
>> particularly after loops, "what is the state of the program at this
>> point?" and the presence of a label is a big red flag telling me I have
>> to take partial execution into account.  It's not a huge advantage,
>> since multi-level breaks are rare and likely to be flagged by a big
>> comment, but the label is in just the right place for me to know I have
>> to think about gotos.
>
> In my codebase (only compiled code not scripting), about 2.5% of all
> 'breaks' are multi-level ones (and break is used very commonly in my
> code to terminate endless loops),

That seems like a lot.  We obviously have different coding styles.

> and 2% of all 'for' loops are 'for-else'.
>
> It doesn't sound much, but DB mentioned once that only 1.5% of his C
> for-loops were anything other simple iteration via a variable. Yet C
> loops still allow all those other possibilities, things that can make
> code harder to reason about, not easier.

Is this supposed to be an argument in favour of making matters worse?  I
don't follow the logic.

-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

for ... else blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-04-16 14:57 -0400
  Re: for ... else blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-04-16 15:06 -0400
    Re: for ... else blocks Bart <bc@freeuk.com> - 2019-04-16 20:35 +0100
      Re: for ... else blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-04-16 17:02 -0400
        Re: for ... else blocks David Brown <david.brown@hesbynett.no> - 2019-04-16 23:36 +0200
          Re: for ... else blocks "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-04-17 00:45 +0200
            Re: for ... else blocks Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-17 01:06 +0100
              Re: for ... else blocks "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-04-17 04:45 +0200
                Re: for ... else blocks David Brown <david.brown@hesbynett.no> - 2019-04-17 09:32 +0200
                Re: for ... else blocks Bart <bc@freeuk.com> - 2019-04-17 11:38 +0100
                Re: for ... else blocks David Brown <david.brown@hesbynett.no> - 2019-04-17 14:05 +0200
                Re: for ... else blocks Bart <bc@freeuk.com> - 2019-04-17 13:57 +0100
                Re: for ... else blocks David Brown <david.brown@hesbynett.no> - 2019-04-17 15:36 +0200
                Re: for ... else blocks Bart <bc@freeuk.com> - 2019-04-17 15:16 +0100
                Re: for ... else blocks David Brown <david.brown@hesbynett.no> - 2019-04-17 17:51 +0200
                Re: for ... else blocks "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-04-17 16:15 +0200
                Re: for ... else blocks "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-04-17 16:24 +0200
                Re: for ... else blocks David Brown <david.brown@hesbynett.no> - 2019-04-17 17:55 +0200
                Re: for ... else blocks Bart <bc@freeuk.com> - 2019-04-17 17:44 +0100
                Re: for ... else blocks Bart <bc@freeuk.com> - 2019-04-17 17:48 +0100
                Re: for ... else blocks fir <profesor.fir@gmail.com> - 2019-04-17 10:18 -0700
                Re: for ... else blocks fir <profesor.fir@gmail.com> - 2019-04-17 10:32 -0700
                Re: for ... else blocks fir <profesor.fir@gmail.com> - 2019-04-17 10:38 -0700
                Re: for ... else blocks fir <profesor.fir@gmail.com> - 2019-04-17 12:12 -0700
                Re: for ... else blocks fir <profesor.fir@gmail.com> - 2019-04-17 12:25 -0700
                Re: for ... else blocks fir <profesor.fir@gmail.com> - 2019-04-17 12:39 -0700
                Re: for ... else blocks fir <profesor.fir@gmail.com> - 2019-04-17 15:52 -0700
                Re: for ... else blocks fir <profesor.fir@gmail.com> - 2019-04-17 16:50 -0700
                Re: for ... else blocks fir <profesor.fir@gmail.com> - 2019-04-17 13:58 -0700
                Re: for ... else blocks David Brown <david.brown@hesbynett.no> - 2019-04-18 12:21 +0200
                Re: for ... else blocks Bart <bc@freeuk.com> - 2019-04-18 18:54 +0100
                Re: for ... else blocks Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-18 20:36 +0100
                Re: for ... else blocks Bart <bc@freeuk.com> - 2019-04-18 21:15 +0100
                Re: for ... else blocks Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-18 21:46 +0100
                Re: for ... else blocks Bart <bc@freeuk.com> - 2019-04-17 15:05 +0100
                Re: for ... else blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-04-17 10:55 -0400
                Re: for ... else blocks Ike Naar <ike@iceland.freeshell.org> - 2019-04-18 05:57 +0000
                Re: for ... else blocks Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-17 20:43 +0100
  Re: for ... else blocks Chad <cdalten@gmail.com> - 2019-04-16 12:15 -0700
  Re: for ... else blocks Bart <bc@freeuk.com> - 2019-04-16 20:27 +0100
  Re: for ... else blocks Christian Gollwitzer <auriocus@gmx.de> - 2019-04-16 21:34 +0200
    Re: for ... else blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-04-16 16:54 -0400
    Re: for ... else blocks David Brown <david.brown@hesbynett.no> - 2019-04-16 23:32 +0200

csiph-web