Re: Factorial
From: Russ Holsclaw (russ_at_holsclaw.nyet)
Date: 05/24/04
- Next message: Hubert Wallgrins: "Re: Treeview: grabbing a nodes tag value (VB6)"
- Previous message: Larry Serflaten: "Re: Here's what I've decided to do [Was: Should I raise a fuss over this?]"
- In reply to: J French: "Re: Factorial"
- Next in thread: Schmidt: "Re: Factorial"
- Reply: Schmidt: "Re: Factorial"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 24 May 2004 15:17:21 -0600
> Oddly I quite like recursion ( or re-entrant ) routines
> - generally a Static watchdog variable solves development problems
FYI, the term re-entrant is not synonymous with recursive. It's a
commonly-held misconception. The term actually relates to code that does
not modify any memory within it's own code segment, or any other memory
except for addresses contained in registers passed to the routine or
buffers acquired via memory-management calls. These attributes enable a
single memory-resident copy of code to be concurrently used by several
processes/threads/tasks in a multi-tasking operating system.
It is true, however, that the programming techniques that enable
re-entrancy also permit recursive routines to be written as well, because
variables in the separate invocations of the routine, even
self-invocations, are kept isolated from each other.
>
> Those things are Ok if you know what you are dealing with, but not for
> idiotic algorithms like QuickSort ( Flames welcome )
You won't get flames from me here. Many years ago, it dawned on me that
books on algorithms, especially those written as academic textbooks, were
excessively obsessed with the specialized problem of sorting data *in
place*, i.e. sorting in an environment that is so memory-constrained that
there's room for only one copy of the list to be sorted, and little else.
This is rarely the case, and even rarer still that you would be able to
predict this situation at the time a program is being designed.
All in-place sorts are sub-optimal, of course. I've quit using them, except
for the most trivial situations (ones that are trivial enough that a simple
bubble-sort is adequate). Generally, I used a merge sort that shuttles the
data back-and-forth between two arrays. When sorting data structures, such
as VB UDT's, I generally don't sort the original array at all, but only a
integer (or Long-integer) array containing a list of array indexes to the
array containing the data. This procedure is much faster than any other
sort. If the data is too voluminous to be safely held in memory, I use
disk-file sorting techniques, or stash the data in a database table. I
don't mess with silly in-place sorting algorithms at all.
> <quote>
> a form of masturbatory software
> design. Some people, particularly academics who have nothing
> better to do, use recursion because they think it makes them look
> cool.
> </quote>
...and yes, in-place sorting belongs in the category of masturbatory
software.
>
> Too damn right, the first problem is getting the code to work
> - the second (and long term most time consuming problem) is
> maintaining the code.
>
> If it ain't simple then it ain't right
>
> Recursion is not the problem, code clarity /is/.
...and I would submit that about the only time recursive code is clearer is
when it's done in a situation that actually *calls* for recursion, such as
traversing tree-like data structures.
- Next message: Hubert Wallgrins: "Re: Treeview: grabbing a nodes tag value (VB6)"
- Previous message: Larry Serflaten: "Re: Here's what I've decided to do [Was: Should I raise a fuss over this?]"
- In reply to: J French: "Re: Factorial"
- Next in thread: Schmidt: "Re: Factorial"
- Reply: Schmidt: "Re: Factorial"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|