|
Has anyone used the language INTERCAL? It doesn't have a
GOTO but a COME FROM instead.
|
|
|
|
|
I think I've used goto only once or twice in my C/C++ programs. The one time I found it really useful was to execute cleanup-and-exit code that needed to be called from different places inside a large function. Since this function was going to be called many times and it wasn't dealing with exceptions at all, I felt it would be better to avoid the unnecessary overhead of exception handling and make the function as efficient as possible.
Still, I can think of a handy way to use goto to piss off a code reviewer (if such an animal still exists):
void ReviewThis()
{
if (YouDontLikeMyCode())
goto Hell;
Hell:
SayHelloToTheFamily();
EnjoyTheClimate();
}
Cheers!
Alvaro
|
|
|
|
|
Umm, you clearly missed the point..
"Go to page number..."
|
|
|
|
|
Of course, all emotionally mature and experienced programers know that the "goto" statement is just another tool - it can be misused (and frequently is), but is occassionally useful.
What I'm always amazed at is the misuse of the term in other contexts; for example, in menus, in documentation, in sentences ("tonight I will goto the movies", "Goto the Whatever Website"), etc.
Anytime I see it used in a menu - can't think of an example offhand - I'm embarassed for my profession.
|
|
|
|
|
I've read the articles on this poll, and to be honoust; I'm shocked
If someone would ever ask me to describe a good developer, one of the first things I would say is "A real developer doesn't use the keyword 'goto'."
Are you all developing BASIC? I'm almost embarrassed
|
|
|
|
|
Do you use 'break', or 'continue'? They are just 'goto' with a less clearly visible endpoint.
Whilst I agree that goto should be avoided, 'goto'-like functionality is in constant use, and it should be understood what the implications - both pro and con - might be, whenever you use such syntax.
Matthew Adams
Development Manager
Digital Healthcare Ltd
|
|
|
|
|
I agree that break and continue should be avoided, but I disagree that they have a "less clearly visible endpoint." Their logic is inherent. ie, whenever I see break, I know the programmer wants to abort a loop prematurely. When I see continue, I know that he's done all he wants during this iteration. But when I see goto, it could mean any number of things, and my only clue is the name of the label. Break and continue have a defined logic: goto does not.
|
|
|
|
|
If I have the code:
switch( cmd )
{
case 'p':
doprint();
break;
case 'n': case 'N':
donew();
}
according to the theory 'break' and 'continue' should be avoided:
switch( cmd )
{
case 'p':
doprint();
// oops! this is a locical error
case 'n': case 'N':
donew();
}
-rhd-
|
|
|
|
|
My e-mail is wrong: mailto:rhd_@hotmail.com
-rhd-
|
|
|
|
|
Well - no
Of course, in a switch statement, there is a very specific syntactic reason to use break - you need it to end the case clause.
However, in a piece of looping logic, break is exactly equivalent to a goto, without a naively transparent end-point.
On the case/break pair, C# has an interesting approach - you can't just drop through to the next 'case' - you must terminate the clause. However, you can use 'goto' to achieve the same functionality, but without the implicit dangers.
Matthew Adams
Development Manager
Digital Healthcare Ltd
|
|
|
|
|
I never use 'break' or 'continue' as well. And I even try to avoid 'switch'-'case'- statements, which are (in my opinion) just as bad.. although, in a lot of cases, 'switch'-'case'- statements is the less-ugly option you might have.
Just curious; What sort of applications does "Digital Healthcare" develop?
|
|
|
|
|
Hi. We develop information/image management solutions for worldwide healthcare markets. Currently, our major product focus is on Clinical Ophthalmology, Optometry and Diabetes care. In addition to the supply of HW/SW, we can outsource the management of the whole project lifecycle, and support several major OEM vendors, such as Canon USA and ProLaser.
Matthew Adams
Development Manager
Digital Healthcare Ltd
|
|
|
|
|
What exactly is a "Good Programmer/Real Developer"? If the main criteria is the fact that any programmer who uses a goto is not a "real programmer" then I hope you're not trying to hire or more likely teach "real developers" (since this seems to come down from the almighties in the academic community). I agree that goto can be misused and is often avoidable given exception handling; however I would argue that gotos, if used properly, can be used effectively for program performance and readability/clarity.
It seems the biggest argument against goto's is it is difficult to maintain and read a program with gotos. I have seen very poor code with gotos, without gotos, and code that went to great lengths to avoid gotos (infinite while loops with breaks, layers and layers of if-then nesting, etc). I don't think the goto was the problem - I think it was the programmer and lack of discipline. It takes discipline and awareness to write good reliable code. Limiting your programming options and not understanding the constructs available to you does not help. If we threw out every construct that could be abused, none of us would be programming.
|
|
|
|
|
I just hope that no one ever looks at the machine that a compiler produces. I suppose you are right even that doesn't use a goto command. Most assemblers tend to call it 'Jump'.
There are times, when time critical real time applications necessitate that jumps/gotos be used because of a machine cycle count that is required, and it has nothing to with whether one is a good or indifferent programmer.
Horses for courses.
I was always taught 'NEVER EVER WRITE SELF MODIFYING CODE', but there was project I was on, if hadn't broken that golden rule the code would never have fit into the ROM. As it turned out it need hand optimization and we finished with 3 unused bytes. YES 3, and heaps of jumps.
Happy programming!!
|
|
|
|
|
Ya! You can use it for telling the cab driver! heeheehee!
|
|
|
|
|
Here's a common situation that a goto works well and makes the code very easy to read/understand. I generally return 0 for success and <>0 for errors. The functions typically do not throw exceptions (They protect themselves - it localizes the throw/catch and returns the appropriate error code if necessary)
Without the goto the cleanup becomes messy or more difficult to read/follow with alot of if/then nesting. Especially if you are allocating multiple blocks of memory/handles.
I can't see this code being re-written a "better" without the use of a goto.
**********
#define __NOERR 0
#define JUMP_ON_ERR( eRc, label ) if( eRc != __NOERR) goto label
ERRCODE MMFunction( LPCTSTR pszFile, ... )
{
HANDLE hFile = NULL;
ERRCODE eRc = __NOERR;
//
// Open the file (may be serial port or memory or located across the network)
// Reads and Writes may actually fail
eRc = MMOpenFile( pszFile, &hFile );
JUMP_ON_ERR( eRc, problems );
//
// Read info from the file/port
eRc = MMFileRead( hFile, ... );
JUMP_ON_ERR( eRc, problems );
//
// Write info to the file/port
eRc = MMFileWrite( hFile, ... );
JUMP_ON_ERR( eRc, problems );
//
// Read info from the file/port
eRc = MMFileRead( hFile, ... );
JUMP_ON_ERR( eRc, problems );
problems:
//
// if the file was successfully opened, close it
if( hFile != NULL )
{
MMCloseFile( hFile );
}
return( eRc );
}
|
|
|
|
|
A textbook motive for exception handling if i've ever seen it.
In some cases like this (not this one, really) break statements may be helpful.
The problem is, you can't break out of arbitrary {} blocks, so with your example, you'd have to...
.
.
.
do
{
eRc = func1();
if (eRc!=__NOERR) break;
eRc = func2();
if (eRc!=__NOERR) break;
}
while(0);
docleanup();
return eRc;
}
but the odd do..while may be too ugly to justify this method. Perhaps..
#define START_BREAKABLE do
#define END_BREAKABLE while(0);
but that might be just as bad. My point is that in many similar situations you can use breaks instead, and while still not entirely elegant, to me they are easier to follow and visualize than a goto.
|
|
|
|
|
this is a sorry example of bad old C. exceptions are called for in this case.
|
|
|
|
|
Please show how you would use exception handling for this particular situation.
|
|
|
|
|
I dont think I'm asking for much, I'd just like to see a *good* all encompassing registry class.
-Ben
"My mind tends to wander, but being a small mind, it never wanders very far." - Dave Marinaccio [All I really need to know I learnt from watching Star Trek.]
|
|
|
|
|
I have never used goto in my life other than with jsr
However, I have seen them in so many samples of MSDN.
I think , Goto is a cheap Duct tape fix.
And would not want to be caught dead using them.
Neither my boss would allow it nor will I allow my team to use it.;P
Cheers
|
|
|
|
|
I have never found myself in a situation where I was forced to use a goto. Used indiscriminantly they certainly lead to snarled up code but you shouldn't have to use them so why is this still an issue?
|
|
|
|
|
.. Ever tried VB 'error handling' without it?
ATL Student
|
|
|
|
|
goto is a hack. VB is a scripting language, which is a euphamism for a hacking language.
no paradox.
real languages use throw and catch.
|
|
|
|
|
Bwhaahaahahahaa !!
Um.... is this person trolling to make *my* point ? ( VB sucks )
I can't imagine choosing to use a language that does not support inheritance, for starters, and agree with the other person who posted on this thread ( in fact this has been discussed below as well in relation to goto vs. try/catch/throw )
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|