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


Groups > comp.lang.c > #162390 > unrolled thread

I have a confession to make...

Started byVir Campestris <vir.campestris@invalid.invalid>
First post2021-08-15 22:14 +0100
Last post2021-09-06 18:04 +0200
Articles 14 — 10 participants

Back to article view | Back to comp.lang.c


Contents

  I have a confession to make... Vir Campestris <vir.campestris@invalid.invalid> - 2021-08-15 22:14 +0100
    Re: I have a confession to make... Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-08-15 14:44 -0700
      Re: I have a confession to make... Thiago Adams <thiago.adams@gmail.com> - 2021-08-15 15:56 -0700
        Re: I have a confession to make... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-08-16 01:50 +0100
    Re: I have a confession to make... Bart <bc@freeuk.com> - 2021-08-16 00:18 +0100
    Re: I have a confession to make... DFS <nospam@dfs.com> - 2021-08-15 20:31 -0400
    Re: I have a confession to make... David Brown <david.brown@hesbynett.no> - 2021-08-16 08:20 +0200
      Re: I have a confession to make... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-08-15 23:21 -0700
      Re: I have a confession to make... Vir Campestris <vir.campestris@invalid.invalid> - 2021-08-17 21:43 +0100
    Re: I have a confession to make... Mark Bluemel <mark.bluemel@gmail.com> - 2021-08-16 00:32 -0700
      Re: I have a confession to make... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-08-16 14:21 +0100
        Re: I have a confession to make... Bart <bc@freeuk.com> - 2021-08-16 17:48 +0100
        Re: I have a confession to make... Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-09-06 06:30 -0700
          Re: I have a confession to make... David Brown <david.brown@hesbynett.no> - 2021-09-06 18:04 +0200

#162390 — I have a confession to make...

FromVir Campestris <vir.campestris@invalid.invalid>
Date2021-08-15 22:14 +0100
SubjectI have a confession to make...
Message-ID<sfc03t$r91$1@dont-email.me>
I've been writing C, and more lately C++, since some time in the 1980s.

I've just written a goto. I know it's evil, and I shouldn't do it, but 
just this once...

And it isn't in any of the serious stuff I do in may day job either.

You all know what a magic square is - a square where all the columns, 
rows, and diagonals add up to the same value.

I'm messing about doing it for a cube. Wikipedia says you can't for 
small cubes.

I have a square for the base, and a centre value, and therefore I can 
work out all the values for the top square as they are on diagonals with 
one of the bottom values and the centre one.

I therefore have 3 nested loops: centre value, X and Y coordinates.

And if I don't like the result I jump out of the X Y loops. Which is 
where I have that goto.

Andy
-- 
(I just felt I had to tell someone!)

[toc] | [next] | [standalone]


#162391

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2021-08-15 14:44 -0700
Message-ID<87v946gz7t.fsf@nosuchdomain.example.com>
In reply to#162390
Vir Campestris <vir.campestris@invalid.invalid> writes:
> I've been writing C, and more lately C++, since some time in the 1980s.
>
> I've just written a goto. I know it's evil, and I shouldn't do it, but
> just this once...
>
> And it isn't in any of the serious stuff I do in may day job either.
>
> You all know what a magic square is - a square where all the columns,
> rows, and diagonals add up to the same value.
>
> I'm messing about doing it for a cube. Wikipedia says you can't for
> small cubes.
>
> I have a square for the base, and a centre value, and therefore I can
> work out all the values for the top square as they are on diagonals
> with one of the bottom values and the centre one.
>
> I therefore have 3 nested loops: centre value, X and Y coordinates.
>
> And if I don't like the result I jump out of the X Y loops. Which is
> where I have that goto.

