Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: on goto

Reply
Thread Tools

Re: on goto

 
 
Lie Ryan
Guest
Posts: n/a
 
      05-13-2010
On 05/14/10 01:34, Richard Heathfield wrote:
> In <(E-Mail Removed)>, Willem wrote:
>
>> Richard Heathfield wrote:

>
> <snip>
>> )
>> ) Personally, I find the SESE (right-hand) version to be visually
>> simpler.
>>
>> In the SESE version, it is not obvious that the function ends
>> immediately when a point has been found.

>
> To me, though, it /is/ obvious. Funny how different people see things
> in different ways.


To me, it is not obvious because the function ends when the exit flag is
set not when the point is found.
 
Reply With Quote
 
 
 
 
Pascal J. Bourguignon
Guest
Posts: n/a
 
      05-14-2010
"Daniel T." <(E-Mail Removed)> writes:

> Richard Heathfield <(E-Mail Removed)> wrote:
>> Nick Keighley wrote:

>
>> > Your code compiles and runs and gives the same answers for both
>> > functions.
>> >
>> > But it still says they both have a complexity of 5
>> > Ah, but the graphs look much more similar. Near identical.
>> > Pictures on their way

>>
>> And now they're on the Web. Please note that, as the URL suggests...
>>
>> <http://www.cpax.org.uk/scratch/seseseme.php>
>>
>> ...I'm liable to reclaim that scratch space at any time. (In practice,
>> I'll probably be too lazy, though, so the link should be good for a
>> little while yet.)
>>
>> Personally, I find the SESE (right-hand) version to be visually simpler.

>
> Something interesting that I've noticed over the years. In every
> debugger I've used (maybe 5 in all,) when I'm stepping through the code
> and the code point hits a return statement, the next step doesn't exit
> the function, instead it jumps to the close brace that ends the
> function. By that light, all functions are SESE even if you put multiple
> returns in them.


That's because there's a non trivial epilog that must be executed
therefore the compiler translates the returns into jumps to the epilog
instead of a single RTN instruction.

However, you could probably play with optimization options and have the
compiler generate several returns. (Notably, disabling the frames for
functions who don't need them).


--
__Pascal Bourguignon__
 
Reply With Quote
 
 
 
 
Phil Carmody
Guest
Posts: n/a
 
      05-14-2010
Richard Heathfield <(E-Mail Removed)> writes:
> Nick Keighley wrote:
> <snip>
>> Your code compiles and runs and gives the same answers for both
>> functions.
>>
>> But it still says they both have a complexity of 5
>> Ah, but the graphs look much more similar. Near identical.
>> Pictures on their way

>
> And now they're on the Web. Please note that, as the URL suggests...
>
> <http://www.cpax.org.uk/scratch/seseseme.php>


Hmmm, have you dammed your server?

Phil
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1
 
Reply With Quote
 
Tim Rentsch
Guest
Posts: n/a
 
      06-17-2010
James Dow Allen <(E-Mail Removed)> writes:

> [comments on another subthread snipped]
>
> The thread title is "Goto" but break, inside return, and
> switch fallthrough suffer, to smaller extent, the same sin as
> goto. We read


Note that the paragraph below is from a posting specifically
discussing goto -- not break, inside return, or switch fallthrough.

> On Apr 29, 3:20 pm, Tim Rentsch <(E-Mail Removed)> wrote:
>> Keith H Duggar <(E-Mail Removed)> writes:
>> > Subsequently I discussed that flame war with one of the worlds
>> > genius compiler writers who confirmed the necessity of the inlining
>> > etc controls explained above. However, he also added that in his
>> > experience it is pointless to argue with the anti-goto mob because
>> > it is a religion that ignores all inconvenient empirical evidence.

>> .
>> Essentially the same thing could be said of the pro-goto mob.

>
> Wrong.


We hear the sound of a mob voice.

> The anti-goto mob claims to prefer code that
> is clearly more complex (is Nathan's the best you have?
> Did you ever post your solution, Mr. H?) in order to avoid the
> inside return (or goto).


One way of telling that comments are coming from someone in a mob
(either pro- or anti-) is an insistence on inherently subjective
statements as being absolutely true. (Another way is attributing
irrational behavior to one of the mobs but not their opposite.
Both are mobs.) The phrase "clearly more complex" is an inherently
subjective judgment; different people can and will judge it
differently.

> None of us are "pro-goto" per se;


Your actions belie your words, sir.

> we're
> just asking to *look at all the code and make the best trade-offs*,
> or select the "least of evils."


No there is more: a refusal to accept others' cost functions
for different aspects of a tradeoff, and (often implicitly) an
insistence that others accept the cost functions the mob member
thinks are "right".

> It's usually better to introduce
> 1 or 2 boolean variables than to write goto, but what if it's 3
> variables and you still need a break? What if by using switch
> case-fallthrough's you save the need for 5 little functions?


Which is 'better' depends on what cost functions one chooses to
adopt. Different development teams choose different sets of
cost functions, and there's nothing wrong with that, since the
judgments involved are inherently subjective.

> There is no "universal demerit system" for code complications,
> but to assign inside-return a cost of infinity seems much
> too aggressive.


Just because it contradicts your sense of proprieties doesn't
make it an inappropriate choice for a cost function. Different
people can choose whatever cost functions they wish, as long as
they don't insist that other people must use the same cost
functions that they do.

And again, for the record, the earlier posting being responded
to was about /goto/, not /inside-return/. If you want to lump
these together in your head, that's up to you, but don't insist
that everyone else share that view.
 
Reply With Quote
 
Tim Rentsch
Guest
Posts: n/a
 
      06-17-2010
Richard Heathfield <(E-Mail Removed)> writes:

> Nick Keighley wrote:
>> On 11 May, 06:26, Richard Heathfield <(E-Mail Removed)> wrote:
>>
>>> My preference for SESE is rooted in some truly appalling SEME
>>> code that I've had to maintain in the past.

>>
>> but MEME is even *more* fun. But that needs a truly awesome assemly
>> programmer.

>
> Well, no - but I think it does at least require a goto.


It doesn't, of course, in C.
 
Reply With Quote
 
Tim Rentsch
Guest
Posts: n/a
 
      06-17-2010
Phil Carmody <(E-Mail Removed)> writes:

> Richard Heathfield <(E-Mail Removed)> writes:
>> Phil Carmody wrote:
>>> Richard Heathfield <(E-Mail Removed)> writes:
>>>> Willem wrote:
>>>>> Let's take your example to make my point:
>>>>> Richard Heathfield wrote:
>>>>> ) found = 0;
>>>>> ) for(x = 0; !found && x < xlim; x++)
>>>
>>>> No, the benefit of SESE is that you know that every loop has a single
>>>> entry point and a single exit point.
>>>
>>> It can exit after !found fails, or after x < xlim fails.

