S
spinoza1111
Not really. C isn't a language that lends itself to proper exception
support because there are too many points where exceptions fall flat.
One can see the problems by looking at C++. C++ exceptions are useful
to a point, but in my opinion they're not nearly as beneficial as they
would be if C++ integrated them more fully into the language (throwing
an exception on out of bounds array indexing, for example) and had
native garbage collection.
By the time you plug the holes, you'll have something more like Java
or C#.
Which some brilliant people at Sun and Microsoft have done. Moore's
Law should take care of the rest. Why is C not given a hero's funeral?
No, you didn't make it clear at all. The statement I quoted and
replied to can easily be interpreted as: copying to a linked list
makes the system run slow if there's 'just enough' memory. This
suggests that referencing in a linked list wouldn't run slow in the
same situation, which is the implication that my reply refutes.
Well, anything slows down if there's just enough memory. But I don't
understand you, and I don't think you understand me. So, I shall
repeat myself: Richard's solution does in many scenarios an
unnecessarily large malloc for struct elements, and then it does an
unnecessary copy. It betrays incomprehension of linked lists. If he'd
started out as I started out on second generation equipment (an 8K
1401 in my case) he'd have a better appreciation of storage
complexity. It seems that for him, memory is free.
I agree that copying large objects may be problematic, especially with
It IS.
an extra malloc call. I don't agree that it's a deal breaker. I'm not
the only one who's suggested that copying a pointer to the data rather
than the data itself is one way to get the effect of referencing with
a copying linked list. You just need to be aware of your memory
management (as one should be), and avoid unnecessary copies on the
client side.
One irritating characteristic of some of your replies is the sudden
entry of terminology such as "client side" which doesn't necessarily
apply in the abstract problem. My "client", if you mean dear Richard's
caller, is sending me data from The Great Beyond. Both me and Dickie
Wad need to have a meaningful address during the duration of the call
(I need it for a picosecond to set a four or eight byte thingie-poo to
point to the data: he needs it for an unpredictable amount of time),
so this is a given.
My assumption is that the address of the data will be stable. OK,
suppose in real scientific asceticism that I should Occam this
exception's balls off, and throw it out, just as I threw out string.h
elsethread.
Then yes, I must copy.
However, this means that on my computer, I should not trust addresses
ever to be stable at all, and should always, in brief intervals of
stability, copy things.
This defeats the whole purpose of a Von Neumann machine.
Copying should be an option in an extended linked list processor. As
the only way, it's absurd.
See above.
The copy may be an extra cost. Or it may not. Let's say the original
object being copied is a local variable as opposed to dynamically
allocated memory. A copy is necessary if the list node lives longer
than the scope of said local variable. Either way you're calling
malloc and copying the object.
Makes no sense. If the element is a local variable, there's almost no
reason (I can think of) to make a copy for posterity!
The data items x1,x2,...xn, let us say, are all developed as local
variables for shits and giggles inside a procedure. The procedure
makes a linked list of those values using Dickie Wad's code.
This linked list is either itself declared as a local variable as
x1,x2...xn at the same level of static nesting or it is not.
If it is, then when they go out of scope, so does the linked list. Uh,
Dickie, why did you make a list? You had the variables, chump.
If it is not, then outside the scope, those variables have NO meaning,
unless you've decided to preserve them for use elsescope. But why did
you need a linked list to do this? OK, you wanted to make a copy of a
bunch for use elsescope. So why didn't you use an ARRAY in the first
place?
There are situations where it makes sense to put data in a linked
list. But there are MORE situations in which you don't want to make a
copy.
Richard's design is actually very close to the boilerplate for my own
published container libraries atwww.eternallyconfuzzled.com(which
may or may not be designed differently if I rewrote them). The
container maintains 'dup' and 'rel' delegates which manage copying and
releasing of the contained objects. When creating a new node, dup
copies the data as in:
node->data = container->dup(data);
When deleting an existing node, the pointer is released:
container->rel(node->data);
If one wants copying semantics, simply call malloc and copy the data
in dup, then free it in rel. For referencing semantics, return the
argument in dup and do nothing in rel:
void *dup(void *data)
{
return data;
}
void rel(void *data)
{
// No work needed
}
This design is preference agnostic in that copying and referencing are
both supported. However, if I were writing about data structures, I'd
only mention this design in passing (or attach complete libraries as
supplementary to the chapter) because the extra fluff takes away from
the topic being taught.
You don't do yourself justice. Elegance, said Dijkstra, such as yours,
is in computing science a matter of life and death. Galileo said it is
the frills, the extras that add "nobility and excellence to a
scientific theory". Mies van der Rohe said God is in the details. The
post modern architect Venturi said, less is less.
Richard said d'oh, copy da data.
You may notice that I follow this pattern in my tutorials on that site
if you've read them. The tutorials typically use integer data and a
copying design to minimize boilerplate code and highlight the data
structures being described. Then the libraries act as supplementary to
exhibit a more reusable implementation.
Your work is probably light years ahead of Richard's, and wanna know
why? Because you write like a girl, which is a compliment. You're not
afraid of complex sentence structure and your orthography is perfect.
Whereas I've noticed in my thirty year career that male programmers
like Richard range from loudmouth braggarts like him, who while he
doesn't make elementary errors in writing, doesn't like the written
word and falls into shibboleth and saw to save his "valuable" time,
and little backstabbers like Seebach whose writing stays at the
shallow end of the kiddie pool, being creative only when he's
inventing new logical fallacies.
As Dijsktra said, great programmers can write well.
The only problem, in fact, that I see in your texts is a corporate
vice: being even handed, overly interested in sacrificing first
principles to "trade offs", and giving equal time to evil.