POV-Ray : Newsgroups : povray.off-topic : Teach yourself C++ in 21 days : Re: Days 5- Server Time
29 Jul 2024 16:26:21 EDT (-0400)
  Re: Days 5-  
From: Darren New
Date: 22 Apr 2012 23:30:04
Message: <4f94ccbc$1@news.povray.org>
On 4/21/2012 11:28, Orchid Win7 v1 wrote:
>> You have no way of knowing how much stack space you have. Nobody writing
>> reliable code wants to recurse for each level of a tree without knowing
>> how deep the tree is.
>
> Nobody writes recursive code? IN WHICH UNIVERSE??

I have written very very little recursive code in my entire career. Of that, 
90% of my recursive code is of the form
   Try to X, 10 times.
   if X failed,
     Try to X one fewer times

Yes, my current project has a tree structure that's at most 3 levels deep, 
and parsing that into flat structures is recursive, once. Before that, it 
was iterative over a queue. (Actually, it might still be, I don't remember.)

> I'm also loving the way you say "you don't know how big the stack is", and
> immediately follow that with "you should check how deep the tree is". But if
> you don't know how big the stack is, you STILL don't know if you can do it. :-P

Well, I know the stack is deep enough to hold 3 levels of tree. The point is 
you can't take an *arbitrary* tree and parse it recursively.

> Besides, it's not like there's an /alternative/ to recursion.

Of course there is. I'm pretty sure every recursive algorithm can be made 
explicitly iterative. The advantage of doing so is that you can handle 
failures of running out of resources, before you ask.

>>> Nobody designs hardware like that any more. Haven't done for decades. :-P
>>
>> So? They're still special areas of memory built into the CPU. Just
>> because you can't address them using normal addressing modes any more
>> doesn't mean they're not memory.
>
> Well, to be /technical/ about it, the entire concept of "memory" is a
> fiction. It would be more accurate to say that there is a large topology of
> transistors connected together - but that's not a very useful way to think
> about it.

But in some cases, those transistors are wired together in a way that 
retains state arbitrarily long, which we call memory. ;-)

>>> So you're telling me that the de facto calling convention that all
>>> software
>>> always uses is "undefined"?
>>
>> Implementation-specific, yes. How could you define it in a standard when
>> you don't even know what architecture you're compiling for?
>
> Amazing. So the one calling convention that every piece of software supports
> isn't actually defined at all. That's impressive, right there.

Which calling convention do you think every piece of software supports? It's 
defined by the implementation. Have you tried invoking Java code from C? 
Have you tried invoking C# code from C++? Have you invoked C++ objects from 
Haskell?

http://www.scribd.com/doc/20689745/Calling-Conventions

Not sure if you're trying to be sarcastic, incredulous, or simply ignorant here.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.