473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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<char,double vpcd;

thanks
Aug 2 '06 #1
6 1223
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<char,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<doubleshoeSizes_t;
typedef std::vector<doubleseismograph_t;

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

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Aug 2 '06 #2

"Gary Wessle" <ph****@yahoo.comwrote in message
news:87************@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<char,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 CharDoublePairVector 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 CoordinatesVector 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 "PlanetDescription".

-Howard

Aug 2 '06 #3
On 03 Aug 2006 07:47:29 +1000, Gary Wessle <ph****@yahoo.comwrote:
>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<char,double vpcd;
Using typedefs to shorten names is IMHO bad style. You just lose the
type information.

Best wishes,
Roland Pibinger
Aug 2 '06 #4
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!!!
Aug 2 '06 #5

"Phlip" <ph******@yahoo.comwrote in message
news:rN***************@newssvr21.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

Aug 3 '06 #6
On Wed, 02 Aug 2006 22:36:07 GMT, "Phlip" <ph******@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
Aug 3 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Vu Pham | last post by:
I think this problem relates to either c or c++ ( but I am not sure which one ) so I post to both of these news group. I am sorry if I did something wrong here. Is there any difference between...
11
by: cppaddict | last post by:
Hi, I recently started using typedefs and am curious if they are ever considered evil. In particular, I'm thinking of a situation where a typedef is used in a file but defined in another,...
13
by: Martin | last post by:
This post asks two questions, which I've illustrated in one C source file (see below), which clean compiles on my GNU compiler. 1. In K&R2, Section A8.9 it says "Declarations whose storage class...
12
by: vvv | last post by:
Hi All, Do we have anything in .NET which is equivalent to C++'s Typedef . Regards, Vasanth
36
by: felixnielsen | last post by:
What i really wanna do, is defining my own types, it doesnt really matter why. Anyway, i have run into some problems 1) typedef unsigned short U16; U16 test = 0xffffffff; // There should be a...
15
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! )...
17
by: Steve Carter | last post by:
Can someone please explain why the following is not possible? typedef foobar { int x; foobar *next; /* why can't we do this? */ }; Thanks
7
by: Logan Lee | last post by:
ORIGINAL CODE: typedef struct StackStruct *Stack; typedef void *StackElt; StackElt top(Stack thisStack); ANOTHER CODE: typedef struct StackStruct Stack; typedef void *StackElt;
1
by: sophia | last post by:
Dear all, the following are the differences b/w #define and typedef ,which i have seen in Peter van der lindens book. is there any other difference between thes two ? The right way to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.