A detail quite irrelevant to my point. Now you're managing a linked
list, blocks of contiguous characters, *and* the relationship between
them to represent a single string. If the original goal is easy
modification, I'd be dubious about how successful this design is
compared to the simpler list of characters or block of characters.
Verbiage, Julienne, of the sort that torpedoes good ideas in
structured walkthroughs, because it is HARD to "modify" strings
maintained as what you seem to mean by "the simpler list of characters
or block of characters" (your meaning is not clear.
If you mean that strings should be maintained in the current way, if a
NUL terminated string is a "simpler" list of characters or block, then
making deletions and insertions is actually quite difficult and time-
consuming. It requires that the entire string, no matter how long, be
completely reallocated.
Whereas deletions and insertions in a linked list are always simple,
both conceptually (once you get the hang of it) and in terms of
computational complexity. It involves no excess or wasted movement of
characters.
I went home and checked my copy of the book. Personally, I think
you're overreacting. The C Unleashed design is a viable one in that
the data structure owns its data, as opposed to having the data owned
by something else and merely storing pointers to said data. In the
former case the data structure can make specific claims of correctness
and integrity while in the latter case you can end up with dangling
pointers and unexpected aliasing. On the down side, in the former case
you end up copying data around when it might not be necessary, and
making copies might not be desirable from a functionality standpoint.
This type of "ownership" is overrated.
If the data pointed to by the linked list is unexpectedly changed, you
most assuredly end up with what you call "dangling" pointers, and
usually a pretty obvious runtime error.
However, using Richard's solution, quite apart from its performance,
if the copied data changed, you end up in many scenarios with
what .Net authority and nice guy Dan Appleman calls the worst kind of
error...one that you don't know about.
Although corporate programmers without excess university training are
somewhat biased, in my experience, towards copying data, I'd say it's
usually better given my compiler experience in addition to my business
experience to link to it.
When programmers start talk, in my experience, about "buffering" data
or making a "work file", this is often a sign of incompetence and
anxiety.
There are advantages and disadvantages to both, which is typical in
software design. Choose the one that best suits your needs, and you'll
end up with higher quality software. Being dogmatic about one or the
other limits your options.
Why is it in corporations that the most vague admonitions are used to
make irrevocable and costly decisions, whereas knowledge is equated
with dogma? This type of thinking caused the crash of two Space
Shuttles: in the case of Challenger, its engineers knew to a moral
certainty that the o-rings that failed were not tested "live" in low
temperatures, and in the case of Columbia, its engineers knew to a
moral certainty that the Space Shuttle was operating outside of its
acceptable performance bounds when it shed insulation parts on lift-
off...and this was admitted in the official review of the accident.
People died, Julienne, because vague admonitions ("think like a
manager and not an engineer") overrode hard engineering facts. As they
died in Iraq because Donald Rumsfeld's corporate BULLSHIT (which he
honed at Searle during the 1990s) overrode the hard requirements of a
respected military officer (Shinseki) for enough troops to secure
Iraq. And reading about incidents like this, which echo my own
experiences at Bell Northern Research, I thank my lucky stars that I
no longer work in corporate programming.
It is *unacceptable* to copy data from a place pointed-to by a pointer
to void into a structure, and call the result "reusable software". As
I have said, preprocessor macros can be used to create a type-safe
reusable linked list manager that uses no pointers to void. However,
the real problem isn't in the use of a pointer to void. It is that the
"reusable" tool is unnecessarily copying a completely unpredictable
number of bytes.
May I direct you to the irony of this statement and your resistance to
My dear Julienne, let us not simulate, even in dulcet tones, the
corporate situation in which independence thought is reduced to a bad
attitude, irrational resistance and behavior. Thank you.
the solution from C Unleashed (which is no worse than your stated
alternative, just different)? While I prefer not to presume to say
*why* someone is resistant to alternatives, it often strikes me as a
matter of ego rather than logic. In a manner of speaking: "I'd do it
this way, so this way is right. Your way isn't how I'd do it, so your
way is wrong".
Bullshit. There's a scene in Hamlet in which two "corporate" types,
Rosencrantz and Guildenstern, two creeps who are the Renaissance
equivalent, being courtiers, are posing as Hamlet's friends while
spying for his mortal enemy, Claudius. Hamlet, who seems "crazy" only
to the ignorant and evil characters of the play, and equally ignorant
high school English teacher, hands Guildenstern a transverse flute,
and asks him to play it. When Guildenstern says "I have not the art",
Hamlet says:
"Why looke you now, how vnworthy a thing you make of me: you would
play vpon mee; you would seeme to know my stops: you would pluck out
the heart of my Mysterie; you would sound mee from my lowest Note, to
the top of my Compasse: and there is much Mu-sicke, excellent Voice,
in this little Organe, yet cannot you make it. Why do you thinke, that
I am easier to bee plaid on, then a Pipe? Call me what Instrument you
will, though you can fret me, you cannot play vpon me. God blesse you
Sir."
In other words, my dear Julienne, I think that of all people,
corporate data processors are amongst the least qualified to do even
Pop psychology and to start ascribing all sorts of childish and
irrational motives to programmers who don't like Richard's kind of
unprofessional crap.
I'd recommend that you take care not to cause too much collateral
damage then. But I'm not sure that recommendation is worth the
bandwidth from me to you because, if I recall correctly, one of your
stated goals was to damage this newsgroup as much as possible.
That is not the case. In fact, I am usually responsible for the most
interesting and well-attended threads.