home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!clarkson!news
- From: kooijman@sun.soe.clarkson.edu (Harry Kooijman,Peyt314a,3808)
- Subject: Re: BP/TP OOP is missing something...
- Message-ID: <1992Nov17.200839.342@news.clarkson.edu>
- Sender: news@news.clarkson.edu
- Nntp-Posting-Host: sun.soe.clarkson.edu
- Organization: Clarkson University
- References: <dmurdoch.282.722020256@mast.queensu.ca>
- Date: Tue, 17 Nov 1992 20:08:39 GMT
- Lines: 61
-
- From article <dmurdoch.282.722020256@mast.queensu.ca>, by dmurdoch@mast.queensu.ca (Duncan Murdoch):
- > In article <1992Nov17.153804.21729@news.clarkson.edu> kooijman@sun.soe.clarkson.edu (Harry Kooijman,Peyt314a,3808) writes:
- >>Why is it that TP with objects does not have the capability to call the
- >>constructors when variables are declared? And when an object goes out of
- >>scope it should be destructed automatically. For example:
- >>
- >>Function DoSomethingWithD;
- >>Var D:DoubleObject(1.2);
- >>Begin
- >> ...
- >> Do something with D
- >> ...
- >>End; {and here D gets destructed}
- >
- > This is there in TP, to a very limited extent: you can have an initialized
- > variable which is an object, and you needn't call the constructor. It's
- > initialized at program load time, not each time the variable comes into
- > scope. The destructor is never called.
- >
- > I think the main reason that TP doesn't have automatic constructor/
- > destructor calls is because it is descended from Pascal. In Pascal in
- > general, code doesn't get executed unless you explicitly ask for it.
- > Adding automatic code would be a big change to the flavour of the language.
- >
- > It's pretty unlikely that Borland would make such a fundamental change
- > that doesn't add any power to the language. Your code fragment is exactly
- > equivalent to
- >
- > var D:DoubleObject;
- > begin
- > D.init(1.2);
- > ...
- > D.done;
- > end;
- >
- > Since what you want to do is already possible with nothing more than a
- > couple of extra lines of code, why make a big change to the language?
- >
- > Duncan Murdoch
- > dmurdoch@mast.queensu.ca
-
- It is this couple of extra lines that make the difference between using
- objects or not. With explicit calls to the constructor/destructor I can
- write exactly the same code without objects, and loose all the object
- overhead. What if you are adding a vector in a subroutine declaration
- list, write the constructor, and use it, but forget to destruct it (an
- o so easy and common bug): you start loosing heap. What if you forget
- the constructor (worse!) ? If you have only a couple of vectors to
- worry about you will probably not make this mistake. However if you are
- dealing with 15 vectors and 15 matrices in one routine it becomes a
- different matter. And that's why automatic construction and destruction
- takes me further.
-
- Your comment about Pascal's flavour is well taken. I have little hope
- for any change.
-
- Harry
- --
- Harry Kooijman: Rigorous dynamic distillation simulation.
- Dept. of Chemical Engineering, Clarkson University, Potsdam NY 13699.
- kooijman@sun.soe.clarkson.edu
-