473,322 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

metasyntactic variables


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

1) Is that a good idea?

2) What variable names are recommended?
Jun 27 '08 #1
3 1237
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.

(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?

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

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

Jun 27 '08 #2
Baboon wrote:
>
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 counterproductive. 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:

<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf>

In practise other standards (like POSIX) may also impose their own
restrictions, as would house guidelines.

Jun 27 '08 #3
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 "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.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hal Vaughan | last post by:
First, I am aware of both SwingUtilities.invokeLater(), and of using Thread to create a new thread.  These are part of the problem. I want to have something running in the background, while the...
4
by: Torsten Bronger | last post by:
Hallöchen! I have a file that looks a little bit like a C header file with a long list of variables (actually constants) definitions, e.g. VI_ATTR_TIMO = 0x54378 .... Actually I need this...
1
by: mark4asp | last post by:
What are the best methods for using global constants and variables? I've noticed that many people put all global constants in a file and include that file on every page. This is the best way of...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
7
by: misha | last post by:
Hello. I was wandering if someone could explain to me (or point to some manual) the process of mapping the addresses of host variables by DB2. Especially I would like to know when DB2 decides to...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.