[comp.edu] Poor Algorithms

nevin1@ihlpf.ATT.COM (00704a-Liber) (02/26/88)

[Note:  this article has been posted to two groups.  When you post
followups, please pick the group which your followup is more relevant to.]


In article <1010@cos.COM> smith@cos.UUCP (Steve Smith) writes:

>Seems they had an Oceanography professor who did a lot
>of flow modeling.  Like most such programs, his used a big xyz array to
>handle flow elements.  As it turned out, one xy plane fitted nicely into
>one virtual memory page.  Unfortunately, for no good reason, he had
>chosen to scan it first in the x direction and second in the z
>direction.  Result - page faults up the wazoo!

CS people do this kind of stuff, too.  In college, CS students are taught
to write their code as OS/architecture independent as possible; ie, they
shouldn't write programs that are specific to the machine they are running
on.  Most colleges don't offer an OS course until senior year.

So what happens when Joe Programmer needs to do a 'real' application?  He
writes it with the same old philosophy in mind:  Make it OS independent,
make it architecture independent, make it language-implementation
independent, make it machine independent, etc.

But real applications *are* for specific machines.  I'm not saying that
machine *dependent* code should be written, though (code should be as
portable as is reasonable).  I am saying that code should be written to
take advantage of the primary OS or architecture that it is running on.

How many novice Pascal programmers use many global vars because it saves
memory?  On a paging system, though, you may need more pages in real memory
because of the way the chaining of variables is done in Pascal.

Or look at C.  A lot of programmers use a char or a short for a local
variable where an int would do (although there are some algorithms where
this may not be desirable).  But the runtime overhead that is incurred
(such as that due to implicit variable coersion) is probably not worth it.
Another point: on a paging system, it may be better to have a static lookup
table than to generate data every time it is needed.

When trying to write efficient algorithms for a specific purpose, you must
take into account the OS, architecture, language-implementation, machine,
etc.
-- 
 _ __			NEVIN J. LIBER	..!ihnp4!ihlpf!nevin1	(312) 510-6194
' )  )				"The secret compartment of my ring I fill
 /  / _ , __o  ____		 with an Underdog super-energy pill."
/  (_</_\/ <__/ / <_	These are solely MY opinions, not AT&T's, blah blah blah