home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6656 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.9 KB  |  74 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!clarkson!news
  3. From: kooijman@sun.soe.clarkson.edu (Harry Kooijman,Peyt314a,3808)
  4. Subject: Re: BP/TP OOP is missing something...
  5. Message-ID: <1992Nov17.200839.342@news.clarkson.edu>
  6. Sender: news@news.clarkson.edu
  7. Nntp-Posting-Host: sun.soe.clarkson.edu
  8. Organization: Clarkson University
  9. References: <dmurdoch.282.722020256@mast.queensu.ca>
  10. Date: Tue, 17 Nov 1992 20:08:39 GMT
  11. Lines: 61
  12.  
  13. From article <dmurdoch.282.722020256@mast.queensu.ca>, by dmurdoch@mast.queensu.ca (Duncan Murdoch):
  14. > In article <1992Nov17.153804.21729@news.clarkson.edu> kooijman@sun.soe.clarkson.edu (Harry Kooijman,Peyt314a,3808) writes:
  15. >>Why is it that TP with objects does not have the capability to call the
  16. >>constructors when variables are declared? And when an object goes out of
  17. >>scope it should be destructed automatically. For example:
  18. >>
  19. >>Function DoSomethingWithD;
  20. >>Var D:DoubleObject(1.2);
  21. >>Begin
  22. >>  ... 
  23. >>  Do something with D
  24. >>  ...
  25. >>End; {and here D gets destructed}
  26. > This is there in TP, to a very limited extent:  you can have an initialized 
  27. > variable which is an object, and you needn't call the constructor.  It's 
  28. > initialized at program load time, not each time the variable comes into 
  29. > scope.  The destructor is never called.
  30. > I think the main reason that TP doesn't have automatic constructor/
  31. > destructor calls is because it is descended from Pascal.  In Pascal in 
  32. > general, code doesn't get executed unless you explicitly ask for it.  
  33. > Adding automatic code would be a big change to the flavour of the language.
  34. > It's pretty unlikely that Borland would make such a fundamental change
  35. > that doesn't add any power to the language.  Your code fragment is exactly 
  36. > equivalent to
  37. >  var D:DoubleObject;
  38. >  begin
  39. >    D.init(1.2);
  40. >    ...
  41. >    D.done;
  42. >  end;
  43. > Since what you want to do is already possible with nothing more than a 
  44. > couple of extra lines of code, why make a big change to the language?
  45. > Duncan Murdoch
  46. > dmurdoch@mast.queensu.ca
  47.  
  48. It is this couple of extra lines that make the difference between using
  49. objects or not. With explicit calls to the constructor/destructor I can
  50. write exactly the same code without objects, and loose all the object
  51. overhead. What if you are adding a vector in a subroutine declaration
  52. list, write the constructor, and use it, but forget to destruct it (an
  53. o so easy and common bug): you start loosing heap. What if you forget
  54. the constructor (worse!) ? If you have only a couple of vectors to
  55. worry about you will probably not make this mistake. However if you are
  56. dealing with 15 vectors and 15 matrices in one routine it becomes a
  57. different matter. And that's why automatic construction and destruction
  58. takes me further.
  59.  
  60. Your comment about Pascal's flavour is well taken. I have little hope
  61. for any change.
  62.  
  63. Harry
  64. --
  65. Harry Kooijman: Rigorous dynamic distillation simulation.
  66. Dept. of Chemical Engineering, Clarkson University, Potsdam NY 13699.
  67. kooijman@sun.soe.clarkson.edu
  68.