forum-msg-id-135470-edit

Original date:2021-01-13 12:23:01 Edited by: petelomax Subject: Re: Nested functions - better example?

ChrisB said...

Call me thick if you want

I'm tempted blink

ChrisB said...

what is the advantage of a nested function, as opposed to an external function?

Consider this (although semi-based on something, it's actually complete fiction):

-- file pGUI.e 
function IupTreeView(...) 
    function createTVelem(...) 
    function iupTreeSetNodeAttributes(...) 
    function iupTreeAddNodesRec(...) 
    function deleteChildren(..) 
    function clickHandler(...) 

as compared to:

-- file pGUI.e 
function createTVelem(...) 
function iupTreeSetNodeAttributes(...) 
function iupTreeAddNodesRec(...) 
function deleteChildren(...) 
function clickHandler(...) 
function IupTreeView(...) 

Obviously, you're getting the same "breakdown into smaller more manageable units" value from both.
There's probably not much difference in understanding IupTreeView, but as a whole pGUI.e becomes far easier.
When modifying IupTreeView, in the second case you have to worry about/check whether anything else is using them,
whereas in the first case you can hack at them with impunity, only caring about a much smaller subset of pGUI.e
Some of them might obviously belong, but could you be so sure about deleteChildren() or clickHandler()?

So, on the small scale and short include files the advantages are pretty much zero, but there's a gain when they grow.

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu