home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / cplus / 1867 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  2.8 KB

  1. Path: sparky!uunet!noc.near.net!hri.com!spool.mu.edu!think.com!rpi!batcomputer!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  2. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Nested functions (was: Re: Zero-length structures and pointer comparisons)
  5. Message-ID: <1992Dec20.143322.8523@ucc.su.OZ.AU>
  6. Date: 20 Dec 92 14:33:22 GMT
  7. References: <24413@alice.att.com> <BzBHn4.26J@ssesco.com> <harvey.724609916@baffin>
  8. Sender: news@ucc.su.OZ.AU
  9. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  10. Lines: 50
  11. Nntp-Posting-Host: extro.ucc.su.oz.au
  12.  
  13. >
  14. >What can nested functions do that OO features of C++ can't? Use
  15. >of nested functions sounds like you may be trying to delegate
  16. >implementation, which is a great use for objects.
  17. >
  18.  
  19.     What nested functions allow you to do that you cant with objects
  20. is take a function that is getting to big and decompose it rapidly
  21. and reliably into several smaller functions.
  22.  
  23.     The second thing you can do is rapidly and reliably factor
  24. out common pieces of code, again to reduce the size of a function,
  25. improve readability and reliability.
  26.  
  27.     One can then later reorganise so the functions are put
  28. into a class instead of a function, however this is a much bigger
  29. job, and it tends to enforce design decisions when one would
  30. prefer to defer them. And when one does finally 'objectify'
  31. the code, it would be nice to have the nested functions
  32. already there waiting to be turned into members,
  33. instead of having to do functional and data decomposition
  34. simultaneously.
  35.  
  36.     There are times when procedural code is much cleaner
  37. than using objects. For example, when one has some objects
  38. with complex links between them (including mutual self reference),
  39. it is often easier to just make the objects raw and then stick
  40. all the pointers in. Doing it with constructors is quite tricky,
  41. especially considering that some of the pointers dont exist yet,
  42. and the initialisation code is spread all over the place
  43. like spagetti. This is particularly true while rapid prototyping.
  44.  
  45.     There's also a couple of technical advantages to
  46. having nested functions even when coding
  47. member functions, over adding a private helper member, one being
  48. that the class interface doesnt have to be changed.
  49.  
  50.     I've mentioned all these things, because I've just
  51. gone through the process of taking a parser function
  52. and turning it into an object. It took longer to
  53. do this than write the original procedural code.
  54. I had to do it, but I would have prefered to be able to
  55. do some functional decomposition first, I think the whole
  56. process would have been quicker.
  57.  
  58. -- 
  59. ;----------------------------------------------------------------------
  60.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  61.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  62. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  63.