adjg@softway.oz (Andrew Gollan) (07/04/89)
>> I do not understand why C does not support Nested routines. Perhaps >>this will be added to the ANSI standard at some point in the future. >Probably the biggest thing against it is the fact that it makes compilers much >more difficult to write (especially modifying existing compilers). No. The reason why C does not support nested functions is that it is a _bad_ idea. The worst piece of impenetrable rubbish I have ever tried to understand was written by Wirth in Algorithms + Data = Programs and purported to handle B-trees. It was made impossible to understand by the _complexity_ of the scoping considerations. C scoping is not perfect, maybe, but nested functions would only make it worse. -- Softway: +61 2 698 2322 Andrew Gollan adjg@softway.oz GPO Box 305, Strawberry {uunet,mcvax}!softway.oz!adjg Hills NSW 2012 Fax: +61 2 699 9174
dsking@pyr.gatech.EDU ( David King) (07/05/89)
In article <1787@softway.oz> adjg@softway.oz (Andrew Gollan) writes: >No. The reason why C does not support nested functions is that it is >a _bad_ idea. The worst piece of impenetrable rubbish I have ever tried >to understand was written by Wirth in Algorithms + Data = Programs and >purported to handle B-trees. It was made impossible to understand by the >_complexity_ of the scoping considerations. C scoping is not perfect, maybe, >but nested functions would only make it worse. Actually, Wirth is one of the more obscure Modula-2 programmers I've seen. The Pascal/Modula-2 scoping constructs are not that difficult assuming that there is proper indenting, not having lots of variables at different levels, and not having huge sections of code in a module - all of these I've seen in Wirth's code at times. The ETH compiler has one module which is half the compiler in size (or so I've heard from a M2 compiler writer who fiddled with it). On the flip side one of the most impenetrable pieces of code was a keyed file editor written in C with no parameters declared at random locations in files. x, xbf, and i were common local and global vars. -David >-- >Softway: +61 2 698 2322 Andrew Gollan adjg@softway.oz >GPO Box 305, Strawberry {uunet,mcvax}!softway.oz!adjg >Hills NSW 2012 Fax: +61 2 699 9174 -- David King - FROM Disclaimers IMPORT Standard; Georgia Insitute of Technology, Atlanta Georgia, 30332 uucp: ...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-ngp}!gatech!gitpyr!dsking ARPA: dsking@pyr.gatech.edu
wade@pnet01.cts.com (Wade Bickel) (07/09/89)
adjg@softway.oz (Andrew Gollan) writes: >No. The reason why C does not support nested functions is that it is >a _bad_ idea. The worst piece of impenetrable rubbish I have ever tried >to understand was written by Wirth in Algorithms + Data = Programs and >purported to handle B-trees. It was made impossible to understand by the >_complexity_ of the scoping considerations. C scoping is not perfect, maybe, >but nested functions would only make it worse. I used that piece of code myself. Never had any trouble understanding how the scoping is use Did you write your own replacement? Without nesting it must be more complicated. I don't see what your probem was with the code, since it worked perfectly as is out of the book As far as it being equally doable by the programmer in C, this is not the case. There is no good way to make the input parametersto a function visable to sub-functions without duplicating them. I can see a possible compiler specific hack that might alleiviate this but this really should not be considered. I've thought about this whole issue of "displays" and I don't believe it is as bad as indicated. Allowing one level of nesting would be a breeze, and deeper nesting would only require a pointer list system. The way I see it is this. If C supported nesting, the programer would know the ramifications of using nesting; namely that each level deeper a nested routine is, the less efficiently it can get at the globals at higher levels. I myself would probably never nest routines more than one level. The code generated by such nesting should be efficeint, using an address register to hold a simple frame pointer No one would have to use the feature, so it would be a plus, with no deficits. Plese understand, I like C. Since I'm mosly writing solo applications or working with a few others on projects we expect no one else to have to maintain, C is great. My only point is it would be improved by adding a few of the things Modula-2 has to offer. I'd ike to see nesting and an equivalent to the WITH statement. Both these things would be advntagous without any corresponding disadvantages. Have Fun, Wade. l UUCP: {nosc ucsd hplabs!hp-sdd}!crash!pnet01!wade ARPA: crash!pnet01!wade@nosc.mil INET: wade@pnet01.cts.com
mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer) (07/10/89)
In article <4586@crash.cts.com> wade@pnet01.cts.com (Wade Bickel) writes:
< Plese understand, I like C. Since I'm mosly writing solo applications
<or working with a few others on projects we expect no one else to have to
<maintain, C is great. My only point is it would be improved by adding a few
<of the things Modula-2 has to offer. I'd ike to see nesting and an equivalent
<to the WITH statement. Both these things would be advntagous without any
<corresponding disadvantages.
Both of these changes would be non-trivial changes to the C langauge
(futzing with the visibility of variables is never trivial, and that's
what both of these changes do). They would both make the compiler
bigger, thus slowing down either compilation (if the compiler lives on
disk) or system performance (if it stays in memory) or both for anyone
who uses it.
In any case, if you really believe these would improve C, don't talk
about it here, convince the ANSI committe to put it in. To do that,
you're going to have to have a working implementation ready when they
start the update to the standard. I'd recommend starting with gcc, as
it's pretty close to the standard, produces good code, and has a
number of interesting extensions already.
<mike
--
When all our dreams lay deformed and dead Mike Meyer
We'll be two radioactive dancers mwm@berkeley.edu
Spinning in different directions ucbvax!mwm
And my love for you will be reduced to powder mwm@ucbjade.BITNET