Article View: pl.comp.objects
Article #16170Re: Typ należ?cy do parametru template'a (czyli STL w parametrze)
From: Adam Karpierz
Date: Tue, 10 Apr 2007 13:29
Date: Tue, 10 Apr 2007 13:29
73 lines
5389 bytes
5389 bytes
Użytkownik "A.L." <fela@2005.com> napisał: > Bylo o tym pisane przy okazji wywiadu z jednym z C++/MS gurus albo w > czasopismie Dr. Dobbs Journal albo Programming Languages (oba juz nie > istnieja, niestety) bardzo dawno temu. Mam w piwnicy, ale pardon, nie > bede szukal w ktorym numerze... Odpryski niegdysiejszych dyskusji/sporow o NIHL <> That remark leads straight into this month's next C++ book, the long-awaited Data Abstraction and Object-Oriented Programming in C++ by Keith Gorlen, Sanford Orlow, and Perry Plexico. Gorlen et al. discuss how to stretch C++ as far as it will go in the direction of object-oriented languages such as Smalltalk, and away from the language's machine-oriented C heritage. This book is based on the the NIH Class Library, a Smalltalk-like class library for C++, which the authors developed as part of a project involving biomedical research on Unix-based workstations at the National Institutes of Health (NIH). The NIH Class Library addresses a very real problem: C++ compilers do not come with extensive class libraries. If you need a LinkedList class, you write it (or borrow the one from Shapiro's book!). If you want the += operator to signify concatenation when applied to a string, then you have to write a String class with an operator+=( ) member function. C++ gives you the mechanisms, but after that you're on your own. Fundamentally, C++ is still C. C++ programmers can be jealous of programmers using object-oriented languages such as Smalltalk, which come with extensive class libraries. When you buy Digitalk Smalltalk/V, you get a massive class hierarchy. When you buy a C++ compiler, you get iostream.h. I am convinced that this Spartan approach, remaining true to the language's C origins, is precisely why C++ has succeeded. It is a compromise between C on the one hand and object-oriented programming on the other. But that doesn't change the fact that you need a class library. The NIH Class Library brings some of the flavor of Smalltalk to C++; its class hierarchy has Object at the top, a Collection class underneath that, a Bag class underneath that, and so on. If you have Turbo C++ or the newer Borland C++, note that the sample CLASSLIB is a scaled-down implementation of this same idea. >From the guided tour of the NIH Class Library given by Gorlen et al., I got the sense that C++ provides just enough object-oriented features to be tempting, but not enough to really work. How could it? C++ is still C. For example, the constructor for a BigInt class must nonintuitively take a string of digits because "this is the only way we can legally write very large integer constants in C++" (p. 34). You can't write BigInt n = 18446744073709551615 because that number has 20 digits and is not a legal integer constant in C--I mean, C++. Nor can you overload operator^( ) to mean exponentiation and check if (n== 2^64 - 1) because in C--I mean in C++, the ^ operator is unary not binary. This sort of restriction means that the promises of C++ often can't be fulfilled. One promise is that with operator overloading, we can give "an easily readable, 'mathematical' appearance" to mathematics programs (p.96). I believe that the NIH Class Library comes as close as possible to this goal, but it can't succeed, because C++ does not provide a free-form collection of overloadable operators. C++ seems to hold out the promise of working at a higher level, only to pull you up short at the last minute with a stern reminder that this is still C. Restrictions of this sort are necessary if C++ is to remain a serious tool for developing commercial software. The authors of the NIH Class Library show what can be done within these restrictions. In addition to reading their book, you can get the NIH Class Library source code, either from the publisher (an additional $16.95) or by downloading it from BIX (listings area c.plus.plus; files nih30.zip, nih30.inf, and cppoops.zip). This is probably the largest collection of public C++ source code available, and is well worth examining. <> AK
Technical Details
Message-ID:
<evg3ih$pri$1@inews.gazeta.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mailReferences:
<slrnf1kjcu.ave.lrem@lrem.maxnet> <evdlhb$f4p$1@inews.gazeta.pl> <evdqq6$qrs$3@news.onet.pl> <desk13psu2rvekht584uoirc0djahrk1dv@4ax.com> <87irc5fnin.fsf@hector.domek> <4u0l13p53mf3nous2u96ulgidcqovr6p5n@4ax.com> <eve28a$4kl$1@inews.gazeta.pl> <jncl135635jksqfark25n0nh1o7epvq1jg@4ax.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mail From: "Adam Karpierz" <karpierz@_NOSPAM_python.pl> Newsgroups: pl.comp.objects Subject: Re: Typ należ?cy do parametru template'a (czyli STL w parametrze) Date: Tue, 10 Apr 2007 15:29:33 +0200 Organization: "Portal Gazeta.pl -> http://www.gazeta.pl" Lines: 75 Message-ID: <evg3ih$pri$1@inews.gazeta.pl> References: <slrnf1kjcu.ave.lrem@lrem.maxnet> <evdlhb$f4p$1@inews.gazeta.pl> <evdqq6$qrs$3@news.onet.pl> <desk13psu2rvekht584uoirc0djahrk1dv@4ax.com> <87irc5fnin.fsf@hector.domek> <4u0l13p53mf3nous2u96ulgidcqovr6p5n@4ax.com> <eve28a$4kl$1@inews.gazeta.pl> <jncl135635jksqfark25n0nh1o7epvq1jg@4ax.com> NNTP-Posting-Host: dns.welnowiec.net X-Trace: inews.gazeta.pl 1176211857 26482 83.143.96.1 (10 Apr 2007 13:30:57 GMT) X-Complaints-To: usenet@agora.pl NNTP-Posting-Date: Tue, 10 Apr 2007 13:30:57 +0000 (UTC) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-Priority: 3 X-RFC2646: Format=Flowed; Original X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-User: karpierz X-MSMail-Priority: Normal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit