home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18236 < prev    next >
Encoding:
Text File  |  1992-12-21  |  3.4 KB  |  76 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Give me safe C++
  5. Message-ID: <1992Dec19.175111.9024@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Dec14.190553.14838@mole-end.matawan.nj.us> <1992Dec17.192301.23525@ucc.su.OZ.AU> <HF.92Dec18115942@whyaduck.tk.telematik.informatik.uni-karlsruhe.de>
  10. Date: Sat, 19 Dec 1992 17:51:11 GMT
  11. Lines: 63
  12.  
  13. In article <HF.92Dec18115942@whyaduck.tk.telematik.informatik.uni-karlsruhe.de> hf@tk.telematik.informatik.uni-karlsruhe.de (Harald Fuchs) writes:
  14. >In article <1992Dec17.192301.23525@ucc.su.OZ.AU>, maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  15. >> Anyone else for nested functions? Against?
  16. >
  17. >I agree that they are sometimes quite handy, but I've never missed
  18. >them. In the old days when I was a Modula-2 addict, I used them most
  19. >of the time in a situation where I needed a function call in a
  20. >specific context (which in turn can be expressed as a kind of
  21. >"state"), and this is exactly what objects are for.
  22. >
  23.     You are perfectly correct that nested functions can be replaced
  24. by members if one rewrites huge hunks of code.  
  25.  
  26.     It is also possible to just use an ordinary function in many cases, 
  27. and pass it lots of parameters.
  28.  
  29.     Your argument is also one that would disallow all nested blocks. 
  30.  
  31.     In the spirit of your argument, I suggest that functions
  32. not be allowed to have more than one parameter,
  33. or more than one local variable.
  34. If somehow this seems to leave you with an object that is just
  35. a subtly hidden subspace of 'global' data, you would be
  36. correct.
  37.  
  38.     While I'm definitely not a structured programming fan,
  39. there are times when functional decomposition is appropriate,
  40. and data decomposition is not.
  41.  
  42.     Especially considering the C++ is not just an OO language,
  43. there are times when nested functions are far and away superior
  44. to using objects, and others when objects are more correct
  45. but its just too much work to bother.
  46.  
  47.     In any case, I'd like the choice. While developing
  48. a parser recently the function got too big to read,
  49. I wanted to decompose it. Because of the amount of context,
  50. I was *forced* to rewrite it in terms of objects.
  51.  
  52.     The rewrite took LONGER to do than the original code
  53. took to develop, and it still doesnt work properly.
  54. Yes, it is now much easier to manage, but nested functions would
  55. have provided a better transition from procedural code
  56. to object oriented code. In particular I have been forced
  57. to bind my data structures and interfaces prematurely
  58. into classes when I actually wanted rapid prototyping.
  59.  
  60.     CLOS as I understand it IMPLEMENTS OO by nested
  61. functions, the object IS the local activation record,
  62. the nested functions ARE the members of that record,
  63. and the object persists because of Garbage Collection.
  64.  
  65.     Perhaps the moral of this story is that there is more
  66. than one way to do OO, and more than one way to write a program,
  67. C++ is supposedly a hybrid language, and often C is said
  68. to be block structured. I just wish this were true, so
  69. I'm repeating my call for the artifical restriction against
  70. nested functions to be removed.
  71. -- 
  72. ;----------------------------------------------------------------------
  73.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  74.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  75. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  76.