home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / std / cplus / 2024 < prev    next >
Encoding:
Text File  |  1993-01-11  |  6.5 KB  |  120 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!mcsun!julienas!jussieu!shiva.jussieu.fr!kriss
  3. From: kriss@trot.ibp.fr (Christophe GROSJEAN)
  4. Subject: Re: Use of nested functions (Was: Proposal for default scope)
  5. In-Reply-To: greg@harvey.qualcomm.com's message of Sun, 10 Jan 1993 02:34:40 GMT
  6. Message-ID: <KRISS.93Jan11121427@trot.ibp.fr>
  7. Sender: news@jussieu.fr (Le Facteur)
  8. Nntp-Posting-Host: trot.ibp.fr
  9. Reply-To: grosjean@masi.ibp.fr
  10. Organization: Laboratoire MASI, Paris, France.
  11. References: <1993Jan9.173310.13214@taumet.com> <1993Jan10.023440.27522@qualcomm.com>
  12. Date: Mon, 11 Jan 1993 11:14:27 GMT
  13. Lines: 105
  14.  
  15. In article <1993Jan10.023440.27522@qualcomm.com> greg@harvey.qualcomm.com (Greg Noel) writes:
  16.  
  17. >   There's a difference between hiding a lot of grungy detail and intrinsic
  18. >   inefficiency.  If the compiler filling in the grungy details is what is
  19. >   causing the inefficiency, the programmer can always replace it with something
  20. >   more efficient.  If it's inefficient because of something required by the
  21. >   language, that's not possible.
  22.  
  23. As others pointed out, nested functions requires innefficiency only when needed.
  24. In a word : if you don't use it no cost for you. That's not the case if this
  25. feature is not in the language. Then you must pay two times :
  26.     - not as efficient implementation as built-in ones (even with very good code)
  27.     - much difficulty to write your code, so NOBODY else but you can use
  28.     libraries using non standard function calls (to emulate nested functions)
  29.  
  30. The evident consequence is that without nested functions inside the language,
  31. I will change my programming style to be level with language inadequacies.
  32.  
  33. >   It's curious---I posted my original article to try to start a discussion
  34. >   about how something like modules or packages could be added to C++ as
  35. >   seamlessly as possible, because I see that as something that the language
  36. >   doesn't handle well and needs badly.  But most of the responses have been
  37. >   from people who reacted to one throw-away clause as a disparagement of
  38. >   nested functions, which is not what I intended at all.
  39.  
  40. Packages would indeed be usefull. But that's not what I miss most right now.
  41. I feel there is already many ways to achieve this with classes.
  42. Is it not the goal of encapsulation ?
  43.  
  44. >   Personally, I'd prefer to let those who feel passionately about nested
  45. >   functions debate this point.  As it is, I'm mooting a point about which
  46. >   I don't care very much.  In my thirty years of experience, including using
  47. >   languages that provided them, I've only wanted nested functions a few
  48. >   times---and I've _never_ wanted to take the address of one.  If I don't
  49. >   use them and if they don't cause me any inefficiency, then I don't really
  50. >   care if they are present or not.
  51.  
  52. I only have fourteen years of programming. But what I can say is that when
  53. I hadn't used OO languages, I never cared much about nested functions.
  54. I won't miss them in Lisp, C, Pascal or Modula.
  55.  
  56. But I can't do without them for OO Programming. Programming in Smalltalk,
  57. Ptitloo (lisp with an object interface) and Weird-Looking Mering IV, what
  58. I miss most is decent containers. Let's explain.
  59.  
  60. My actual problem is making part of my local context be seen by a function.
  61. Wich I can't call myself, cause it's called indirectly either by a system
  62. C function (like qsort), or by a class library.
  63.  
  64. Making the context of a call seeable by a library is necessary in order
  65. to make clean containers. What I mean by clean containers is containers
  66. that can handle iterations internally, not externally using another class
  67. (iterators) as it is generally done in C++.
  68.  
  69. The two approches are not equivalent. Iterators give control back to users
  70. at each element in order to execute the user's code. Even if in much cases
  71. it works fine, it doesn't with complex structures or heavily parallelized
  72. archithectures.
  73.  
  74. What I'm saying is : is I don't give back the control to users at each step
  75.     - I can do recursive calls very easily (to walk trees for instance)
  76.     - I can make the iteration parallel in my library, may be I will have
  77.     to hack machine code *inside* my container library, but users don't care
  78.     this can't be done with iterator classes.
  79.  
  80. *BUT* to write a clean iterator, I need something to iterate : a function call.
  81. This function is provided by user, so it MUST be easy to write, still its
  82. interface is fixed by the container  (generally it takes an element of DATA),
  83. and finally this function have generally to see external world.
  84.  
  85. You can achieve thoses three goals with nested functions. No other C++ hack
  86. would do. The main problem is with simplicity, the other two, you can do.
  87. What I call simplicity in my lab is, *as C as possible*. Many peoples are
  88. eager to compile with C++ in order to reuse libraries written by others,
  89. but not much are really wanting to learn OOP. Creating instances, they can
  90. manage. Nested functions too (some C compilers as gnu C already has nested
  91. functions). OO Design is to much. Nested functions would be a clean way to
  92. write clean, efficien, perfectly encapsulated containers with iterators for
  93. these people. I could adapt my libraries on parallel computers without
  94. having them to change their code.
  95.  
  96. Ok, this use of nested functions is not perfectly clean in OO Design,
  97. what should be perfect is a brand new class of functions...
  98. functions that are really instances of a class, with a context,
  99. an initialisation member, a return adress, etc.
  100. If you think of it, it's nearly what a compiler would do in order to
  101. implement nested functions.
  102.  
  103. This kind of class functions I can do in C++, but it's not simple to create
  104. them. Terminal users won't use them... if I can't shorten their declaration.
  105. I could do it with a better preprocessor... but preprocessor has'nt evolded.
  106. It's still the good old C preprocessor, whose initial purposes are mostly
  107. obsolete with C++. It's not well adapted with other purposes, as simplifying
  108. specific class declarations. But that's another point.  
  109.  
  110. >   On the other hand, there are literally hundreds of times I've wanted to
  111. >   have a helper function that was not externally visible.  In C, a static
  112. >   function provides most of the functionality I want, while in C++ it's
  113. >   all but impossible.  If C++ wants to be considered a ``better'' language
  114. >   than C, that's something that will have to be addressed.
  115.  
  116. Agreed... is it not still a problem of the number of line you have to write to
  117. do what you want ? Efficiency is not even half of a language IMO, reusability
  118. and clean interface (merely *short* semantic, minimalise the number of tokens
  119. you must type to express yourself) is the other half. 
  120.