Re: DISCUSSION: Naming conventions (for C code)

Doug Moen (dmoen@utcc.utoronto.ca)
Fri, 4 Jun 1993 02:16:29 -0400

I approve of the proposed new consistent naming convention.

The programming convention we use suffixes all typedef names with "_t";
thus, struct PyObject { ... } PyObject_t. The _t convention has the
advantage of being instantly understood by all C programmers (because of
size_t, etc, in the ANSI C standard).

I'm not so happy about the alternative suggestion of just prefixing the
existing names with py_, since this "will leave the existing inconsistencies
in place". Python has a great future ahead of it; a little work at fixing
inconsistencies now will repay itself with interest. Future generations
will praise your foresight (just as they curse the designers of C for not
fixing the gets/fgets botch in the mid seventies, to avoid inconveniencing
a few dozen people).

The directory reorganization (putting different kinds of files into different
directories) will be a big win for us, since it will make it much easier
for us to build python using the Qef construction tool (we don't use make).

When you rename the header files, please don't exceed 8 characters before
the ".h"; this will make it easier for me when I compile the DOS and Windows
versions of Python.

You mention a python script for automating the name change.
Here is how we do name changes of this sort at my organization.

1. First, we use a grep variant which takes a list of C identifiers
rather than a regular expression, and produce a file of the form
filename:lineno:contents of file
...
This is the same format that grep outputs.

2. Then, we visually scan the file, looking for lines that shouldn't
actually be changed (eg, comment lines containing the word "object"
in the English sense); these lines are deleted.

3. Then, we perform a global substitution on the file. We use a tool
which takes a dictionary of old-C-identifier, new-C-identifier pairs,
one pair per line, separated by tabs.

4. A final visual scan, to make sure no mistaken substitutions were made.

5. Finally, we feed the file to a tool called "repl", which interprets
the filename and lineno fields, and replaces the indicated lines in
the indicated files with the new text.

With the above procedure, large scale name changes are fairly easy
to do. The nice thing about this procedure is that it's quick and easy to
eyeball the changes before you commit to them.