@ wrote... (5 years, 10 months ago)

Part of my Why is simple hard? series.

Like most people with taste, I despise Hungarian notation. But, at the end of the day it really is only a style issue and easy enough to fix with a search & replace.

There is one form of prefix notation that I do like, the prefixes m_ for member variables, s_ for static variables and g_ for any global variables.

Globals!?! g_logger or g_app are reasonable globals, there are only a handful of others.

So what's good notation and naming?

There are only two hard things in Computer Science: cache invalidation and naming things.
Phil Karlton

Well the name should give a good hint to what is and what it's for. As an example, any function that I write that returns a bool starts with a boolean type word, like “is”, “has”, “can”, etc. Having said that, these prefixes are usually redundant.

bool IsConnected();            // or just Connected()
bool HasListeningPort();       // or just Listening()
bool CanYouSeeAPatternHere();  // or just true

Which brings up an important point, C++ has bool, true and false keywords. Use them! Don't use BOOL, TRUE, FALSE. I know that most Windows API calls use the ugly caps versions but that doesn't mean that new code that you write has too.

Category: tech, Tags: cpp, programming, simple
Comments: 0
Click here to add a comment