POV-Ray : Newsgroups : povray.off-topic : 10 things to use a Min Heap for : Re: (Tainted) Server Time
7 Sep 2024 19:16:40 EDT (-0400)
  Re: (Tainted)  
From: Darren New
Date: 19 Jun 2008 16:39:25
Message: <485ac3fd$1@news.povray.org>
Invisible wrote:
> data MinHeap x = Node x (MinHeap x) (MinHeap x) | Null

This is much cleaner than anything you'd see in Erlang, fwiw. Lots of 
Erlang syntax for passing around functions (or lambdas) is so 
heavy-weight that making (say) a list of lambdas as a bound variable in 
another lambda you pass somewhere winds you up with so much nesting and 
syntax cruft you're almost required to split it into a different function.

I've found there's a couple of annoyances with functional programming 
(at least in Erlang):

1) Every control-structure is out of line. You can't really do a while 
loop without having the body show up somewhere else, and almost always 
needing a name.  (I suspect Haskell's lazy evaluation makes this much 
less of a problem, since you can just use something like fold over a 
multi-gigabyte file and not worry about bombing out.)

2) There's no simple way to pass private information around. If I'm 
doing some process that is (say) reading thru a big file, processing 
hundreds of lines a second but still taking dozens of minutes to run, if 
I want to put in a counter to print how far along it has gotten every 
1000 lines (so I know it's working), it's a major pain to pass and 
update that everywhere, interfering with all kinds of things (including 
the caller of the function needing to pass the initial counter).

3) If you have a functionality that has a complex control flow, you 
basically wind up writing it as a bunch of separate functions with tail 
calls routing things around, like a state machine. Every time one you 
change one of those to track something new, you have to track down every 
call and pass the new thing.  (For example, you have a turn-based game 
that has a dozen paths thru it that all lead back to the next turn. You 
decide you want to keep track of each move in the game. You can't just 
add a static variable and append each move to it - you have to modify a 
dozen places where the function is called to pass the partial list.)

I will admit, pretty much everything worked right pretty easily once I 
got it to run at all, so it isn't that difficult, but it does seem like 
a maintenance problem in a big program with lots of functionality.

-- 
Darren New / San Diego, CA, USA (PST)
  Helpful housekeeping hints:
   Check your feather pillows for holes
    before putting them in the washing machine.


Post a reply to this message

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