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

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!eff!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!rpi!utcsri!skule.ecf!torn!news.ccs.queensu.ca!slip209.telnet1.QueensU.CA!dmurdoch
  3. From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  4. Subject: Re: BP/TP OOP is missing something...
  5. Message-ID: <dmurdoch.171.722054313@mast.queensu.ca>
  6. Lines: 73
  7. Sender: news@knot.ccs.queensu.ca (Netnews control)
  8. Organization: Queen's University
  9. References: <KIM.92Nov16125141@kim.Software.Mitel.COM> <1992Nov17.153804.21729@news.clarkson.edu> <dmurdoch.282.722020256@mast.queensu.ca> <10773@vice.ICO.TEK.COM>
  10. Date: Wed, 18 Nov 1992 02:38:34 GMT
  11.  
  12. In article <10773@vice.ICO.TEK.COM> bobbe@vice.ICO.TEK.COM (Robert Beauchaine) writes:
  13. >  This whole topic falls under the scope of garbage
  14. >  collection, which is considered by many programmers an extremely
  15. >  important part of a language.  And pascal already does it all the
  16. >  time anyway.  What happens to the local variables allocated on the
  17. >  stack when a function begins or ends?  They are created/destroyed
  18. >  by the compiler, which knows knows exactly how to perform these
  19. >  tasks.  The only difference between
  20. >  objects and the predefined data types is that *you* have to tell
  21. >  the compiler exactly how to build or get rid of the objects.  You
  22. >  should not have to tell the compiler _when_ to do so.  It seems to
  23. >  me the current object construction/destruction methodology is the
  24. >  departure from the norm.
  25.  
  26. No, I think there's a difference between allocating variables and 
  27. initializing them.  The compiler is perfectly capable of automatic 
  28. allocation of objects when they're local variables, and it'll automatically 
  29. free up the storage when it goes out of scope.
  30.  
  31. However, calling a constructor for an object is akin to initializing it.  
  32. As far as I can recall, there aren't any cases in Pascal where variables 
  33. are initialized without explicit action by the programmer.  In TP, there are 
  34. "typed constants", but as you mentioned, they usually aren't a good solution.
  35. There are also variables that get initialized by the init sections of units, 
  36. but the only one that doesn't require explicit mention is System.
  37.  
  38. Maybe allowing automatic initialization would be a good change.  It 
  39. would certainly save a line here and there if I could declare a local 
  40. variable with an initial value, e.g.
  41.  
  42.   procedure myproc;
  43.   var
  44.     i : integer = 0;
  45.   begin
  46.     while i < 5 do ...
  47.  
  48. and have the same effect as
  49.  
  50.   procedure myproc;
  51.   var
  52.     i : integer;
  53.   begin
  54.     i := 0;
  55.     while i < 5 do ...
  56.  
  57. But a change like this wouldn't gain me anything.  I wouldn't be able to do 
  58. anything that I can't do now.  The only advantage is that I'd save a bit of 
  59. typing.  
  60.  
  61. On the other hand, it would be a far reaching change that would 
  62. affect the language in lots of little ways.  Right now, declarations 
  63. are declarations, they aren't executable statements.  You're suggesting 
  64. that the distinction be blurred.  
  65.  
  66. >  This is exactly why I like the C++ approach.  With automated
  67. >  construction/destruction, operator overloading, etc, objects are
  68. >  much more seamlessly integrated into an application as extensions
  69. >  of the basic data types.  Once the class is properly defined, the
  70. >  programmer never has to consider the objects as anything except
  71. >  predefined atomic stuctures again.
  72.  
  73. On the other hand, it seems that it would be rather inefficient in lots of 
  74. code.  For example, I often write routines that need to do calculations 
  75. before they can call the constructor for an object; if it had already been 
  76. constructed, would I have to destroy it before changing it?  A simple 
  77. example would be reading a matrix from a file:  I might read a line to get 
  78. the matrix dimensions, construct an appropriate matrix, and then read the 
  79. data into it.  How are situations like that handled with automatic 
  80. constructors?  Or is the automatic construction optional?  If so, that just 
  81. leads to code equivalent to the TP code.
  82.  
  83. Duncan Murdoch
  84. dmurdoch@mast.queensu.ca
  85.