Whoa scary-town. The reason for not having forward references/recursive
structures in the first place is largely due to the nightmare they induce in
C++. For the languages where all objects are actually pointers, it's
straightforward enough to toss in some nulls all over the place, but to pull
this off in C++ means we need to start making every object a pointer, which
means implementing dynamic memory management in generated code, which means
very-scary-contracts-with-application-code, etc. etc.
Here's the super-scary case:
class MyObject {
MyObject *otherObject;
}
MyObject a = someCodeThatReadsOneOfThese(); // automatically allocates
nested object
MyObject *b = a.otherObject; // fair enough, you want to use it too
a.otherObject = ohActuallyIWantThisOne; // fair enough, you want to modify
the object
OH GOD, WHO OWNS THE DYNAMICALLY ALLOCATED MEMORY?
There is no one hard-and-fast rule. Sometimes, you want the memory
dynamically owned. Other times, you want to yank it out and transfer
ownership to your application code (without having to do a deep copy).
Basically, to pull this off we'd have to make every Thrift object a
smart_ptr or reference-counted storage of some type, which goes against
Thrift's design principle of simplicity and light-weightness for the common
base cases.
Cheers,
mcslee
----- Original Message -----
From: "Ted Dunning" <[email protected]>
To: <[email protected]>
Sent: Wednesday, March 25, 2009 6:50 PM
Subject: Re: Addition of union type
It seems pretty reasonable and not all that hard. If you got all
ambitious,
you could rewrite the entire compiler to allow forward references and we
would suddenly have recursive data structures!
(or not)
On Wed, Mar 25, 2009 at 3:05 PM, Bryan Duxbury <[email protected]> wrote:
What do people think about this idea? If we like it we can start to flesh
it out some more and then open a ticket to get implementations going.
--
Ted Dunning, CTO
DeepDyve