typedef every where

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Wessle

    typedef every where


    Hi
    my toy project is spanning few files already, typing is becoming an
    issue, is it acceptable practice to do the following globally?
    typedef vector<doublevd ;
    typedef vector<pair<cha r,double vpcd;

    thanks
  • Phlip

    #2
    Re: typedef every where

    Gary Wessle wrote:
    my toy project is spanning few files already, typing is becoming an
    issue, is it acceptable practice to do the following globally?
    typedef vector<doublevd ;
    typedef vector<pair<cha r,double vpcd;
    Name the typedef, like any identifier, after its intent. Don't fold typedefs
    together just because their internal types are the same. To whit:

    typedef std::vector<dou bleshoeSizes_t;
    typedef std::vector<dou bleseismograph_ t;

    And put them inside the class or namespace that uses them.

    --
    Phlip
    http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!


    Comment

    • Howard

      #3
      Re: typedef every where


      "Gary Wessle" <phddas@yahoo.c omwrote in message
      news:87vepa95e6 .fsf@localhost. localdomain...
      >
      Hi
      my toy project is spanning few files already, typing is becoming an
      issue, is it acceptable practice to do the following globally?
      typedef vector<doublevd ;
      typedef vector<pair<cha r,double vpcd;
      >
      Depends on who it needs to be acceptable to, I guess. :-)

      One issue I'd have is that those names are completely unintelligible unless
      you know in advance what they mean. Come back next year, and you'll wonder
      "what the heck is a 'vpcd'?".

      Something like DoubleVector and CharDoublePairV ector might be more
      descriptive. Of course, if all you're trying to gain is less typing, then
      that's not saving much. But I rarely base decisions on how much or little
      I'll have to type; instead, I go for clarity.

      Also, a vector of recorded race times and a vector of space-time coordinates
      (for example) may each be a vector of doubles, but wouldn't it make more
      sense to have (say) a RaceTimesVector type and a CoordinatesVect or type?
      It's like a class: you don't call your class "csi" simply because it's a
      class containing a string and an int. You name it what it is, something
      more like "Competitor " or "PlanetDescript ion".

      -Howard



      Comment

      • Roland Pibinger

        #4
        Re: typedef every where

        On 03 Aug 2006 07:47:29 +1000, Gary Wessle <phddas@yahoo.c omwrote:
        >Hi
        >my toy project is spanning few files already, typing is becoming an
        >issue, is it acceptable practice to do the following globally?
        typedef vector<doublevd ;
        typedef vector<pair<cha r,double vpcd;
        Using typedefs to shorten names is IMHO bad style. You just lose the
        type information.

        Best wishes,
        Roland Pibinger

        Comment

        • Phlip

          #5
          Re: typedef every where

          Roland Pibinger wrote:
          Using typedefs to shorten names is IMHO bad style. You just lose the
          type information.
          Typedeffing template instantiations is excellent style. Not only does it
          convert the type information (that the compiler will enforce anyway) into a
          meaningful name, but it also defines the template's instatiation point. Such
          a typedef is more than just an alias; it also locks in all the identifiers
          that the template definitions see.

          --
          Phlip
          http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!


          Comment

          • Howard

            #6
            Re: typedef every where


            "Phlip" <phlipcpp@yahoo .comwrote in message
            news:rN9Ag.544$ o27.340@newssvr 21.news.prodigy .com...
            Roland Pibinger wrote:
            >
            >Using typedefs to shorten names is IMHO bad style. You just lose the
            >type information.
            >
            Typedeffing template instantiations is excellent style. Not only does it
            convert the type information (that the compiler will enforce anyway) into
            a meaningful name, but it also defines the template's instatiation point.
            Such a typedef is more than just an alias; it also locks in all the
            identifiers that the template definitions see.
            >
            Provided the name actually _is_ meaningful. And 'vpcd' definitely is not.
            :-)

            -Howard



            Comment

            • Roland Pibinger

              #7
              Re: typedef every where

              On Wed, 02 Aug 2006 22:36:07 GMT, "Phlip" <phlipcpp@yahoo .comwrote:
              >Typedeffing template instantiations is excellent style. Not only does it
              >convert the type information (that the compiler will enforce anyway) into a
              >meaningful name,
              I beg to differ. 'vector<double> ' is certainly more meningful than
              'vd'. Typdedefs make sense when they have a conceptual purpose, eg.
              the typedefs for iterators in STL containers, not to merely 'shorten'
              names.
              >but it also defines the template's instatiation point.
              ??
              >Such
              >a typedef is more than just an alias; it also locks in all the identifiers
              >that the template definitions see.
              I'm not familiar with all atrocities of the C++ Standard but I guess a
              typedef doesn't 'lock in' more than a (forward) declaration (otherwise
              it would even be an argument against 'typedef everywhere').

              Best wishes,
              Roland Pibinger

              Comment

              Working...