Path: news.daimi.aau.dk!news.uni-c.dk!sunic!sunic.sunet.se!newsfeed.tip.net!news.seinf.abb.se!nooft.abb.no!Norway.EU.net!EU.net!howland.reston.ans.net!newsfeed.internetmci.com!news.mathworks.com!fu-berlin.de!zrz.TU-Berlin.DE!marie!wpp From: wpp@marie.physik.tu-berlin.de (Kai Petzke) Newsgroups: comp.lang.beta Subject: Re: Templates Date: 29 Aug 95 20:15:34 GMT Organization: Technical University Berlin, Germany Lines: 100 Message-ID: References: NNTP-Posting-Host: marie.physik.tu-berlin.de kolbjorn.aambo@ub.uio.no (Kolbjørn Aambø) writes: >I found a very interesing little feature in C++ that I have not been seeing >in beta ..... C++ have templates which make it possible to implement one >generic binary tree and then insert anything in it that have <, =, > >operators implemented for it. What seems vacant in beta is both templates >and operator overloading.... Operator overloading and function overloading are both not present in BETA. Many people see this as a disadvantage. Especially many library programmers want their libraries to be as easy to use as possible. And if you write a class library, for, say complex numbers, it is quite usefull, if the user of that library can later type "A + B", as if A and B were ordinary numbers. My experience is, that BETA does not focus on writing libraries or writing class libraries. Rather, it focusses on writing systems. Systems are (most times singular) objects, that are suited for handling certain operations, like arithmatic operations with complex numbers. Chapter 12 of the BETA book has a nice example for this. You may argue, that, from an end-users point of view, such a system is harder to handle than a library. Indeed, it is. But the system is more flexible. It leaves the end user more alternatives for extension than a class library. Your other point, that BETA does not have templates, is void in my opinion. BETA's virtual patterns allow almost all uses, that you can use templates for. In your application, I would go with the following scheme: cardinal_object: (# mytype:< cardinal_ojbect; compare:< (# other: ^mytype; result: @integer enter other[] do INNER exit result #); #) binary_tree: (# element:< cardinal_object; ... #); Then define the cardinal_objects, that you need: simple_number: cardinal_object (# mytype:: simple_number; value: @integer; compare:: (# do (if true // other.value > value then 1->result // other.value < value then -1->result else 0->result if) #) #) number_tree: binary_tree (# elemnt:: simple_number #); It is not simple. It has its odds and ends, like that you have to write that stupid compare functions several times, and that things break apart, if you forget to redefine the mytype virtual in the subclass. However, your solution (templates and overloaded operators in C++) is not perfect either. You can use only those classes in the binary tree, that have meaningfull relational operators defined. If you want to order objects of classes, that don't have that operators, or if you want to order by more than one property (say, you have a class person, and want to have two trees, one sorted by name and one sorted by age) you have to define your particular "wrapper" classes, that have nothing but a pointer to the real thing and the overloaded relational operators. So in the end, C++ turns out to be more nifty than BETA in a few simple cases. >It's not a particularly good alternative to >subclass a pattern "object" and overloading virtual operators GT,EQ, LT which >are not even infix operators..... Do we have something for future implementation >or du we have a passé minority language that are never up-to-date with the >user-interface libraries of the different platforms? Flaming is easy, isn't it? Kai -- Kai Petzke, Technical University of Berlin, Germany http://www.physik.tu-berlin.de/~wpp/ to learn about Linux, Postgres and BETA. wpp@marie.physik.tu-berlin.de for regular e-mail How fast can computers get? -- Warp 9, of course, on Star Trek.