DawnDawnSat Aug 4 02:59:45 2001
Orbiting Symbols
Topics: Programming

Just did some code changes to my netdiary software. Substantial code cleanups, and they're beautiful too. Here's the relevant part of the old code:

my @files = readdir(SUMDIR); # read all the files closedir(SUMDIR);

my @filelist = sort {$b <=> $a} @files; # Numerically sort them fit: for($idx=0; $idx <= $#filelist; $idx++)

     {
     if($filelistLINK =~ /summary/i){next fit;} # skip index
     if($filelistLINK =~ /\./) {next fit;} # Skip '.' and '..'
     parsefile($filelistLINK); # Actually parse a file
     }
And the new code:

my @files = # List of files is

     sort {$b <=> $a}  # a numerically sorted list
     grep !/^\./,      # Skipping . and ..
     grep !/^summary/, # and skipping the summary file
     readdir(SUMDIR);  # from all the files
closedir(SUMDIR);

for($idx=0; $idx <= $#files; $idx++)

     {
     parsefile($filelistLINK);
     }

For some odd reason, the way those function calls nest creates a strange image in my mind, like an ordinary program would be like

-------------------------------

But that part is more like
                ^
---------------/ \---

And I can imagine rewriting it to pull that loop even higher, as fewer portions between statements exist and things nest further. For some reason, I'm getting thoughts that perhaps with sufficient thought, the entire program could be written going up rather than going across, although that might look ugly (both in metaphor and in the actual code). Maybe that's what LISP and similar languages would normally look like.



Time Heals All Wounds.. And Then Kills the Patient
Previous Next