Re: BRAT-2-9-9.

From: Christian Holm Christensen (cholm@hehi03.nbi.dk)
Date: Mon Aug 04 2003 - 05:06:33 EDT

  • Next message: Flemming Videbaek: "Brat update"
    Hi Flemming, Bjorn, et al.
    
    "Flemming Videbaek" <videbaek@sgs1.hirg.bnl.gov> wrote concerning
      Re: BRAT-2-9-9. [Fri, 1 Aug 2003 13:39:45 -0400] 
    ----------------------------------------------------------------------
    > Hi Jens Ivar,
    > thanks for the work. Of course for internal arrays inside code you
    > are better off  IMHO by using STL e.g. like
    > 
    > vector <Int_t> Expandable;
    > ..
    > expandable.push_back(next value)
    > 
    > This way you do not have to keep track of any resizing the resize is
    > done automaticaly and you know at any given time what it is. And the
    > content can be any kind of object. 
    
    I completely agree (some may remember I once said quite the opposite,
    but since then, I've learnt to appreciate the wonders of templates,
    and I've changed stand on this :-), and I only wish that ROOT (and in
    particularly would support templates better.  
    
    
    Also, I'd like to point out, that the different Standard Library
    containers have different semantics, and it's worth considering these
    when choosing what kind of container to use. 
    
    I'd argue that ROOT should use templates a lot more than it
    does - it would really clean up the code.  Consider
    
      template <typename XType, typename YType=XType) 
      class TH1;
    
      template <typename Type>
      class TClonesArray { 
        ... 
        Type* At(size_t i);
      }
    
    versus 
    
      class TH1S; class TH1I; class TH1F, class TH1D; ...
      class TClonesArray { 
        ... 
        TObject At(size_t i);
      };
    
    Much nicer code, and a lot better for the novice and casual developer,
    as it's type-safe. 
    
    We could use templated members, like 
    
      class BrDcWhatEver { 
        ...
        std::vector<BrDcWhatEverAgain> fWhatevers;
      };
    
    if we make sure to use instantiate the template in a LinkDef.h file. 
    
    What ROOT also should use a lot more, is smart pointers.  A smart
    pointer is a wrapper class (actually most often a struct) that behaves
    like a pointer, but offers more referential safety, copy semantics,
    and so on.  The only smart pointer in the standard library is 
    `std::auto_ptr<typename Type>', which isn't that clever.  All it does,
    is that when you copy a `auto_ptr' is to transfer ownership of the
    contained object to the new copy: 
     
      int* a = new int;
      std::auto_ptr<int> b(a);
      std::auto_ptr<int> c(b); // Now owns a - that is, deletes a in dtor. 
      std::cout << *a << std::endl; // Writes out what a points to
    
    However, smart pointers can be regular Einsteins: You can make them do
    reference counting, checks for null-memory, encapsulate thread
    locking, and so on.  Really clever thing.  
    
    [Some may remember Objectivity - that uses smart pointers to ensure
    valid references in to the database - quite clever.  However, the rest
    is pure bollocks.]
    
    I think I've said it before, but these very cool thing of templates
    coupled with the Object-Oriented paradigm and fast execution time,
    makes C++ a truly powerful language - much more than say Java,
    Python, SmallTalk, Ada, and <shudder>C#</shudder>.  I'd argue that C++ is
    in fact a sort of super-language to these sub-languages.  All you can
    do in Java, C#, SmallTalk, Ada, Python, Perl, C, Fortran77/90/95,
    Simula, Modula, Basic, etc. you can do in C++, and then a whole lot
    more.  I think the only language I have to exclude from that list, is
    Intercal - after all, C++ does not sport probabilistic execution of
    statements or the `COME FROM' statement :-)
    
    Some of you may argue, that C++ is missing a lot of what Java, Ada,
    SmallTalk, C#, and what not has in terms of library support.  Well, if
    you take a look at the web, I think you can pretty much find C++ class
    libraries for just about anything you need.  And if not, you can
    always use the C library directly (or write a wrapper :-).  
    
    All in all, I think we should be glad that we've chosen C++, and not
    some sub-set of it (C, Java, C#, SmallTalk, Ada, Fortran, etc.). 
    
    > just my few cents worth of philosophy.
    
    And then me rambling :-) 
     
    Yours, 
    
     ___  |  Christian Holm Christensen 
      |_| |	 -------------------------------------------------------------
        | |	 Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
         _|	          DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
        _|	          Denmark                    Office: (+45) 353  25 305
     ____|	 Email:   cholm@nbi.dk               Web:    www.nbi.dk/~cholm
     | |
    


    This archive was generated by hypermail 2.1.5 : Mon Aug 04 2003 - 05:07:44 EDT