Goto (Posting On Python-List Prohibited)

Peter J. Holzer hjp-python at hjp.at
Sat Dec 30 07:46:14 EST 2017


On 2017-12-29 19:09:35 -0500, Dennis Lee Bieber wrote:
> On Fri, 29 Dec 2017 23:12:22 +0000, bartc <bc at freeuk.com> declaimed the
> following:
> >Looking at 14 million lines of Linux kernel sources, which are in C, 
> >over 100,000 of them use 'goto'. About one every 120 lines.
> >
> 
> 	C is a language that predates the "structured programming" concepts of
> the late 70/early 80.

I don't think this is correct. Structured programming is much older:
ALGOL 60 was already a block structured language and Dijkstra wrote
"goto considered harmful" in the late 1960s. Pascal appeared in 1970, C
in 1974. To me (who learned to program in BASIC on a CP/M machine), C
is very much a structured programming language. If structured
programming gained traction around 1980, it might even have been because
structured languages like C with good performance became widely
available.

That said, C lacks exception handling (well, there is setjmp/longjmp,
but ...) and multi-level break/continue, so goto is often the cleanest
way to abort what you are doing and start to clean up. Python has
exception handling, and that removes most of the cases where you would
use goto in C (the rest is probably mostly in micro-optimizations: If
you care about the run-time difference between a goto and a subroutine
call, you probably shouldn't use Python in the first place).

        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp at hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20171230/a8e8b5d4/attachment.sig>


More information about the Python-list mailing list