In my "C" programs, I am always using heaps of metasyntactic variables.
Like foo, bar, baz, flarn, spoo, it, thing, wossname?
1) Is that a good idea?
Usually not.
2) What variable names are recommended?
Ones that say, briefly, what they mean, so they communicate to the
human reader (who cares) as opposed to the compiler (which usually
doesn't complain, even if it does care). The larger their scope,
the more likely that the name is long (since it occurs more often
out of context).
Traditionally, loop indicies have names like `i`, `j`, `k`, although
better names may present themselves/be required, especially if there
are multiple nested/sequential loops where the meaning of the indexes
can be obscure.
(fx:imao)
I often end up with 1-or-2-character names for function parameters
when (a) the type of the argument has an explanatory name, (b) there's
only one argument of that type, (c) the type name's constuituent
words abbreviate to the name, (d) the function is short [1] (e) the
result isn't stupid.
Strata stratify( Premises p ) { ... }
`p` may be a perfectly good name, certainly much better than `premises`.
`g` and `qh` (or even `q`) are good enough names, better than
`graphToQuery` or `queryHandlerTo Use`.
[1] One of my coding goals is "all functions should be short". That
means any long functions I end up with must have a really good
reason for being long [2].
[2] "long" and "short" are really unfortunate word-choices here, yes?
>
In my "C" programs, I am always using heaps of metasyntactic
variables.
Are you sure.
1) Is that a good idea?
No. Metasyntactic variables exist to make life easy for illustrative
purposes. Code meant for actual use needs to have meaningful
identifiers, as far as possible.
2) What variable names are recommended?
In general you should strive to name your variables to indicate what
type of object they are or what type of information they hold. Some
examples are:
error_code, air_pressure, line_length, object_state, matrix_size, etc.
Of course you'll develop your own style like say using mixed-case
instead of underscores etc. The main aim is to convey the object's
purpose and to maximise readability. Excessively long or short names
are usually counterproducti ve. OTOH you might give a small identifier
like 'ctr' or 'i' to a very short lived localised object. The
overarching goals are readability, consistency (i.e., picking a style
and sticking to it within any one project) and conveying some
information about the variable.
These considerations also apply for function and macro names, except
that they are usually named for what they _do_ rather than what they
_are_ .
Also you need to be aware that the C standard prohibits user code from
using certain forms of identifiers. Section 7.1.3 spells out the exact
rules for this. You can get a draft of the current C standard here:
On May 19, 3:07 am, Baboon <nos...@nospam. invalidwrote:
In my "C" programs, I am always using heaps of metasyntactic variables.
>
1) Is that a good idea?
>
Generally, no.
2) What variable names are recommended?
Anything that clearly conveys what the variable (or function)
represents and how it's used in the program. For a totally contrived
example, say your code gathers weather data to prepare a weather
report. The most logical names for your variables would be things
like "temperatur e", "humidity", "windDirection" , "windSpeed" , etc.
Don't be afraid to use plain English (or whatever your native language
is) names. By that same token, don't go insane and use names like
"temperatureFro mSensorNumberSe ven" or something like that.
Comment