home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / ada / 2498 < prev    next >
Encoding:
Text File  |  1992-08-31  |  3.3 KB  |  80 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!widget!jjh
  3. From: jjh@evb.com (John Halper)
  4. Subject: Re: ADA question
  5. Message-ID: <1992Aug31.211450.4809@evb.com>
  6. Organization: EVB Software Engineering, Inc.
  7. Date: Mon, 31 Aug 1992 21:14:50 GMT
  8. Lines: 70
  9.  
  10. *In article <1992Aug27.102951.8681@news.uni-stuttgart.de>, ucaa2385@ruscvx.rus.uni-stuttgart.de (Peter Hermann) writes:
  11. *|> In article <1992Aug27.004228.19551@evb.com> jjh@evb.com (John Halper) writes:
  12. *|> >Daljeet writes:
  13. *|> >>I have a function in a package A which returns string. I am using
  14. *|> >>that function in another package B and try to give the value returned
  15. *|> >>by that function to a variable (which has been declared in package B).
  16. *|> >>The variable is of type string (1 .. max) initialised to empty string.
  17. *|> >
  18. *|> >I don't like making the call twice, and would rather use one of first two 
  19. *|> >solutions, but ...
  20. *|> 
  21. *|> It is advisable to call any function only once
  22. *|> for the same purpose, because a function result
  23. *|>  1. may change from call to call
  24. *|>  2. may be expensive
  25. *|>
  26. *
  27. *Absolutely! Avoid this like the plague.
  28. *
  29.  
  30.  
  31.  
  32. Ok, maybe I didn't explain my position adequately.  
  33.  
  34.  
  35. At EVB Software Engineering, this is not a problem for the following
  36. reasons.  
  37.  
  38. 1) Functions that return strings, other unconstrained arrays, or even limited
  39.    types are created under the rarest of circumstances. I would say never created
  40.    but the word 'never' is more black and white than most of the rest of reality.
  41.    Anybody know of a case requiring a function that returns one of these types?
  42.    So (IMHO), the "correct" solution is to rewrite the function as a procedure.
  43.  
  44. 2) At EVB, all development is done using an OO method which identifies 
  45.    operations as selectors, constructors or iterators ala Booch.  Selectors
  46.    almost always map to functions and by definition don't change the state of 
  47.    the associated object.  Therefore, other than selectors on an object
  48.    with life (life meaning the ability of an object to change it's own state),
  49.    selectors (functions) will always return the same result as long as a 
  50.    constructor has not been ivoked between the calls to the selector.  When a 
  51.    task is involved we have a number of schemes for dealing with protection of
  52.    shared data, some of which allow the double call to the selector to still 
  53.    work correctly.  In those cases where the selector could return a different
  54.    result, we apply #1.  I know you guys are not writing functions with 
  55.    side effects so I assume these circumstances had been considered. Then again 
  56.    the last time I assumed anything I got equated with a plague.     
  57.  
  58. 3) As to the efficieny of making two calls.  If I ever attempted to get something
  59.    like this through an inspection, well lets say this would consume the better 
  60.    part of an afternoon.  We try to give equal consideration to the portability, 
  61.    maintainability,  modifiability, reliability and efficeincy.  In this case, 
  62.    would strive for an implementation based on a single function call? 
  63.    See point #1.
  64.  
  65.  
  66. The only reason I resonded to the original post was to show that the result of a 
  67. function call can be used with a attribute.  Maybe I should have just said that in
  68. the first place.
  69.  
  70.  
  71. John Halper 
  72. Software Engineer
  73. EVB Software Engineering, Inc.
  74. 1 800 877 1815
  75. jjh@evb.com 
  76. -- 
  77.  
  78. John Halper
  79. halper@evb.com
  80.