Hi Uri, On Thursday 14 Apr 2011 17:47:02 Uri Guttman wrote: > >>>>> "SF" == Shlomi Fish <shlo...@iglu.org.il> writes: > SF> On Thursday 14 Apr 2011 09:15:35 Uri Guttman wrote: > >> >>>>> "PS" == Peter Scott <pe...@psdt.com> writes: > PS> Here is the definitive explanation: > >> http://www.cs.utexas.edu/users/EWD/ PS> ewd02xx/EWD215.PDF . > >> > >> having heard about that article for many years it was interesting to > >> read it. it may be over the head of some members here but useful to > >> read anyway. it doesn't go into any practical reasons why goto is > >> bad. it just says the logical complexity (his index data) goes way up > >> with gotos but stays reasonable with high level flow controls > >> (if/else/while/sub/etc.). > > SF> Quoting my post: > > SF> [QUOTE] > > SF> The entire "GOTO statement considered harmful" is quite a > SF> myth. Granted, Dijkstra wrote an article with this title, and many > SF> people agreed with him. But, on the other hand, some people have > SF> demonstrated that it is possible to do structured programming with > SF> goto statements, and sometimes even better with them than without > SF> them. > > demonstrations don't mean a thing. i did tons of assembler coding and > was even object oriented and my goto use was cleaner than most high > level coders. i still wouldn't want to go back to that.
Demonstrations do mean something. > > SF> For example, Don Knuth wrote an article "Structured Programming > SF> Using Goto Statements" (rumouredly sub-titled "'Goto Statement > SF> Considered Harmful' Considered Harmful") in which he deomnstrated > SF> exactly that. And I take this view as well. > > knuth was making more of a joke with that. also he is knuth. you are not > knuth. His "Structured Programming Using Goto Statements" was not a joke - it was a serious article and you can find it here: http://www.google.com/search?q=structured%20programming%20goto%20statements ( The "'Goto statement Considered Harmful' Considered Harmful" article was someone else, BTW). I may not be Prof. Knuth (no one except him is or was), but I may still agree with him, and can cite his papers for support. And you shouldn't dismiss what I say as "You are not Knuth" because this is an http://en.wikipedia.org/wiki/Ad_hominem . And as someone on the comments on the post there (which you should read) said, the idea for the title "Goto statement considered harmful" was introduced by Dijkstra's editor, and Dijkstra did not mean that any and all use of goto is bad. > > > SF> Don't get me wrong, I don't advocate a goto-spaghetti, like I once > SF> saw in old BASIC programs. But goto's have their use. > > wrong. especially wrong for newbies. even more wrong for newbies > learning perl. In Perl, I don't encourage people using goto statements, and I did not find a use for them in Perl, yet. But I don't rule out that they have legitimate use in other languages. > > SF> When programming in C, I find myself using goto's whenever I feel > SF> the need to. This occurs less in Perl where I have other powerful > SF> constructs. > > then you don't know how to code well in c. Thanks for the compliment. ;-) > it may not be as nice as perl > for some flow control things but goto is never needed in c either. Thanks for avoiding over-generalisations. ;-) > i > have seen it used and there are always better ways to code it than with > gotos. you just need to know other techniques and none of them are > convoluted. a better design helps too. > Well, some use cases for goto in C: 1. Breaking out of more outer loop (as there is no "continue label;" or "break label;" in C: <CODE> for (i=0 ; i < len ; i++) { for (j = 0.... { if (func(i, j) { goto after_loops; } } } after_loops: </CODE> 2. Another is the de-allocation of resources at the end of the function with checking for failure: <CODE> int alloc_stuff(struct_t * * ref) { . . . if (!first = malloc(...)) { return FAILURE; } if (!second = malloc(....)) { goto first_free; } if (!third = malloc(...)) { goto second_free; } . . . *ref = mystruct_ptr; return SUCCESS; second_free: free(second); first_free: free(first); return FAILURE; } </CODE> I should note that in C "continue", "break", and a pre-mature "return" may also be considered as pseudo-gotos. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Interview with Ben Collins-Sussman - http://shlom.in/sussman I'd do Windows-- , but this may result in an integer underflow. -- an Israeli Linuxer. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/