Phlip said:
That's sometimes the correct style, because if a prototype misses its
actual, the compiler might not warn you.
However, if one does that, the prototypes should still all be listed
somewhere, even if commented-out. From my point of view, headers aren't
just "syntactic glue that makes stuff compile and link without error";
they are statements from one programmer to another saying "See, look
here! Here's what you got! Here's the data-types and functions and
classes I've made available for your use!"
Ie, programming languages are human languages. (And also, almost
coincidentally, computer languages.)
Otherwise, let's all just program in machine language.
01001011010101010100011010101101111010110001011010101010011001
10101010100101101000100011010101011010010101000111010101001101
10101100110110010010110101010100010101010101110100010101010100
11011110100101010010110010101001010101010011010101010001001101
Wheee! Isn't this fun! :-/
However, this code should have lots of classes, where prototypes are not
optional and are strictly matched. And it shouldn't have 10,000 line
methods.
347,000 lines of code and not one class in the entire thing.
Very few structs, for that matter. No methods. (Well, some
of the structs I wrote myself, I wanted to be able to construct
in different ways, so I wrote parameterized constructors.
Those are the only "methods" in the program.)
This is probably C-style C++, if not just C.
Combo of both. Originally, it was pure C. But the need for containers,
algorithms, iterators, templates, inline functions, std::string, and the
stronger typing of a C++ compiler, was enormous, so coworkers and I
converted it to C++. That way, we could create data structures we needed
(such as a map of structs which contain deques of structs) without writing
thousands of lines of error prone implimentation and leak-prone malloc and
free calls.
Ouch. The functions are also run-on. They should be short and sweet.
Personally, I like functions with 25 lines of code, and files
with about a half-dozen such functions. If I need more stuff than
that, I make more files. Each file with it's own logical purpose
and responsibilities, and in it's own namespace. My personal
programming at home, for hobby and utility, is all like that.
(I even use a little OOP, where it seems the best approach.)
The software I'm maintaining at work, though, is NOTHING like that.
The dude who wrote it used 500-line-long functions and 10000-line-long
files. No OOP, no classes, almost no structs. Lots of endlessly
repeated cut-n-paste code. Lots of small fixed-size arrays which keep
overflowing. You get the picture. (And a might ugly picture it is.)
Ideally, this app should have been a strongly OOP project from the
start, but the author hated C++ and OOP, so he locked me into a very
different style. So I have to handle a bewildering hierarchy of
object types and subtypes, without benefit of any common interface
or implimentation between related object types. Everything's just
replicated over and over for each slightly-different type.
Download Doxygen and run this source through it. One of Doxygen's outputs is
XML. Whack that, like a database, with an XPath tool, and you have your
prototypes. Oh, and it will also produce a website documenting your code!
Ok, thanks for the tip. I'll look into that.
Now what will you do with the prototypes? Put them into one collosal
.h file that everyone will import and nobody will respect?
No, I'm going in the opposite direction, putting headers for each
*.cpp file in a like-named *.h file, and only #including headers
where they're needed. Nearly every cpp file includes main.h which
includes the MOST-USED header files from inside and outside the
project; but little-used headers are now included only where needed.
My main purpose for wanting to generate prototypes for EVERYTHING
is just to see what's there. Maybe half the functions in this
project are unprototyped, undocumented, effectively "hidden".
Now, if I had a program that not only listed the prototypes, but
generated charts of what functions call what functions, that would
be even better. That would save me hours of laboriously tracing
execution through the debugger.
You have a "legacy code" situation. Read /Working Effectively
With Legacy Code/ by Mike Feathers. I just told the SCQAA users
group that, last week in Anaheim/Orange, so you might also get
down with them about it!
I've already got that book on my "to-buy" list from when you
recommended it to me last Thursday in response to a post of mine
in which I asked about some weird, idiotic thing my dear departed
ex-boss did in his code. It'll have to wait till Friday (payday),
though; then I'll snarf it from Amazon.
Interesting that you were in the Anaheim/Orange area last week;
I live in Tustin (the next city SE of Orange), and work in
Rancho Santa Margarita (when I'm not telecommuting).
--
Cheers,
Robbie Hatley
Tustin, CA, USA
lonewolfintj atsign pacbell period net
home period pacbell period net slantbar earnur slantbar