Formats of coding !

Started by
62 comments, last by Metal Typhoon 20 years, 4 months ago
hm. that age_str is not an age_string, its just an input string. you have to validate then if it really represents an age..

std::string userInput;std::cin >> userInput;int age;try {    age = boost::lexical_cast(userInput);} catch(boost::bad_lexical_cast& /*or something similar?!*/) {    // its a long time i''ve coded in c++, sorry..    std::cout<<"You''ve entered an invalid age!!\n";} 




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Advertisement
quote:Original post by CWizard
Well, using any sort of notation doesn't make that notation HN. I do sometimes also include vague type information in my variable names, eg:

std::string age_str;
std::cin >> age_str;
int age_int = atoi(age_str.c_str());

However, that doesn't make it HN.



okay perhaps its not "hungarian notation" in the truest sense, but its still there for the same thing, to somehow identify type based on variable name. Now why do you feel that its nescessary in that case, and not nescessary in every other case?

Personally i feel whatever standard you feel comfortable with (or whatever is enforced by your employer) the most important thing is consistency, if you prefix or suffix your variable then prefix/suffix ALL of them, dont just do it partially.

And for those who believe that "typing" variable names is pointless, how much harder would it be to spot the following bugs without any form of type info in the variable names?

while (u32counter >= 0) dosomething();s8value = 126;...s8value++;...s8value++;fVal = fabs(u16Val/65536);   


etc etc


[edited by - Narcist on December 16, 2003 7:42:45 AM]
Everybody bashing clean notation?
c''mon - it''s just a helper. Reading code using pre-/suf-fixes shouldnt make much difference to people not using them, and can be very helpful to people using them.

My selection:

// Standard typesfloat fFloat;bool bBool;void* pPointer;void (*pfnFunctionPointer)(int,float);int nNumberOfElements; /* Used for keeping track of number of elements in an array, for example */int iIndexIntoAnArray;int dStandardInteger;int m_dStupidMemberInteger;// Constructsclass pfx_Class{};struct pfx_Struct{};enum pfx_XXXXType{}; 


pfx_ is actually the prefix for all engine constructs - yeah, i know a namespace would be nicer...but...anyways
No special prefix for interfaces, btw
I use enumerations almost exclusively for enumerating types - thats why they are suffixed with ''Type''
e.g.
enum pfx_XmlNodeType {...};

*waiting_to_be_flamed*
Sometimes you lose, and sometimes your opponents win.
i just don''t see any use for it. code is more clean when it only contains what is really needed to identify what it does. types are unimportant for that..

and s8++ doesn''t normally show that its an overflow. thats no help.

people still typing their variables don''t get that their code should be typeless. algorithms and concepts work, no mather really what sort of type they use.

just learn to use templates, and voilà, you''ll drop all the prefixes..

template max(a,b) { if(a > b) return a; return b; } 


you can''t prefix those variables at all. (oh, and, yeah, _THAT_ would be cool template syntax, not?:D)

as i code a lot of code split from types, so that i can easily remap it to other types, and only change minor interface changes, i have about no use for prefixes. i would only have to change them all the time anyways.



they are useless. you manually restrict your code to things that don''t mather.



If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

This topic is closed to new replies.

Advertisement