Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > metasyntactic variables

Thread Tools

metasyntactic variables

Posts: n/a

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

1) Is that a good idea?

2) What variable names are recommended?

Reply With Quote
Chris Dollin
Posts: n/a
Baboon wrote:

> 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.


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?

/Questions? Answers! Answers? Questions!/ - Focus

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Reply With Quote
John Bode
Posts: n/a
On May 19, 3:07 am, Baboon <(E-Mail Removed)> wrote:
> 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.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
what is difference between Class variables and Instance variables? Java 10 06-06-2011 06:43 AM
Put variables into member variables or function variables? C++ 9 03-23-2008 04:03 PM
Session Variables and Static Variables ASP .Net 1 03-26-2006 11:05 AM
Accessing class member variables - properties or variables? dwok Java 7 03-04-2005 03:54 AM
Re: Class public shared Variables vs. Application Variables in ASP.NET avnrao ASP .Net 0 05-07-2004 05:28 AM