From: Alexei A. Frounze on 25 Apr 2010 05:20 On Apr 24, 5:18 pm, "Rod Pemberton" <do_not_h...(a)havenone.cmm> wrote: .... > used. But, from a different perspective, BASIC or C, GOTO's cause problems. > They are unstructured. That means that a GOTO can branch out of one loop > and into another, intentionally or accidentally. Since most loops have a > loop variable or counter, this causes problems with a misplaced GOTO. The > jumped into loop may not terminate correctly. We can misplace and incorrectly reorder many things, not just goto's. If you restrict the use of goto in C/C++ to several simple patterns and write your code carefully, goto's aren't really a problem. Alex
From: Alexei A. Frounze on 25 Apr 2010 05:49 On Apr 24, 5:18 pm, "Rod Pemberton" <do_not_h...(a)havenone.cmm> wrote: > It seems you stirred up the comp.lang.c, comp.lang.c++, crowds... I've > removed them from this post. I'm not interested in hearing from them that > my experience and knowledge is wrong. Stay away from purists and idealists, they are far too often too strict and offer impractical advice. :) I too have been bitten by those folks. That's not to say I didn't learn anything from the experience -- I spent quite some time figuring out proper C as per its standard and started coding more portably and defensively (but that's a totally different story). Alex
From: Nick Keighley on 25 Apr 2010 05:50 On 24 Apr, 16:48, "Leigh Johnston" <le...(a)i42.co.uk> wrote: > "Daniel T." <danie...(a)earthlink.net> wrote in message > > news:daniel_t-DBCC13.11141024042010(a)70-3-168-216.pools.spcsdns.net... > > > Ali Karaali <ali...(a)gmail.com> wrote: > > >> I use goto to break nested for loops and I can't see a > >> reason to ban goto. > > > I'll give you a reason to ban goto. This is a line of BASIC code: > > > 90 x = 5 > > > Now, I ask you, where is the line that was previously executed? Is it > > directly above line 90, is it directly below it, or could it be anywhere > > in the program? Because of the goto statement, simply because an > > unstructured "goto" is possible in the language, you have to analyze the > > entire program to know the answer. If we ban the use of "goto", we can > > confidently know exactly what line of code comes before line 90. > > This channel is about C++ not BASIC, you do not have to analyze the entire > program in C++ as goto can only jump within the same function so comparisons > with BASIC is silly. there's longjmp though even that can only jump upstack
From: spinoza1111 on 25 Apr 2010 06:28 On Apr 25, 5:50 pm, Nick Keighley <nick_keighley_nos...(a)hotmail.com> wrote: > On 24 Apr, 16:48, "Leigh Johnston" <le...(a)i42.co.uk> wrote: > > > > > > > "Daniel T." <danie...(a)earthlink.net> wrote in message > > >news:daniel_t-DBCC13.11141024042010(a)70-3-168-216.pools.spcsdns.net... > > > > Ali Karaali <ali...(a)gmail.com> wrote: > > > >> I use goto to break nested for loops and I can't see a > > >> reason to ban goto. > > > > I'll give you a reason to ban goto. This is a line of BASIC code: > > > > 90 x = 5 > > > > Now, I ask you, where is the line that was previously executed? Is it > > > directly above line 90, is it directly below it, or could it be anywhere > > > in the program? Because of the goto statement, simply because an > > > unstructured "goto" is possible in the language, you have to analyze the > > > entire program to know the answer. If we ban the use of "goto", we can > > > confidently know exactly what line of code comes before line 90. > > > This channel is about C++ not BASIC, you do not have to analyze the entire > > program in C++ as goto can only jump within the same function so comparisons > > with BASIC is silly. > > there's longjmp > though even that can only jump upstack Hmm, I never have to use longjmp, since I tend to factor more. Factoring a problem is resisted in Amerikkkan programming because Amerikkkan managers don't want employees to be "creative", and it takes a minimal amount of creativity to create a new C function. Employees who learn how to construct and manage large systems are innately dangerous, since their knowledge might transfer to labor union organization or political causes above the level of Tea Baggery. This is why properly factored code that consists of properly functionally bound units often ENRAGES managers, and programmers alienated and dispirited by the corporate rat race. If it contains small functions whose purpose can be expressed in a well-constructed sentence it is an image of a decent society in a society that thrives on exporting death and importing alienation. It's ideologically safer to use slop programmerese such as "I don't wanna call dis function in multiple cases becuz dat is bad" in order to show you know your place in the pecking order. The ideal program is a single main() routine that does everything: a model of a Fascist society. Ein reich! Ein Fuhrer!
From: Leigh Johnston on 25 Apr 2010 06:54
"James Kanze" <james.kanze(a)gmail.com> wrote in message news:f8ad45ef-b5e6-488c-8940-5841b2408e0b(a)11g2000yqr.googlegroups.com... > On Apr 24, 1:20 pm, "Leigh Johnston" <le...(a)i42.co.uk> wrote: >> "spinoza1111" <spinoza1...(a)yahoo.com> wrote in message > >> news:051fa27d-5cf8-4f7e-94c8-e9e5b26566b7(a)g34g2000pro.googlegroups.com... > >> > On Apr 24, 6:06 pm, Ali Karaali <ali...(a)gmail.com> wrote: >> >> I use goto to break nested for loops and I can't see a >> >> reason to ban goto. > >> > Why not use break instead? Does the same thing, spares you >> > from having to define a label. > >> Because break only breaks out of the innermost loop, using >> goto to break out of nested loops is one of the few sensible >> uses of goto. > > But when do you have to break out of a nested loop? (And of > course, the only valid use of break in C++ is to end a case in a > switch. Otherwise, it's just a goto in disguise.) > > -- > James Kanze I don't use goto much, I have just three uses of it in my entire codebase and in all cases it is for breaking out of a nested control structure: two are for exiting a switch inside a while loop and the other is exiting a nested for loop. The alternative to using goto in these cases would involve the creation of an extra exit flag that would have to be checked at each level which is not always desirable. /Leigh |