🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1318

Re: Nested functions (was: Re: Zero-length structures and pointer comparisons)

#1318
From: John MAX Skaller
Date: Sun, 20 Dec 1992 14:33
50 lines
2930 bytes
>
>What can nested functions do that OO features of C++ can't? Use
>of nested functions sounds like you may be trying to delegate
>implementation, which is a great use for objects.
>

	What nested functions allow you to do that you cant with objects
is take a function that is getting to big and decompose it rapidly
and reliably into several smaller functions.

	The second thing you can do is rapidly and reliably factor
out common pieces of code, again to reduce the size of a function,
improve readability and reliability.

	One can then later reorganise so the functions are put
into a class instead of a function, however this is a much bigger
job, and it tends to enforce design decisions when one would
prefer to defer them. And when one does finally 'objectify'
the code, it would be nice to have the nested functions
already there waiting to be turned into members,
instead of having to do functional and data decomposition
simultaneously.

	There are times when procedural code is much cleaner
than using objects. For example, when one has some objects
with complex links between them (including mutual self reference),
it is often easier to just make the objects raw and then stick
all the pointers in. Doing it with constructors is quite tricky,
especially considering that some of the pointers dont exist yet,
and the initialisation code is spread all over the place
like spagetti. This is particularly true while rapid prototyping.

	There's also a couple of technical advantages to
having nested functions even when coding
member functions, over adding a private helper member, one being
that the class interface doesnt have to be changed.

	I've mentioned all these things, because I've just
gone through the process of taking a parser function
and turning it into an object. It took longer to
do this than write the original procedural code.
I had to do it, but I would have prefered to be able to
do some functional decomposition first, I think the whole
process would have been quicker.

-- 
;----------------------------------------------------------------------
        JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
	Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
Technical Details
Message-ID: <1992Dec20.143322.8523@ucc.su.OZ.AU>
Path: arc1-ca.pugleaf.net!sparky!uunet!noc.near.net!hri.com!spool.mu.edu!think.com!rpi!batcomputer!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
References: <24413@alice.att.com> <BzBHn4.26J@ssesco.com> <harvey.724609916@baffin>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!noc.near.net!hri.com!spool.mu.edu!think.com!rpi!batcomputer!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
Newsgroups: comp.std.c++
Subject: Re: Nested functions (was: Re: Zero-length structures and pointer comparisons)
Message-ID: <1992Dec20.143322.8523@ucc.su.OZ.AU>
Date: 20 Dec 92 14:33:22 GMT
References: <24413@alice.att.com> <BzBHn4.26J@ssesco.com> <harvey.724609916@baffin>
Sender: news@ucc.su.OZ.AU
Organization: MAXTAL P/L C/- University Computing Centre, Sydney
Lines: 50
Nntp-Posting-Host: extro.ucc.su.oz.au