Jump to content
  • Advertisement
Sign in to follow this  
MrPickle

Capitalizing Variables

This topic is 3559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Usually when I see a capitalized variable, I presume it's a constant. I prefer to see naming conventions that work with what I am used to seeing.

Share this post


Link to post
Share on other sites
I prefer int foo; myself. You're probably better off using what you like best; this question usually ends in a debate about psychology.

Share this post


Link to post
Share on other sites
Quote:
Original post by MrPickle
I have got into a habit of capitalizing the variables and I wasn't sure whether it was a bad one?


Almost without exception, capitalized names are used for types, and sometimes functions.

Share this post


Link to post
Share on other sites
Standards (or concensus at best) are language specific. Java and C# have relatively well established standards relative to C++.

In general, consistency is most important. Whatever you do, stick with it. If you are working in someone elses code, follow their standards.

Do a search for camelcase to find discussions on various standards (I'm not advocating it specificly, but its a decent search keyword)

Share this post


Link to post
Share on other sites
My style, the way I have stuck for a good few years now:

Types - Prefixed and Capitalised.
Enums - 'e' Prefix, and enum values prefixed lowercase with capital shorthand.
Member Enums - Lowercase prefix dropped.
Variables - CamelCase. Pointers are exclusion to this rule and prefixed 'p'
Member Variables - Same rule applied + trailing underscore.
Global Variables - Prefixed 'g', otherwise same as Member Variables.
Methods - Lower case.
Global functions - Prefixed same as types.
Defines - Capitals (With a few exceptions to some macros)

And also - Doxygen, Doxygen, Doxygen.

Sample class and some functions from my engine's content system:


//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// From the H:
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////
/** \class CsArchive
* \brief Resource Archive.
*
* An archive to contain resources and provide runtime access to them.
*/

class CsArchive:
public BcThread // NOTE: This will be a worker thread interface soon.
{
public:
CsArchive();
~CsArchive();

/**
* Get a resource of a specific type.
* @param _Ty Class/Struct of resource.
* @param Name String name of resource in archive (no file extension).
* @return Pointer to resource class/struct.
*/

template< class _Ty >
_Ty* pResource( const BcChar* Name );

/**
* Get a raw resource of a specific type by its ID.
* @param Type Type of resource.
* @param ID ID of the resource.
* @return Pointer to raw resource.
*/

CsResource* pResourceByID( eResourceType Type, BcU32 ID );


/**
* Get user file packed into archive.
* @param Name of resource.
* @param Pointer to a BcU32 which will store the size.
* @return Pointer to raw data.
*/

BcU8* pFile( const BcChar* Name, BcU32* pSize = NULL );

/**
* Check if archive is ready to be used.
* @return BcTrue if archive is ready.
*/

BcBool isReady();

/**
* Check if archive is in error, ie, failed to load.
* @return BcTrue if in error.
*/

BcBool inError();

/**
* Get reference count of this archive.
*/

BcU32 refCount() const;


// Shortcut routines. Implemented to make sip's life easier. Don't use normally.
RsFlashMovie* getFlashMovie( const BcChar* Name )
{
return (RsFlashMovie*)pInternalResource( rt_RS_FLASH, Name );
}

RsFont* getFont( const BcChar* Name )
{
return (RsFont*)pInternalResource( rt_RS_FONT, Name );
}

SgNode* getNode( const BcChar* Name )
{
return (SgNode*)pInternalResource( rt_SG_NODE, Name );
}

private:
virtual void execute();

private:
friend class CsCoreImpl;

//
BcU32 RefCount_;
BcChar ArchiveName_[64];

//
enum eInternalState
{
IS_LOAD_PENDING = 0,
IS_LOADING_HEADER,
IS_LOADING_RESOURCE_HEADERS,
IS_LOADING_RESOURCE_DATA,
IS_DECOMPRESSING,
IS_DECOMRESSED,
IS_LOADED,
IS_UNLOAD_PENDING,
IS_UNLOADED,
IS_ERROR
};

//
void* pInternalResource( eResourceType Type, const BcChar* Name, BcU32* pSize = NULL );

//
void initLoad( const BcChar* FileName );
void initUnload();

//
void load();
void unload();

//
FsFile ArchiveFile_;

//
BcCompress Decompressor_;

// Useful structures
CsHeader ArchiveHeader_;
CsResource* pResourceList_;

// Start of raw data
BcU8* pArchiveData_;
BcU8* pArchiveResourceData_;

// Housekeeping
eInternalState InternalState_;

// Unload behavoir.
BcU32 TimeOut_;
};

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// From the CPP:
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////
// initLoad
void CsArchive::initLoad( const BcChar* FileName )
{
// Copy across name.
BcStrCopy( ArchiveName_, FileName );

// Open the archive
if( ArchiveFile_.open( FileName, fsFM_READ ) )
{
// Stream archive header in.
ArchiveFile_.streamTo( (BcU8*)&ArchiveHeader_, sizeof( ArchiveHeader_ ) );

// Set state
InternalState_ = IS_LOADING_HEADER;
}
else
{
BcPrintf( "** ERROR: Archive \"%s\" failed to open **\n", FileName );
InternalState_ = IS_ERROR;
}
}

//////////////////////////////////////////////////////////////////////////
// initUnload
void CsArchive::initUnload()
{
BcAssert( InternalState_ == IS_LOADED );

InternalState_ = IS_UNLOAD_PENDING;
}




Oh, answer to the capitalised variable names - much prefer it. Easier to read as the capital breaks up lines quite nicely - as you typically use more variables in a statement than function calls [smile]

Share this post


Link to post
Share on other sites
Richy's code makes me cry.

I use the boost standards:

namespace my_enum
{
enum Enum
{
a_choice,
another_choice
};
}

class a_class_name
{
int private_variable_;
public:
int public_variable; // no trailing underscore!

int function_name();
int another_function(my_enum::Enum e = my_enum::a_choice);
};




The enums aren't exactly boost-style, but I find they're really good. C++09 ftw (strongly named enums).


Share this post


Link to post
Share on other sites
Quote:
Original post by _goat
Richy's code makes me cry.

I use the boost standards:

*** Source Snippet Removed ***


The enums aren't exactly boost-style, but I find they're really good. C++09 ftw (strongly named enums).


Hey, i started doing that with my enums a long time ago.
Because scoping and qualifying is so much better.
Except instead of Enum i use type.

I didnt even realise boost did this too. So i must've had a few decent ideas after all :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!