mersenneforum.org  

Go Back   mersenneforum.org > Factoring Projects > Msieve

Reply
 
Thread Tools
Old 2009-04-06, 08:38   #12
xilman
Bamboozled!
 
xilman's Avatar
 
"π’‰Ίπ’ŒŒπ’‡·π’†·π’€­"
May 2003
Down not across

10,753 Posts
Default

Quote:
Originally Posted by rogue View Post
Personally I'm not a fan of "goto"s in C code. IMO, well-designed code shouldn't need them. Where I work there is a project that requires all functions to have a single exit point, thus gotos are required to make that happen, but the only reason for the single exit point is a trace statement before returning. IMO, it should be quite acceptable to use return from within a function to reduce the need for unnecessary if statements.
I consider goto's harmful and should never be used under any circumstances. The are clearly unnecessary and serve only to hide the structure of a well-designed program. Consider the clarity of the following demonstration code which uses only control constructs from sound structured programing techniques --- a switch() and a while().

Code:
#include <stdio.h>

void hello (char *s)
{
  int i = 42;
  char c;

  while (1)
    {
      switch (i)
	{
	case 7:
	  putchar ('\n');
	  i = 93;
	  break;
	case 0:
	  putchar (c);
	  i = 5;
	  break;
	case 42:
	  c = *s;
	  i = 19;
	  break;
	default:
	  s++;
	  i = 42;
	  break;
	case 93:
	  return;
	case 19:
	  i = (c == 0) * 7;
	}
    }
}

main ()
{
  hello ("Hello world");
}

Paul
xilman is offline   Reply With Quote
Old 2009-04-06, 13:28   #13
rogue
 
rogue's Avatar
 
"Mark"
Apr 2003
Between here and the

11·577 Posts
Default

Quote:
Originally Posted by xilman View Post
I consider goto's harmful and should never be used under any circumstances. The are clearly unnecessary and serve only to hide the structure of a well-designed program. Consider the clarity of the following demonstration code which uses only control constructs from sound structured programing techniques --- a switch() and a while().
Paul
You're a little late for April Fool's Day, or am I missing your point?
rogue is offline   Reply With Quote
Old 2009-04-06, 15:15   #14
Brian Gladman
 
Brian Gladman's Avatar
 
May 2008
Worcester, United Kingdom

21416 Posts
Default

Quote:
Originally Posted by rogue View Post
You're a little late for April Fool's Day, or am I missing your point?
Unless I am mistaken, Paul is gently pointing out that the use of structured programming constructs is no more a guarantee of good code any more than the use of goto's is a guarantee of bad code.

The real issue here is not to avoid 'break' or 'goto' clauses but rather to avoid their inappropriate use.

The use of break clauses to achieve early exits from loops is often appropriate - so much so that some high level languages have a specific construct to achieve this.

Brian Gladman

PS to Paul - I was about to disagree with you until I actually read your piece of code :-)

Last fiddled with by Brian Gladman on 2009-04-06 at 15:18
Brian Gladman is offline   Reply With Quote
Old 2009-04-06, 19:45   #15
xilman
Bamboozled!
 
xilman's Avatar
 
"π’‰Ίπ’ŒŒπ’‡·π’†·π’€­"
May 2003
Down not across

10,753 Posts
Default

Quote:
Originally Posted by rogue View Post
You're a little late for April Fool's Day, or am I missing your point?
Yes, you are missing my point, probably because you need to get your irony detector serviced.

Paul
xilman is offline   Reply With Quote
Old 2009-04-06, 21:44   #16
tmorrow
 
tmorrow's Avatar
 
Jan 2004

10310 Posts
Default

And here I was thinking Paul's "Hello World" was a beautifully elegant, transparent, tight, high performance implementation, exhibiting supreme mastery of the language. Damn!
tmorrow is offline   Reply With Quote
Old 2009-04-06, 22:03   #17
xilman
Bamboozled!
 
xilman's Avatar
 
"π’‰Ίπ’ŒŒπ’‡·π’†·π’€­"
May 2003
Down not across

10,753 Posts
Default

Quote:
Originally Posted by tmorrow View Post
And here I was thinking Paul's "Hello World" was a beautifully elegant, transparent, tight, high performance implementation, exhibiting supreme mastery of the language. Damn!
But it is! Well, elegant and transparent, at least, though perhaps not optimized for performance.

In particular, it's a clear and simple example of the concept of Turing eqivalence -- in particular, of how to implement GOTO in a Turing-complete language which lacks an explicit representation of that concept. I even demonstrated how to implement a computed GOTO though that was, I confess, showing off.


Paul
xilman is offline   Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ivy Bridge Thread Dubslow Hardware 70 2012-05-25 00:56
Bad Poetry Thread Passionflower2 Lounge 26 2012-01-25 04:35
PRP discussion thread philmoore Five or Bust - The Dual Sierpinski Problem 83 2010-09-25 10:20
If a p-1 thread is unStickied, does it mean it's done? jasong Marin's Mersenne-aries 2 2006-10-08 02:07
Deutscher Thread (german thread) TauCeti NFSNET Discussion 0 2003-12-11 22:12

All times are UTC. The time now is 01:06.


Sat Jul 17 01:06:35 UTC 2021 up 49 days, 22:53, 1 user, load averages: 2.26, 1.93, 1.61

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.