Naming conventions

Started by
36 comments, last by swiftcoder 19 years, 7 months ago
The .NET naming convention is easy to remember, if nothing else: Everything public uses PascalCase. Private attributes, parameters, and locals use camelCase.

The Java convention is a bit more... conventional: types use PascalCase, methods use camelCase, constants are IN_ALL_CAPS.
"There is only one everything"
Advertisement
I use pythonic_names in my Python (but not the leading _'s for private vars; when I get to the point that other people see my Python code, I will rethink things) and generally follow Java conventions when writing anything more C-like. Except that I'll also use pythonic_method_names in Java for the dirty hacks that I'm not proud of, something like "this smells like it wants its own class, but everything got seriously uglified in an optimization attempt." (*space* optimization, mind; I'm developing for J2ME. It takes a *lot* of manual switches to outweigh the class overhead, I'm rather disappointed actually :( )

IMHO humility is an important quality for a programmer (but so is pride :) ), and you should recognize the poorer-aesthetic bits of your work, and at least acknowledge them if you can't afford to fix them.
Quote:Original post by Boder
edit: why no C for class names?
Because it's ugly and serves no purpose at all.
harsh

Well so far it seems like no one has recommended including any sort of type information with variable names, apart from sometimes using g_ to destinguish global scope.

What if I design a class for my game and I only intend to have one instance (global) in my program. The class is very specific and only designed for one purpose. This way I don't have to resort to the_Class or myClass or g_Class when naming it.

resulting in..
CApplication Application;
Application.Run();

instead of..
Application myApplication;
myApplication.Run();

I also sometimes like to distinguish strings with a little s in front.
Convention 1: How your supposed to do it (i think)
ClassNames
variableNames
constant_Names
FunctionNames

Convention 2: How I do it
ClAsSNAmEs
vaRiAbLeNaMeS
cOnStAnT_NaMeS
FUnCtIoNNAmEs
class CClassCMember CCLass::member_CMember CCLass::Member()void CCLass::Member(CMember member)class IInterfaceSomeFunctionstruct SPODTypeenum Enum


I use I,C,S because it seems to irritates lots of people and because it doesn't interfere with my get/set pair naming scheme.
[size=2]
Quote:Original post by Boder
harsh

Well so far it seems like no one has recommended including any sort of type information with variable names, apart from sometimes using g_ to destinguish global scope.

What if I design a class for my game and I only intend to have one instance (global) in my program. The class is very specific and only designed for one purpose. This way I don't have to resort to the_Class or myClass or g_Class when naming it.

resulting in..
CApplication Application;
Application.Run();

instead of..
Application myApplication;
myApplication.Run();

I also sometimes like to distinguish strings with a little s in front.


um, why not just use lowercase for variable names, like in Java style
For my functions, variables and parameters, I switch between camelCase and lower_case depending on my mood at the time. I've been favouring lower_case lately, since IFindItToBeSoMuchMoreEasyToRead.

My private variables are suffixed with an underscore. I don't prefix them with underscores because identifiers with leading underscores are reserved for the implementation. Your header files could #define _x to mean anything.

For classes, I use UpperCase exclusively.

If I catch any of you using CClassName or lpalpszLines I will personally defenestrate you and your immediate family.
lol, I remember when someone used a lite version of hungarian, but then changed globals to locals, integers to statics, integers to floats, doubles to floats, etc. In the end, some conventions weren't changed so everything was even more confusing.

Xai's code looks just like mine. However, I sometimes don't even put a "_", such as numverts, numwhatever, prevkill, nextmove, etc... In fact, I sometimes use only a single letter (within functions only) when doing a complex algorithm. Once a human knows what that letter is for, it's SO much easier than, say, m_fSemiLongThing, scattered all over the place. Comments on the side of course [smile]
Well im one of those people that uses hungarian only in the Form of 'C'-Prefixes for classes and 'S'-Prefixes for structs.
I dont really think there should be a discussion on wether or not to use them.
They do nothing extremely bad and nothing extremely good.
I just like that:
- The code seems more organized
- the files in my compiler are automatically sorted to group classes.
- Structs tend to have public members while classes dont, so its not bad to be able to distinguish them.
A possible con is:
If I were to change a class to struct I have to rename.

Id say everybody how he wants. But saying 'C'-prefixes are devlish is rediculous in my opinion.

-CProgrammer

This topic is closed to new replies.

Advertisement