James Harris <no.email.please> wrote:
> Before I embark on a new long-term project I'd appreciate your advice
> on how to split up long names. I would like to keep the standards for
> command names the same as that for variable names. Looking at the
> examples below, which ones seem better?
Please fix your line lenghts to something of around 70 (I reformatted
the text to make things readable).
> Straight names
> echoclient
> lastcharoffset
> helloworld
> Internal underscores
> echo_client
> last_char_offset
> hello_world
I would much prefer the second since it's way easier to read and
typos are easier to recognize. Just compare
lastcharoffset <-> last_char_offset
lastcharofset <-> last_char_of_set
and it should become clear immediately why I feel that way.
> I could also use embedded hyphens as my minus sign must be surrounded
> by whitespace (please suspend disbelief while looking at these. I know
> they will look unfamiliar!)
> echo-client
> last-char-offset
> hello-world
Huh? Unless you do some automatic conversion of the source code before
you pass it to the compiler that won't do what you expect...
> Mixed case
> EchoClient
> LastCharOffset
> HelloWorld
> Initial lower case then mixed
> echoClient
> lastCharOffset
> helloWorld
> In some ways I like the mixed case versions using an inital capital,
Well, I still would prefer the version with underscores since they
seem still easier to read (you immediately see the subdivision in
words because we're trained to expect spaces between words) but
having the upper case at the start of words gives you at least a lot
more visual clues then without. What becomes a problem with the
use of upper case characters is when you want to code some extra
meaning into the use of upper/lower case, e.g. have global variables
always start with an upper case character but everything else in
lower case and upper case for all word starts for typedef'ed stuff
like in
Var_array <- a global variable
Var_Type <- a type with a typedef somewhere in the headers
> especially as I may want to prefix some names with a code for an
> abstract data type, which, when present, could begin with a lower
> case. Is this getting too Microsoft-ish? Is it getting to Hungarian?
> Is Hungarian bad when used with abstract data types rather than
> inbuilt ones?
Well, lots of people loath Hungarian notation (and I am admittedly
one of them) because
a) all that stuff at the start makes it harder to read since you
always have to scan for the real variable name, especially when
used without an intervening underscore and you end up with names
like 'rgbsyHash' or 'rgwDic' (as taken directly from an article
http://cm-solutions.com/cms/technica...convention.htm
by its inventor Simonyi, it shows rather nicely why not to use it,
the example code mostly looks to me as if it had been rot13'ed),
b) if you're that far away from the definition of a variable that
it gets tedious to look it up (and you can't remember it) then
your function probably has already become too long
c) or, if this is a variable that is defined somewhere else, it
should have a name that at least gives you a clue to what its
type is.
> Advice on which is or is not thought to be acceptable would be much
> appreciated. Please bear in mind that I intend these names for
> commands/instructions as well as variables and types. Constants would
> be in all caps.
I tend to write function names in lower case only - that it's a
function normally is obvious because of the parenthesis following
it.
Regards, Jens
--
\ Jens Thoms Toerring ___
\__________________________
http://www.toerring.de