In comp.os.linux.advocacy, Kelsey Bjarnason
<
[email protected]>
wrote
If it were formatted for readability and used variables and other symbols
which themselves indicated their use, yes.
Not surprising, given your code. Most of us, however, don't see
reinventing the wheel as a good thing; if there's existing code which can
be modified to suit the task, rather than writing entirely new code, we do
it; it saves time, effort and bugs - the existing code is much more likely
to have been relatively debugged than the new code.
Writing unmaintainable code, as you do, does, indeed, make one want to
rewrite it.
I for one would be curious as to whether someone's developed
a tool that would allow for the management of unreadable C
code.
Something along the lines of Eclipse, perhaps?
Anyway, the capabilities that I might find useful are these:
[1] "De-macroization" of function calls and identifiers. Basically,
it would either expand by one level or down to standard macros.
More on "standard macros" later on.
[2] Replacement of local variable names. If I see a 'c', I can replace
it with 'local_speed_of_light'. (That's a bit contrived but you
get the idea.) No other instances of 'c' out of the scope would
be affected.
[3] Replacement of global variable names. This one's a bit trickier
and would require that the development environment know a lot
more about the system under development -- every module would
have to be looked at. One other possibility: conversion of a global
variable to a static scoped classfield name:
x => Y::z
and inclusion somewhere of:
class Y { public: static int z; }
int Y::z = 0;
Or even a non-static accessor function:
x => Y::singleton_y().z()
class Y { public: static Y & singleton_y(); int z(); }
Y & Y::singleton_y() { ... }
int Y::z() { ... }
[4] Elimination of unnecessary #includes, and proper guardbanding of
user #includes and certain system #includes.
[5] Identification of standard macros such as 'getchar', 'EOF', and
'FD_SET', so that they don't get de-macroized in [1]. Shadowing
of macros would be properly detected.
[6] Of course it should prettyprint. There are a few issues here, mostly
of the "which scheme did you like?" type.
[7] Auto-docstubbing. Basically, declarations of the type:
int x,y,z,w;
would be replaced by:
int x; // TODO: what is x?
int y; // TODO: what is y?
int z; // TODO: what is z?
int w; // TODO: what is w?
One could also extend parameter lists, either old- or new-style.
a(int b, int c) =>
a(
int b, // TODO: what is b?
int c // TODO: what is c?
)
Of course variable and parameter lists with existing documentation
would be unaffected.
[8] Something along the lines of javadoc or Cweb, for generation
of documentation from the codebase. Ideally, the reverse would
also be possible but most Marketing departments won't be
technical enough to get the formatting quite right. (It's an
interdepartmental negotiation process in any event.)
[9] If I need a system macro or function, the system would at my
behest include the relevant #include file, if it's not already there
(or #included by some other #include file I already have).
This could also be extended to include user-defined stuff
as well.
[10] All of this would be nicely visual. KDevelop isn't too bad as
a starting point, for example, though I can't say I like some
of Qt's hacks.
[11] Detection of loop-local variables, and the replacement of:
int i;
for(i = 0; ...) {
}
with
for(int i = 0; ...) {
}
if 'i' is used nowhere else in the module.
[12] A capability similar to [3] except for addition, renaming, and
possibly even deletion of base-level virtuals.
[13] Methods by which one can splice and merge class hierarchy,
by creating a new base or derived class and then moving methods
and fields around. The constructors and accessors would do the
right thing.
[14] A method by which one can move virtuals, leaving a "ghost"
(pure virtual) in the right place.
[15] A method by which one can replace pointer declarations with a
"smart pointer", and a simple template for declaring "smart pointers".
There are admittedly a few ugly issues here (my implementation
of "smart pointers" requires two friend declarations, for example,
and requires an extra int to manage the refcount).
[16] Individual, group, and company-wide policy declarations to manage
all this.