On Feb 19, 2008 7:14 AM, Bob La Quey <[EMAIL PROTECTED]> wrote:
> On Feb 18, 2008 11:40 PM, Andrew Lentvorski <[EMAIL PROTECTED]> wrote:
> > Bob La Quey wrote:
> > > On Feb 18, 2008 4:02 PM, Andrew Lentvorski <[EMAIL PROTECTED]> wrote:
> > >
> > >> Well, part of it is the fact that most XML libraries in C and Java
> > >> eventually flip themselves inside out in order to be iterative to avoid
> > >> stack faults.
> > >
> > > Really? Color me mildly skeptical.
>
> > > How deep are these
> > > XML structures anyway? Can you give me an example?
>
> I guess I should have indicated my sarcasm :(
>
> > www.slashdot.org -> view page source
> >
> > So, assuming that slashdot is probably well behaved, there's your
> > minimum depth for site.
>
> I looked and counted: about 8 or 9 levels. It isn
> ot like 100's or anything of that sort. I suppose
> some folks compile with small stacks.
>
> > However, you don't want *any* site to be able to crash your application
> > by simply nesting elements sufficiently deeply.
>
> Uh, then limit the recursion in the code.
>
> > >> Suddenly, you can't access things in a recursive fashion
> > >> and have to start doing things like callbacks, iterators, etc.
> > >
> > > There are a_lot_ of reasons to want to access things in
> > > other than recursive fashion. That is a main reason why
> > > we traverse stuctures, like XML structures.
> >
> > I can come up with reasons, but I think you are being kind.
> >
> > I would argue that we traverse structures iteratively rather than
> > recursively because the languages in use to this point make iterative
> > easier than recursive.
>
> Not necessarily.  Often we simply want to map things onto
> other structures. Sometimes that is easier to do recursively
> sometimes in some other way. Lots of code gets written that
> traverses XML in essentially a pattern matching mode without
> much reference to the tree structure. Certainly that is a
> natural way for a lot of the Perl guys to do things.
>
> > Without closures/continuations, there is no way to suspend the "stack"
> > information from a recursive set of calls to be resumed later (C, C++,
> > Java, for example).
>
> Well it has been a while but what about jump, setjump in C?
>
> > When you  have closures/continuations, suddenly you
> > get recursive solutions popping up.  Witness the number of "yield"-based
> > XML traversal solutions in Python (yield is a weak continuation construct).
>
> OK. I will have to explore this.
>
> > To be fair, though, lots of the junk in the SAX way of traversing XML is
> > to deal with the fact that XML "nodes" are polymorphic while the
> > implementation language is statically typed.
>
> Agree that the nodes are polymorphic but I do _not_ see
> what that has to do with static typing. Please explain.
>
> Maybe what you are saying is that if a node were
> a single data type then compile time checking
> could be imposed?
>
> BobLQ

In another message David wrote:
> The main reason that drives this isn't the depth of the recursion, but the
> size of the whole structure.  Without some way of stopping part way
> through, the code can only read the entire entity into memory.  This is
> actually normal for webpages and stuff, but imagine a network XML stream,
> or a traversal of a filesystem.

Agreed. It is the size of the whole structure that is most often
the problem _not_ the depth of recursion.

BobLQ

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to