Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: Notesfiles $Revision: 1.7.0.10 $; site ccvaxa Path: utzoo!watmath!clyde!cbosgd!ihnp4!inuxc!pur-ee!uiucdcs!ccvaxa!aglew From: aglew@ccvaxa.UUCP Newsgroups: net.lang Subject: Re: and if you put this in your languag Message-ID: <800009@ccvaxa> Date: Thu, 13-Mar-86 21:54:00 EST Article-I.D.: ccvaxa.800009 Posted: Thu Mar 13 21:54:00 1986 Date-Received: Sat, 15-Mar-86 19:41:41 EST References: <1187@mmintl.UUCP> Lines: 68 Nf-ID: #R:mmintl.UUCP:1187:ccvaxa:800009:000:1852 Nf-From: ccvaxa.UUCP!aglew Mar 13 20:54:00 1986 Why add `and-if'? Use gotos: if A then X; if B then Y else goto AB else goto AB AB: begin Z end. Have I shocked you all? Will I have enough flames to break up the Ottawa River early? (I'm going home this weekend, hurrah!) Are you all going to tell be the above code is wrong? Hold on: this is Donald E. Knuth's example. In the uproar that followed Dijkstra's "Goto considered dangerous" letter, Knuth came out with a bit of reason. He suggested that gotos only be used where a bit of work (X above) has made one case into another. He also suggested that it be illegal to fall through to a label - that the only way to reach a label is via a goto. Finally, something I'm not sure whether it's my idea, or Knuth's, or somebody else's, there is the concept of an ASIDE. An ASIDE is a labelled block of code that can only be entered via a goto to the label at the top of the aside (and can only be exited in one of the normal ways to exit a block). Code that would seemm to fall through to an aside branches around it. So above you really have goto END AB: begin Z; goto END end END: ... The aside has saved you a goto and a label - it makes it seem just a bit less like spaghetti. Anyway, you can obviously do if A then X if B then Y else Z else Z Although it reads more easily if you do if !A then Z else if B then Y else Z but if Z is not simply a function call then you have to make sure that two copies of code get updated. That's what macros are for if ( !A ) { #define Z zzzzzzzzzzzzzzz Z; } else { if ( B ) Y; else Z; } A big #define in line looks ugly, and is really just like an aside, except that it hides a bit of the concept of doing work to get simpler cases. Andy "Krazy" Glew. Gould CSD-Urbana. USEnet: ...!ihnp4!uiucdcs!ccvaxa!aglew ARPAnet: aglew@gswd-vms