>>
>> Nice try. They are, however, effectively the same exit point.

>
> I disagree - there's a sequence point separating them.


It seems reasonable to consider this expression as a
single exit point since neither side of the '&&' has
any side-effects. That there is a sequence point is
just an artifact of how C is defined; it's still a
single controlling expression with no side-effects.
 
Reply With Quote
 
Willem
Guest
Posts: n/a
 
      06-17-2010
Tim Rentsch wrote:
) It seems reasonable to consider this expression as a
) single exit point since neither side of the '&&' has
) any side-effects. That there is a sequence point is
) just an artifact of how C is defined; it's still a
) single controlling expression with no side-effects.

It seems equally reasonable to consider that there are
still two ways the loop can end, that these two ways are
still caused in different places inside the loop, and that
the difference is a small technicality.

Situation 1:
- The loop can either exit when it reaches the end of the count,
or when 'break' is used somewhere inside the loop.

Situation 2:
- The loop can either exit when it reaches the end of the count,
or when 'found' becomes true somewhere inside the loop.

I find the difference underwhelming.

Furthermore, 'break' is a keyword, and will be the same in all the loops,
whereas 'found' is arbitrary and could be used a number of ways.


PS:

Situation 3:
- The loop exits when it reaches the end of the count,
but you should beware that the counter can be changed
inside the loop as well to force an exit.

That last one is the worst of two worlds; in situation 2, at least,
it is plainly obvious that there is a second exit condition.


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
 
Reply With Quote
 
Tim Rentsch
Guest
Posts: n/a
 
      06-20-2010
Willem <(E-Mail Removed)> writes:

> Tim Rentsch wrote:
> ) It seems reasonable to consider this expression as a
> ) single exit point since neither side of the '&&' has
> ) any side-effects. That there is a sequence point is
> ) just an artifact of how C is defined; it's still a
> ) single controlling expression with no side-effects.
>
> It seems equally reasonable to consider that there are
> still two ways the loop can end,


Yes, there are two ways the loop can end just like the
condition 'x*y != 0' can fail if either x==0 or y==0.
But it's still only one point of exit, in that there
is no imperative code between the "two" conditions.

> that these two ways are
> still caused in different places inside the loop, and that
> the difference is a small technicality.


It's true that 'while( x < y )' can exit because of
changes to either 'x' or 'y'. If these variables
have 32 bits, in some sense there are 64 different
"things" that could affect the exit condition.
It's still only one exit point.

So I guess I might say I agree that there's some sort
of difference, but that difference has nothing to do
with what I was talking about.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VHDL Goto statement ? Skybuck Flying VHDL 9 08-26-2005 01:46 PM
Re: VHDL Goto statement ? Skybuck Flying VHDL 0 08-08-2005 03:21 AM
where does Console.WriteLine() goto in a web app? Flip ASP .Net 1 04-14-2005 08:01 PM
where does Console.WriteLine() goto? Flip ASP .Net 6 11-18-2004 06:05 PM
goto statement is recommened in systemc? youngsun park VHDL 2 11-18-2003 03:47 PM



Advertisments