[comp.software-eng] Poor Algorithms

sommar@enea.se (Erland Sommarskog) (03/02/88)

Nevin J Liber (nevin1@ihlpf.UUCP) writes:
>[Note:  this article has been posted to two groups.  When you post
>followups, please pick the group which your followup is more relevant to.]

And I deleted comp.edu and added comp.software-eng which seems be 
to a more approriate place for further discussion. 

>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.

This reminds me of when I did my exam work. My task was to do a
capacity analysis of the file system of a 68000-based machine. Since
this file system was quite buggy I had to check the sources to see
what happened. The langauge used was EriPascal, a Pascal extention
with Modula-2 module concept and real-time primitives.
  Nevin would have loved them. They used a lot of global variables. 
A typical procedure could have some local variables, but mostly they
used the used the global ones, even for typical local purposes. To
make it even more fun, all variables had one-letter prefixes like
cnumber, cix etc. And on top of all, the modules were *huge*. 6000
lines or so.
  Now, was this a fast and speedy file system? Laugh. Reading a 
record from a 100 record-index file with variable-length fields 
could take 3 seconds. With a Winchester. No, no time-sharing. At 
disk-manager level, reading a specified block in a file was randomly 
distributed between 100 and 300 ms. 
  Talk about poor algorithms. You should have seen the code for
finding a particular block. In practice they counted on their
fingers, making complicated a MOD for every decrement. Not takling
of the procedure that allocated disk blocks. 27 Gotos into 150
lines of code. Yes, there was a bug in it.

So moral: You may save some execution time by having your variables
global, but you since you are obscuring your code so fatally,
you will lose the notion of what you are doing and introduce
bugs and inefficiencies instead.

Oh, it should be added that the file system I talked of has since then
been improved. I have no idea of how it works today.
-- 
Erland Sommarskog       
ENEA Data, Stockholm        
sommar@enea.UUCP           "Souvent pour s'amuser les hommes d'equipages
                            and it's like talking to a stranger" -- H&C.