⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drdobbs-interview.html

📁 这个帮助文档就不需要解释了
💻 HTML
📖 第 1 页 / 共 3 页
字号:
an object with a copy constructor out of another object, the twoobjects should be equal.  C++ does not mandate this, but this isone of the fundamental laws that we must obey.  Assignment has tocreate equal objects.  So I presented a bunch of axioms thatconnected these basic operations.  I talked a little bit aboutaxioms of iterators and showed some of the generic algorithmsworking on iterators.  It was a two-hour talk and, I thought,rather dry.  However, it was very well received.  I didn't thinkat that time about using this thing as a part of the standardbecause it was commonly perceived that this was some kind ofadvanced programming technique which would not be used in the&quot;real world&quot;.  I thought there was no interest at all in any ofthis work by practical people.</P><P>     I gave this talk in November, and I didn't think about ANSIat all until January.  On January 6 I got a mail message fromAndy Koenig, who is the project editor of the standard document,saying that if I wanted to make my library a part of thestandard, I should submit a proposal by January 25.  My answerwas, &quot;Andy, are you crazy?&quot; to which he answered, &quot;Well, yes I amcrazy, but why not try it?&quot;</P><P>    At that point there was a lot of code but there was nodocumentation, much less a formal proposal.  Meng and I spent 80-hour weeks to come up with a proposal in time for the mailingdeadline.  During that time the only person who knew it wascoming was Andy.  He was the only supporter and he did help a lotduring this period.  We sent the proposal out, and waited.  Whiledoing the proposal we defined a lot of things.  When you writethings down, especially when you propose them as a standard, youdiscover all kinds of flaws with your design.  We had to re-implement every single piece of code in the library, severalhundred components, between the January mailing and the nextmeeting in March in San Diego.  Then we had to revise theproposal, because while writing the code, we discovered manyflaws.</P><P><B>Can you characterize the discussions and debate in the committeefollowing the proposal?  Was there immediate support?Opposition?</B></P><P>     We did not believe that anything would come out of it.  Igave a talk, which was very well received.  There were a lot ofobjections, most of which took this form: this is a hugeproposal, it's way too late, a resolution had been passed at theprevious meeting not to accept any major proposals, and here isthis enormous thing, the largest proposal ever, with a lot oftotally new things.  The vote was taken, and, interestinglyenough, an overwhelming majority voted to review the proposal atthe next meeting and put it to a vote at the next meeting inWaterloo, Ontario.</P><P>     Bjarne Stroustrup became a strong supporter of STL.  A lotof people helped with suggestions, modifications, and revisions.Bjarne came here for a week to work with us.  Andy helpedconstantly.  C++ is a complex language, so it is not always clearwhat a given construct means.  Almost daily I called Andy orBjarne to ask whether such-and-such was doable in C++.  I shouldgive Andy special credit.  He conceived of STL as part of thestandard library.  Bjarne became the main pusher of STL on thecommittee.  There were other people who were helpful:  MikeVilot, the head of the library group, Nathan Myers of Rogue Wave,Larry Podmolik of Andersen Consulting.  There were many others.</P><P>     The STL as we proposed it in San Diego was written inpresent C++.  We were asked to rewrite it using the new ANSI/ISOlanguage features, some of which are not implemented.  There wasan enormous demand on Bjarne's and Andy's time trying to verifythat we were using these non-implemented features correctly.</P><P>    People wanted containers independent of the memory model,which was somewhat excessive because the language doesn't includememory models.  People wanted the library to provide somemechanism for abstracting memory models.  Earlier versions of STLassumed that the size of the container is expressible as aninteger of type <tt>size_t</tt> and that the distance between twoiterators is of type <tt>ptrdiff_t</tt>. And now we were told, why don'tyou abstract from that?  It's a tall order because the languagedoes not abstract from that; C and C++ arrays are notparameterized by these types.  We invented a mechanism called&quot;allocator,&quot; which encapsulates information about the memorymodel.  That caused grave consequences for every component in thelibrary.  You might wonder what memory models have to do withalgorithms or the container interfaces.  If you cannot use thingslike <tt>size_t</tt>, you also cannot use things like <tt>T*</tt>  because ofdifferent pointer types (<tt>T*</tt>, <tt>T huge *</tt>, etc.).  Then you cannotuse references because with different memory models you havedifferent reference types.  There were tremendous ramificationson the library.</P><P>    The second major thing was to extend our original set of datastructures with associative data structures.  That was easier,but coming up with a standard is always hard because we neededsomething which people would use for years to come for theircontainers.  STL has from the point of view of containers, a veryclean dichotomy.  It provides two fundamental kinds of containerclasses: sequences and associative containers.  They are likeregular memory and content-addressable memory. It has a cleansemantics explaining what these containers do.</P><P>    When I arrived at Waterloo, Bjarne spent a lot of timeexplaining to me that I shouldn't be concerned, that most likelyit was going to fail, but that we did our best, we tried, and weshould be brave.  The level of expectation was low.  We expectedmajor opposition.  There was some opposition but it was minor.When the vote was taken in Waterloo, it was totally surprisingbecause it was maybe 80% in favor and 20% against.  Everybodyexpected a battle, everybody expected controversy.  There was abattle, but the vote was overwhelming.</P><P><B>What effect does STL have on the class libraries published in theANSI/ISO February 1994 working paper?</B></P><P>     STL was incorporated into the working paper in Waterloo.The STL document is split apart, and put in different places ofthe library parts of the working paper.  Mile Vilot isresponsible for doing that.  I do not take active part in theeditorial activities.  I am not a member of the committee butevery time an STL-related change is proposed, it is run by me.The committee is very considerate.</P><P><B>Several template changes have been accepted by the committee.Which ones have impact on STL?</B></P><P>     Prior to the acceptance of STL there were two changes thatwere used by the revised STL.  One is the ability to havetemplate member functions.  STL uses them extensively to allowyou to construct any kind of a container from any other kind of acontainer.  There is a single constructor that allows you toconstruct vectors out of lists or out of  other containers.There is a templatized constructor which is templatized on theiterator, so if you give a pair of iterators to a containerconstructor, the container is constructed out of the elementswhich are specified by this range.  A range is a set of elementsspecified by a pair of iterators, generalized pointers, oraddresses.  The second significant new feature used in STL wastemplate arguments which are templates themselves, and that's howallocators, as originally proposed, were done.</P><P><B>Did the requirements of STL influence any of the proposedtemplate changes?</B></P><P>     In Valley Forge, Bjarne proposed a significant addition totemplates called &quot;partial specialization,&quot; which would allow manyof the algorithms and classes to be much more efficient and whichwould address a problem of code size.  I worked with Bjarne onthe proposal and it was driven by the need of making STL evenmore efficient. Let me explain what partial specialization is.At present you can have a template function parameterized byclass T called <tt>swap(T&amp;, T&amp;)</tt>  and swaps them.  This is the mostgeneric possible <tt>swap</tt>.  If you want to specialize <tt>swap</tt> and dosomething different for a particular type, you can have afunction <tt>swap(int&amp;, int&amp;)</tt>, and which does integer swapping insome different way.  However it was not possible to have anintermediate partial specialization, that is, to provide atemplate function of the following form:<pre>  template &lt;class T&gt; void swap(vector&lt;T&gt;&amp;, vector&lt;T&gt;&amp;);</pre>This form provides a special way to swap vectors.  This is animportant problem from an efficiency point of view.  If you swapvectors with the most generic <tt>swap</tt>, which uses three assignments,vectors are copied three times, which takes linear time.However, if we have this partial specialization of <tt>swap</tt> forvectors that swap two vectors, then you can have a fast, constanttime operation, that moves a couple of pointers in the vectorheaders.  That would allow <tt>sort</tt>, for example, to work on vectorsof vectors much faster.  With the present STL, without partialspecialization, the only way to make it work faster is for anyparticular kind of <tt>vector</tt>, such as <tt>vector&lt;int&gt;</tt>, to define its own<tt>swap</tt>, which can be done but which puts a burden on theprogrammer.  In very many cases, partial specialization wouldallow algorithms to be more effective on some generic classes.You can have the most generic <tt>swap</tt>, a less generic <tt>swap</tt>, an evenless generic <tt>swap</tt>, and a totally specific <tt>swap</tt>.  You can dopartial specialization, and the compiler will find the closestmatch.  Another example is <tt>copy</tt>.  At present the <tt>copy</tt> algorithmjust goes through a sequence of elements defined by iterators andcopies them one by one.  However, with partial specialization wecan define a template function:<pre>  template &lt;class T&gt; T ** copy(T**,T**,T**);</pre>This will efficiently copy a range of pointers by using <tt>memcpy</tt>,because when we're copying pointers we don't have to worry aboutconstruction and destruction and we can just move bits with<tt>memcpy</tt>.  That can be done once and for all in the library and theuser doesn't need to be concerned.  We can have particularspecializations of algorithms for some of the types.  That was avery important change, and as far as I know it was favorablyreceived in Valley Forge and will be part of the Standard.</P><P><B>What kinds of applications beyond the standard class librariesare best served by STL ?</B></P><P>     I have hopes that STL will introduce a style of programmingcalled generic programming.  I believe that this style isapplicable to any kind of application, that is, trying to writealgorithms and data structures in the most generic way.Specifying families or categories of such structures satisfyingcommon semantic requirements is a universal paradigm applicableto anything.  It will take a long time before the technology isunderstood and developed.  STL is a starting point for this typeof programming.</P><P>     Eventually we will have standard catalogs of genericcomponents with well-defined interfaces, with well-definedcomplexities.  Programmers will stop programming  at the microlevel.  You will never need to write a binary search routineagain. Even now,  STL provides several binary search algorithmswritten in the most generic way.  Anything that is binary-searchable can be searched by those algorithms.  The minimumrequirements that the algorithm assumes are the only requirementsthat the code uses.  I hope that the same thing will happen forall software components.  We will have standard catalogs andpeople will stop writing these things.</P><P>    That was Doug McIlroy's dream when he published a famouspaper talking about component factories in 1969.  STL is anexample of the programming technology which will enable suchcomponent factories.  Of course, a major effort is needed, notjust research effort, but industrial effort to provideprogrammers with such catalogs, to have tools which will allowpeople to find the components they need, and to glue thecomponents together, and to verify that their complexityassumptions are met.</P><P><B>STL does not implement a persistent object container model.  The<tt>map</tt> and <tt>multimap</tt> containers are particularly good candidates forpersistent storage containers as inverted indexes into persistentobject databases.  Have you done any work in that direction orcan you comment an such implementations?</B></P><P>     This point was noticed by many people.  STL does notimplement persistence for a good reason.  STL is as large as wasconceivable at that time.  I don't think that any larger set ofcomponents would have passed through the standards committee.But persistence is something that several people thought about.During the design of STL and especially during the design of theallocator component, Bjarne  observed that allocators, whichencapsulate memory models, could be used to encapsulate apersistent memory model. The insight was Bjarne's, and it is animportant and interesting insight.  Several object databasecompanies are looking at that. In October 1994 I attended ameeting of the Object Database Management Group. I gave a talk onSTL,  and there was strong interest there to make the containerswithin their emerging interface to conform to STL. They were notlooking at the allocators as such. Some of the members of theGroup are, however, investigating whether allocators can be usedto implement persistency. I expect that there will be persistentobject stores with STL-conforming interfaces fitting into the STLframework within the next year.</P><P><B><tt>Set</tt>,<tt> multiset</tt>, <tt>map</tt>, and <tt>multimap</tt> are implemented with a red-blacktree data structure. Have you experimented with other structuressuch as B*trees?</B></P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -