Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / A Must Read IMHO - C++ Best Practices Article. Very GOOD! Naming Conventions etc.

Author
Message
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 27th May 2008 19:24
AHH!! I could have use that 3 weeks ago I just wrote one up for my company. Nice find though..
tobi453
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 27th May 2008 20:05
I can't agree with everything.



Why??? I think (!pname) is very elegant way.

FINAL VERSION RELEASED!!!!
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 27th May 2008 21:00
I can't agree with everything in the document either, but there is some good stuff in there.

Example: I used to be a stickler for my own version of hungarian notation - not weird "my own" just platform independant....

But with intellisense, and objects - I drop it because it tells me the data type, and the names are alphabetically listed - PLUS if I change the data type, I still find that "name" where it was before.

Now I still use my notation method... but only in areas where intellisense doesn't save the day....

My notation is basically....

s=string
sl=Large string (matters on database apps kinda - implementation specific... like maybe for strings >1024bytes... or 256 whatver...)
ss=Short String - again - usually only with database apps
sz=null terminated

a=array - So it looks vulgar with an array of short strings... LOL

i=integer - generic - platform specific
i1 = one byte int
i2 = two byte int
i4
i8 etc.

u1 - unsigned byte
u2
u4
u8 etc.

p_ = parameter like void MyFunction( int p_iMyParameter );

But... again... for stuff like a struct, a class etc... I make the members just the name only - without data type information... and I prefix things that are private usually with:
pvt_

ESPECIALLY because its FASTER to EXECUTE code that reads a variable versus calling a function... so sometimes I make private stuff public but I keep the pvt_ there so I know - HEY you have access to this BUT you better understand that class before you go mucking around with it.

??? What do I mean ???

int MyValue = MyClass->pvt_Value; //executes faster than

int MyValue = MyClass->Value_Get(); // Sweet... more overhead...stack involved.

--Jason

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 27th May 2008 21:20
Quote: "Example: I used to be a stickler for my own version of hungarian notation - not weird "my own" just platform independant....
"


Don't get me started on Hungarian notation. I tried to use it and all my identifiers started to look like personalized license plates. In truth I had difficulty determining if something was a pointer, a long pointer, short pointer or a Labrador Retriever. sz (zero terminated string) looked like it should have related to a size_t variable. And when you start combining things it got even worse. lpsz is a long pointer to a zero terminated string. Who cares if it's long or short, far or near? It's a pointer. That should be enough.

Then there's the act of putting "m_" in front of, what, class members? What if you wanted to name something in another class the same thing? Sure there's no collision, but putting "m_" as part of the identifier just tells me it's a member of some class. But which one?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 27th May 2008 21:54 Edited at: 27th May 2008 21:58
For seeing if a pointer is null I will always use:



As it makes it clear without using intellisense that you're comparing against a pointer, saying it sometimes errors is just stupid, if you don't have NULL defined then you define it :s.

If I'm comparing a variable that's defined as an int or something to a value that isn't 0 then I will likely use 'if ( !myLovelyint )' the only time I'd use '== 0' is if 'myLovelyInt' is a very long variable name or some function call, i.e. 'if ( hallo::something[plop]->somethingElse.pizza(omlette) == 0 )'.

Out of the three coding styles he pointed out at the top, the closest to the one I use is the .NET one, it's also the closest to virtually all C++ code I've seen. To me it just makes far more sense compared to the other two, underscores in things that aren't constants/enums, not starting function names with upper case, 8 space indentation.../me closes tab.

Dunno why you'd call it the best practices guide though, I've seen some more in-depth ones that make more sense and have justifications for the decisions, such as this, but no one's going to agree at the end of the day, everyone has their own slightly different style most of the time, thank Kosh for intellisense eh .

Login to post a reply

Server time is: 2024-09-29 21:25:54
Your offset time is: 2024-09-29 21:25:54