metasyntactic variables

B

Baboon

In my "C" programs, I am always using heaps of metasyntactic variables.

1) Is that a good idea?

2) What variable names are recommended?
 
C

Chris Dollin

Baboon said:
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`.

ResultSequence runQuery( Graph g, QueryHandler qh ) { ... }

`g` and `qh` (or even `q`) are good enough names, better than
`graphToQuery` or `queryHandlerToUse`.

[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?
 
J

John Bode

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 "temperature", "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
"temperatureFromSensorNumberSeven" or something like that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top