Breaking out of a nested loop is one legitimate use case for a goto.  An
alternative is to separate the inner loop into another function and use
return rather than goto.  That might not be practical.  And it's always
*possible* to write without gotos (there's a theorem to that effect),
but sometimes at the cost of making the code more difficult to read.

As I wrote here:
https://softwareengineering.stackexchange.com/a/133523/33478

    The main use of a goto in a reasonably modern language (one that
    supports if/else and loops) is to simulate a control flow construct
    that's missing from the language.

I'd like to see an extended "break" (and "continue") that refers to the
name of the loop to be broken -- note: not the code location to which it
jumps, but the name of the construct that's being affected.  A number
of other languages have this kind of named break (Ada, Perl, etc.).

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

[toc] | [prev] | [next] | [standalone]


#162392

FromThiago Adams <thiago.adams@gmail.com>
Date2021-08-15 15:56 -0700
Message-ID<c0350a6e-422a-47c4-aa97-a054b581c102n@googlegroups.com>
In reply to#162391
On Sunday, August 15, 2021 at 6:44:35 PM UTC-3, Keith Thompson wrote:
> Vir Campestris <vir.cam...@invalid.invalid> writes: 
> > I've been writing C, and more lately C++, since some time in the 1980s. 
> > 
> > I've just written a goto. I know it's evil, and I shouldn't do it, but 
> > just this once... 
> > 
> > And it isn't in any of the serious stuff I do in may day job either. 
> > 
> > You all know what a magic square is - a square where all the columns, 
> > rows, and diagonals add up to the same value. 
> > 
> > I'm messing about doing it for a cube. Wikipedia says you can't for 
> > small cubes. 
> > 
> > I have a square for the base, and a centre value, and therefore I can 
> > work out all the values for the top square as they are on diagonals 
> > with one of the bottom values and the centre one. 
> > 
> > I therefore have 3 nested loops: centre value, X and Y coordinates. 
> > 
> > And if I don't like the result I jump out of the X Y loops. Which is 
> > where I have that goto.
> Breaking out of a nested loop is one legitimate use case for a goto. An 
> alternative is to separate the inner loop into another function and use 
> return rather than goto. That might not be practical. And it's always 
> *possible* to write without gotos (there's a theorem to that effect), 
> but sometimes at the cost of making the code more difficult to read. 
> 
> As I wrote here: 
> https://softwareengineering.stackexchange.com/a/133523/33478 
> 
> The main use of a goto in a reasonably modern language (one that 
> supports if/else and loops) is to simulate a control flow construct 
> that's missing from the language. 
> 
> I'd like to see an extended "break" (and "continue") that refers to the 
> name of the loop to be broken -- note: not the code location to which it 
> jumps, but the name of the construct that's being affected. A number 
> of other languages have this kind of named break (Ada, Perl, etc.). 
>

I miss some jumps in C and I am using macros just to give gotos a more
structured meaning.

#define try  if (1)
#define catch else catch_label:
#define throw goto catch_label

try {
   if (error) throw;

  //success
} 
catch {
  //error situation
}

I don't like the names (try catch throw)  especially because they are already 
being used but I didn't find anything better. 
Something in the language would immediately fix and spread the idea.

This is the equivalent code:

if (1) {
   if (some error) goto error;
}
else error: {
}

This "if (1)" causes indignation on reviewers and the same
for "else error:". 

I am using this jumps and I am really happy with then, but they
cause these bad feelings on reviewers.

They made my code much less nested and the success path
much more linear and easy to review. As soon you get the idea.

The same pattern is used in many C samples, but they work
exiting the function for instance:

if (some error) {
  fprintf(stderr, "Error message.\n");
  exit(1);
}

or

if (some error) {
  fprintf(stderr, "Error message.\n");
  return 1;
}

The samples are simple. The problem with exit
is that we don't want to exit always, and the problem with 
return is that in many situations there are resources that must be free 
and the code using return becomes complicated and bad.

Using the try catch pattern above I release resources after catch.

Using this pattern I also miss some "success jump".  This happens when
we have a shortcut success path. For instance a simple case where the more
complicated steps can be ignored.

I am not using any macro for this, and I am not using this in my code
 but the idea was:


if (0)  success: {

}

if (0)  error: {

}

This create this small islands that can be used only if you jump inside.

There is some code in C that uses goto to jump to errors like this:

int foo(int bar)
{
    int return_value = 0;
    if (!do_something( bar )) {
        goto error_1;
    }
    if (!init_stuff( bar )) {
        goto error_2;
    }
    if (!prepare_stuff( bar )) {
        goto error_3;
    }
    return_value = do_the_thing( bar );
error_3:
    cleanup_3();
error_2:
    cleanup_2();
error_1:
    cleanup_1();
    return return_value;
}

I don't like it because we can read the error labels linearly but the same path 
is used for success. There is no clear separation.

This is the same code using the macros:

int foo(int bar)
{
    int return_value = 0;
   try {

    if (!do_something( bar )) {
        throw;
    }

    if (!init_stuff( bar )) {
      throw;
    } 
    if (!prepare_stuff( bar )) {
       throw;
    }
    return_value = do_the_thing( bar );
}
catch
{
}

cleanup_3();
cleanup_2();
cleanup_1();
return return_value;
}

Generally the cleanup is necessary for both success or error
and in some case if (do I have the resource?) clear()  is used.

[toc] | [prev] | [next] | [standalone]


#162395

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2021-08-16 01:50 +0100
Message-ID<87a6liw6v2.fsf@bsb.me.uk>
In reply to#162392
Thiago Adams <thiago.adams@gmail.com> writes:

> On Sunday, August 15, 2021 at 6:44:35 PM UTC-3, Keith Thompson wrote:
>> Vir Campestris <vir.cam...@invalid.invalid> writes: 
>> > I've been writing C, and more lately C++, since some time in the 1980s. 
>> > 
>> > I've just written a goto. I know it's evil, and I shouldn't do it, but 
>> > just this once... 
>> > 
>> > And it isn't in any of the serious stuff I do in may day job either. 
>> > 
>> > You all know what a magic square is - a square where all the columns, 
>> > rows, and diagonals add up to the same value. 
>> > 
>> > I'm messing about doing it for a cube. Wikipedia says you can't for 
>> > small cubes. 
>> > 
>> > I have a square for the base, and a centre value, and therefore I can 
>> > work out all the values for the top square as they are on diagonals 
>> > with one of the bottom values and the centre one. 
>> > 
>> > I therefore have 3 nested loops: centre value, X and Y coordinates. 
>> > 
>> > And if I don't like the result I jump out of the X Y loops. Which is 
>> > where I have that goto.
>> Breaking out of a nested loop is one legitimate use case for a goto. An 
>> alternative is to separate the inner loop into another function and use 
>> return rather than goto. That might not be practical. And it's always 
>> *possible* to write without gotos (there's a theorem to that effect), 
>> but sometimes at the cost of making the code more difficult to read. 
>> 
>> As I wrote here: 
>> https://softwareengineering.stackexchange.com/a/133523/33478 
>> 
>> The main use of a goto in a reasonably modern language (one that 
>> supports if/else and loops) is to simulate a control flow construct 
>> that's missing from the language. 
>> 
>> I'd like to see an extended "break" (and "continue") that refers to the 
>> name of the loop to be broken -- note: not the code location to which it 
>> jumps, but the name of the construct that's being affected. A number 
>> of other languages have this kind of named break (Ada, Perl, etc.). 
>>
>
> I miss some jumps in C and I am using macros just to give gotos a more
> structured meaning.
>
> #define try  if (1)
> #define catch else catch_label:
> #define throw goto catch_label
>
> try {
>    if (error) throw;
>
>   //success
> } 
> catch {
>   //error situation
> }

I don't think hiding a goto in a macro does anything to ameliorate the
potential problems.  It seems to me it's just going to make things
worse.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#162393

FromBart <bc@freeuk.com>
Date2021-08-16 00:18 +0100
Message-ID<sfc7co$vek$1@dont-email.me>
In reply to#162390
On 15/08/2021 22:14, Vir Campestris wrote:
> I've been writing C, and more lately C++, since some time in the 1980s.
> 
> I've just written a goto. I know it's evil, and I shouldn't do it, but 
> just this once...
> 
> And it isn't in any of the serious stuff I do in may day job either.
> 
> You all know what a magic square is - a square where all the columns, 
> rows, and diagonals add up to the same value.
> 
> I'm messing about doing it for a cube. Wikipedia says you can't for 
> small cubes.
> 
> I have a square for the base, and a centre value, and therefore I can 
> work out all the values for the top square as they are on diagonals with 
> one of the bottom values and the centre one.
> 
> I therefore have 3 nested loops: centre value, X and Y coordinates.
> 
> And if I don't like the result I jump out of the X Y loops. Which is 
> where I have that goto.

I can't believe you've never had a similar requirement in the last 
approx 35 years.

[toc] | [prev] | [next] | [standalone]


#162394

FromDFS <nospam@dfs.com>
Date2021-08-15 20:31 -0400
Message-ID<qliSI.22625$6p.5475@fx36.iad>
In reply to#162390
On 8/15/2021 5:14 PM, Vir Campestris wrote:
> I've been writing C, and more lately C++, since some time in the 1980s.
> 
> I've just written a goto. I know it's evil, and I shouldn't do it, but 
> just this once...

Once in 35 years?  Very evil...



> And it isn't in any of the serious stuff I do in may day job either.
> 
> You all know what a magic square is - a square where all the columns, 
> rows, and diagonals add up to the same value.
> 
> I'm messing about doing it for a cube. Wikipedia says you can't for 
> small cubes.
> 
> I have a square for the base, and a centre value, and therefore I can 
> work out all the values for the top square as they are on diagonals with 
> one of the bottom values and the centre one.
> 
> I therefore have 3 nested loops: centre value, X and Y coordinates.
> 
> And if I don't like the result I jump out of the X Y loops. Which is 
> where I have that goto.
> 
> Andy


I use goto's for menu-driven cli code, such as:

https://imgur.com/a/cQdvAeM

[toc] | [prev] | [next] | [standalone]


#162396

FromDavid Brown <david.brown@hesbynett.no>
Date2021-08-16 08:20 +0200
Message-ID<sfd02h$an9$1@dont-email.me>
In reply to#162390
On 15/08/2021 23:14, Vir Campestris wrote:
> I've been writing C, and more lately C++, since some time in the 1980s.
> 
> I've just written a goto. I know it's evil, and I shouldn't do it, but
> just this once...
> 

You've been to confession.  Now say 10 Hail Dijkstra's, take a sip of
the holy jolt cola, and don't do it again!

:-)


(Magic cubes sounds fun - it's off-topic here, but I for one would be
curious to hear if you find one.)

[toc] | [prev] | [next] | [standalone]


#162397

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-08-15 23:21 -0700
Message-ID<sfd053$109v$2@gioia.aioe.org>
In reply to#162396
On 8/15/2021 11:20 PM, David Brown wrote:
> On 15/08/2021 23:14, Vir Campestris wrote:
>> I've been writing C, and more lately C++, since some time in the 1980s.
>>
>> I've just written a goto. I know it's evil, and I shouldn't do it, but
>> just this once...
>>
> 
> You've been to confession.  Now say 10 Hail Dijkstra's, take a sip of
> the holy jolt cola, and don't do it again!
> 
> :-)

Amen! :^D


> 
> 
> (Magic cubes sounds fun - it's off-topic here, but I for one would be
> curious to hear if you find one.)
> 

[toc] | [prev] | [next] | [standalone]


#162412

FromVir Campestris <vir.campestris@invalid.invalid>
Date2021-08-17 21:43 +0100
Message-ID<sfh710$s8j$3@dont-email.me>
In reply to#162396
On 16/08/2021 07:20, David Brown wrote:
> (Magic cubes sounds fun - it's off-topic here, but I for one would be
> curious to hear if you find one.)

Not within my parameters: a 3x3 cube must contain the numbers 1 to 27, 
and all the rows, columns, diagonals add up to 42.

(I did a double take when I realised it was 42!)

I ran an exhaustive search, and failed to find any before I'd even 
written all the rules it needed to obey.

Andy

[toc] | [prev] | [next] | [standalone]


#162398

FromMark Bluemel <mark.bluemel@gmail.com>
Date2021-08-16 00:32 -0700
Message-ID<f5f0f455-3d5a-423b-8624-056999529dc6n@googlegroups.com>
In reply to#162390
On Sunday, 15 August 2021 at 22:14:48 UTC+1, Vir Campestris wrote:
> I've been writing C, and more lately C++, since some time in the 1980s. 
> 
> I've just written a goto. I know it's evil, and I shouldn't do it, but 
> just this once... 
> 
> And it isn't in any of the serious stuff I do in may day job either. 
> 
> You all know what a magic square is - a square where all the columns, 
> rows, and diagonals add up to the same value. 
> 
> I'm messing about doing it for a cube. Wikipedia says you can't for 
> small cubes. 
> 
> I have a square for the base, and a centre value, and therefore I can 
> work out all the values for the top square as they are on diagonals with 
> one of the bottom values and the centre one. 
> 
> I therefore have 3 nested loops: centre value, X and Y coordinates. 
> 
> And if I don't like the result I jump out of the X Y loops. Which is 
> where I have that goto. 

I gave up "goto" in the late 1970s, when I was programming in COBOL. Our in-house coding standards had Section and Paragraph names which reflected depth in the call hierarchy - paragraphs could have names like C-100, CA-100, CBA-100. The risk of typos ("GO TO CA-100" when you meant "GO TO CAA-100") and the general inelegance of it all led me to give up on "GO TO". If you can manage without "GO TO" in COBOL, doing so in other languages should be fairly natural. I currently program mainly in Java which doesn't even have a "goto", but does have labelled loops.

In the absence of labelled loops, to allow for "break <loopName>;" Andy's seems the appropriate approach.

Other trivia: the supplemental notes that my university Maths department produced for the ALGOL manual included a paragraph which read something like "Any references to GOTO (an obscure Japanese admiral) are obscene, unfit for your eyes and anyway don't mean whatever you think they mean. Please ignore all such references." !

[toc] | [prev] | [next] | [standalone]


#162402

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2021-08-16 14:21 +0100
Message-ID<87y291v83n.fsf@bsb.me.uk>
In reply to#162398
Mark Bluemel <mark.bluemel@gmail.com> writes:

> On Sunday, 15 August 2021 at 22:14:48 UTC+1, Vir Campestris wrote:

>> I therefore have 3 nested loops: centre value, X and Y coordinates. 
>> 
>> And if I don't like the result I jump out of the X Y loops. Which is 
>> where I have that goto. 
>
> I gave up "goto" in the late 1970s, when I was programming in
> COBOL. Our in-house coding standards had Section and Paragraph names
> which reflected depth in the call hierarchy - paragraphs could have
> names like C-100, CA-100, CBA-100. The risk of typos ("GO TO CA-100"
> when you meant "GO TO CAA-100") and the general inelegance of it all
> led me to give up on "GO TO".

Grim.  I, too, last used a GOTO in the late 70s when my job was fixing
bugs in FORTRAN code, mostly written by science subject specialists in
the course of their research.  By the time I saw the code it was usually
hundreds of lines (well, cards) or tangled loops.  Every GOTO had
probably seemed like a good idea at the time, but the cumulative effect
resulted in a program that even he author could not understand.  It put
me off for life.

Dijkstra was writing in the era.  Had the worst abuse of a GOTO been a
jump to a common exit block in a function or breaking out of a nested
loop, I doubt we'd have the polemic we now have.  I'd prefer cleaner
language construction such as named loops (for break), final blocks in
functions and, maybe, co-routines or generators for the few other very
rare use cases.

That said, I've still never had to use one.  I use the fact that I want
one to prompt me to think if I've got the code wrong and, so far, I
always decide I have.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#162404

FromBart <bc@freeuk.com>
Date2021-08-16 17:48 +0100
Message-ID<sfe4sk$7jm$1@dont-email.me>
In reply to#162402
On 16/08/2021 14:21, Ben Bacarisse wrote:
> Mark Bluemel <mark.bluemel@gmail.com> writes:
> 
>> On Sunday, 15 August 2021 at 22:14:48 UTC+1, Vir Campestris wrote:
> 
>>> I therefore have 3 nested loops: centre value, X and Y coordinates.
>>>
>>> And if I don't like the result I jump out of the X Y loops. Which is
>>> where I have that goto.
>>
>> I gave up "goto" in the late 1970s, when I was programming in
>> COBOL. Our in-house coding standards had Section and Paragraph names
>> which reflected depth in the call hierarchy - paragraphs could have
>> names like C-100, CA-100, CBA-100. The risk of typos ("GO TO CA-100"
>> when you meant "GO TO CAA-100") and the general inelegance of it all
>> led me to give up on "GO TO".
> 
> Grim.  I, too, last used a GOTO in the late 70s when my job was fixing
> bugs in FORTRAN code, mostly written by science subject specialists in
> the course of their research.  By the time I saw the code it was usually
> hundreds of lines (well, cards) or tangled loops.  Every GOTO had
> probably seemed like a good idea at the time, but the cumulative effect
> resulted in a program that even he author could not understand.  It put
> me off for life.
> 
> Dijkstra was writing in the era.  Had the worst abuse of a GOTO been a
> jump to a common exit block in a function or breaking out of a nested
> loop, I doubt we'd have the polemic we now have.  I'd prefer cleaner
> language construction such as named loops (for break), final blocks in
> functions and, maybe, co-routines or generators for the few other very
> rare use cases.
> 
> That said, I've still never had to use one.  I use the fact that I want
> one to prompt me to think if I've got the code wrong and, so far, I
> always decide I have.

I also used to write Fortran (IV). You necessarily had to use gotos, but 
it didn't put me off them at all. I accepted that the languages I used 
later had better structured statements so most of the need for them in 
Fortran disappeard.

But I still used them /as needed/.

At present, I use them heavily in C source which has been generated from 
linear bytecode, where program structure is only represented with 
branches. Hence, the matching C code uses lots of gotos too. However no 
one needs to ever see that code.

What is important is that the language allows it. Many languages now 
don't have it, which means they are considerably more difficult to use 
from code generators.

[toc] | [prev] | [next] | [standalone]


#162645

FromTim Rentsch <tr.17687@z991.linuxsc.com>
Date2021-09-06 06:30 -0700
Message-ID<86lf49vnkj.fsf@linuxsc.com>
In reply to#162402
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> [report of early bad experiences with GOTO.]  It put me off for life.
>
> [...]
>
> That said, I've still never had to use one.  I use the fact that I
> want one to prompt me to think if I've got the code wrong and, so
> far, I always decide I have.

I have a different approach.  I learned early on to write code
without considering even the possibility of using goto.  So when
I write code now (and for the last more than 40 years), 'goto'
just isn't in the vocabulary.  Only after having written a full
implementation (of a function or perhaps set of functions), if
the code looks clunky for some reason do I go back (no pun
intended) and explore less orthodox alternatives, including the
possibility of using 'goto'.  It does happen from time to time
that using 'goto' gives a better result along some axes in the
space of possible tradeoffs.  How often?  Rarely.  Somewhere
between once a year and once per decade, if I had to guess.  It's
always a judgment call as to which tradeoffs give the best result
overall.

Incidentally, I put 'switch', and to a lesser extent 'if', in
almost the same category as 'goto'.  Unrestrained use of 'if'
or 'switch' is almost as bad as unrestrained use of 'goto'.

[toc] | [prev] | [next] | [standalone]


#162648

FromDavid Brown <david.brown@hesbynett.no>
Date2021-09-06 18:04 +0200
Message-ID<sh5e6t$4t2$1@dont-email.me>
In reply to#162645
On 06/09/2021 15:30, Tim Rentsch wrote:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> 
>> [report of early bad experiences with GOTO.]  It put me off for life.
>>
>> [...]
>>
>> That said, I've still never had to use one.  I use the fact that I
>> want one to prompt me to think if I've got the code wrong and, so
>> far, I always decide I have.
> 
> I have a different approach.  I learned early on to write code
> without considering even the possibility of using goto.  So when
> I write code now (and for the last more than 40 years), 'goto'
> just isn't in the vocabulary.  Only after having written a full
> implementation (of a function or perhaps set of functions), if
> the code looks clunky for some reason do I go back (no pun
> intended) and explore less orthodox alternatives, including the
> possibility of using 'goto'.  It does happen from time to time
> that using 'goto' gives a better result along some axes in the
> space of possible tradeoffs.  How often?  Rarely.  Somewhere
> between once a year and once per decade, if I had to guess.  It's
> always a judgment call as to which tradeoffs give the best result
> overall.
> 
> Incidentally, I put 'switch', and to a lesser extent 'if', in
> almost the same category as 'goto'.  Unrestrained use of 'if'
> or 'switch' is almost as bad as unrestrained use of 'goto'.
> 

Do you /like/ programming in C?  Your style is, I would say, more
idiomatic for functional programming than for imperative programming.

(Of course one can always say "unrestrained use of X is bad", for any
feature X in any language.)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web