Re: [Gluster-devel] An interesting take on GoTo statement by Dijkstra -
Thanks Jeff and Kaleb for providing a good insight. At least in Gluster code I have not come across any use of go to other than forward and out. On 16-Jan-2015, at 12:21 am, Jeff Darcy wrote: >> Since the goto idiom that Gluster uses generates the same code — which >> is what matters — I gave up my short-lived battle for not using it. > > One handy rule of thumb is based on whether a "goto" is forward or back, > in (to a loop or other control contruct) or out. Forward and out are > generally OK - no worse than extra state flags and better than code > duplication - so they generally don't bother me. A handful of times in > my entire career, I've seen a backward goto that was (weakly) justified. > I've never seen an inward goto that was anything but pure evil, and I > don't expect to. Fortunately, many people don't even know they're > possible, so they're rare. > ___ > Gluster-devel mailing list > Gluster-devel@gluster.org > http://www.gluster.org/mailman/listinfo/gluster-devel > > ___ Gluster-devel mailing list Gluster-devel@gluster.org http://www.gluster.org/mailman/listinfo/gluster-devel
Re: [Gluster-devel] An interesting take on GoTo statement by Dijkstra -
> Since the goto idiom that Gluster uses generates the same code — which > is what matters — I gave up my short-lived battle for not using it. One handy rule of thumb is based on whether a "goto" is forward or back, in (to a loop or other control contruct) or out. Forward and out are generally OK - no worse than extra state flags and better than code duplication - so they generally don't bother me. A handful of times in my entire career, I've seen a backward goto that was (weakly) justified. I've never seen an inward goto that was anything but pure evil, and I don't expect to. Fortunately, many people don't even know they're possible, so they're rare. ___ Gluster-devel mailing list Gluster-devel@gluster.org http://www.gluster.org/mailman/listinfo/gluster-devel
Re: [Gluster-devel] An interesting take on GoTo statement by Dijkstra -
On 01/15/2015 08:02 AM, Nagaprasad Sathyanarayana wrote: On 15-Jan-2015, at 5:38 pm, Vijay Bellur wrote: On 01/15/2015 12:13 PM, Nagaprasad Sathyanarayana wrote: In a quest to find why good programmers are wary of the "Go To" statement, came across this interesting article by /Edsger W. Dijkstra/ . http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html. goto statements that cause one to go back & forth across the code are annoying to me. However, if goto statements are used to return control from a common point within a function, they enhance readability and also help in ensuring that we perform necessary cleanup/terminal actions for a function in a single place. It is to be noted that Dijkstra's article appeared before C was invented. If you are interested in understanding more about goto, Knuth's paper titled Structured Programming with go to statements [1] and a lkml thread on the same [2] can be helpful. FWIW, if you consider the trivial example: #include void Goto(int ctl) { if (ctl == 0) { printf ("foo\n"); goto out; } if (ctl == 1) { printf ("bar\n"); goto out; } if (ctl == 2) { printf ("baz\n"); goto out; } printf ("nothing happened\n"); out: printf ("returning\n"); } void StructuredGoto(int ctl) { do { if (ctl == 0) { printf ("foo\n"); break; } if (ctl == 1) { printf ("bar\n"); break; } if (ctl == 2) { printf ("baz\n"); break; } printf ("nothing happened\n"); } while (0); printf ("returning\n"); } If you compile to assembly, both functions generate exactly the same code, both with and without optimization. (gcc-4.9.2, clang-3.4) Gluster prefers the use of goto as it eliminates a level of indentation. We have a somewhat artificial limit of 80 columns and functions that have too many levels of indention will get kicked out in review. Since the goto idiom that Gluster uses generates the same code — which is what matters — I gave up my short-lived battle for not using it. -- Kaleb ___ Gluster-devel mailing list Gluster-devel@gluster.org http://www.gluster.org/mailman/listinfo/gluster-devel
Re: [Gluster-devel] An interesting take on GoTo statement by Dijkstra -
Thanks Vijay for sharing these. Very informative. Thanks Naga > On 15-Jan-2015, at 5:38 pm, Vijay Bellur wrote: > >> On 01/15/2015 12:13 PM, Nagaprasad Sathyanarayana wrote: >> In a quest to find why good programmers are wary of the "Go To" >> statement, came across this interesting article by /Edsger W. Dijkstra/ . >> >> http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html. > > goto statements that cause one to go back & forth across the code are > annoying to me. However, if goto statements are used to return control from a > common point within a function, they enhance readability and also help in > ensuring that we perform necessary cleanup/terminal actions for a function in > a single place. > > It is to be noted that Dijkstra's article appeared before C was invented. If > you are interested in understanding more about goto, Knuth's paper titled > Structured Programming with go to statements [1] and a lkml thread on the > same [2] can be helpful. > > Cheers, > Vijay > > [1] > http://dl.acm.org/citation.cfm?id=356640&dl=ACM&coll=DL&CFID=472165232&CFTOKEN=27447667 > (needs access to ACM) > > [2] > http://koblents.com/Ches/Links/Month-Mar-2013/20-Using-Goto-in-Linux-Kernel-Code/ > > ___ > Gluster-devel mailing list > Gluster-devel@gluster.org > http://www.gluster.org/mailman/listinfo/gluster-devel > > ___ Gluster-devel mailing list Gluster-devel@gluster.org http://www.gluster.org/mailman/listinfo/gluster-devel
Re: [Gluster-devel] An interesting take on GoTo statement by Dijkstra -
On 01/15/2015 12:13 PM, Nagaprasad Sathyanarayana wrote: In a quest to find why good programmers are wary of the "Go To" statement, came across this interesting article by /Edsger W. Dijkstra/ . http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html. goto statements that cause one to go back & forth across the code are annoying to me. However, if goto statements are used to return control from a common point within a function, they enhance readability and also help in ensuring that we perform necessary cleanup/terminal actions for a function in a single place. It is to be noted that Dijkstra's article appeared before C was invented. If you are interested in understanding more about goto, Knuth's paper titled Structured Programming with go to statements [1] and a lkml thread on the same [2] can be helpful. Cheers, Vijay [1] http://dl.acm.org/citation.cfm?id=356640&dl=ACM&coll=DL&CFID=472165232&CFTOKEN=27447667 (needs access to ACM) [2] http://koblents.com/Ches/Links/Month-Mar-2013/20-Using-Goto-in-Linux-Kernel-Code/ ___ Gluster-devel mailing list Gluster-devel@gluster.org http://www.gluster.org/mailman/listinfo/gluster-devel
[Gluster-devel] An interesting take on GoTo statement by Dijkstra -
In a quest to find why good programmers are wary of the "Go To" statement, came across this interesting article by /Edsger W. Dijkstra/ . http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html. Cheers Naga ___ Gluster-devel mailing list Gluster-devel@gluster.org http://www.gluster.org/mailman/listinfo/gluster-devel