Too Many Open Files (was Re: The CLOSE command)

Jeff Harrison jeffaharrison at yahoo.com
Fri Feb 17 17:42:46 PST 2006


--- Fairlight <fairlite at fairlite.com> wrote:

> This public service announcement was brought to you
> by Jeff Harrison:
> > 
> > Ah, but why not have filepro do it automatically? 
> > There are many instances where filepro does the
> > reasonable thing - such as automatically
> protecting
> > lookups when a write occurs.  
> 
> Erm...then what's the -p for in the lookup
> statement?  Would it not then be
> superfluous?
> 

No its not.  One should always use the -p flag on
lookups that could eventually be written to.  Filepro
will automatically place a lock on the file - if one
is not there already - when an actual assignment takes
place, but this may be too late if someone has in the
meantime grabbed that record.  Using -p flag prevents
this possibility.

> > In my opinion most filepro programmers are "close
> > happy".  By that I mean they issue unnecessary
> closes
> > to files all the time - often just to use it again
> > soon after the close - instead of letting filepro
> > handle the closing where it can and should.
> > 
> > This issue, unfortunately, could well have the
> result
> > of making programmers even more "close happy".
> 
> I can't speak to the issue of people trying to use
> something again after
> they've closed it.  
> 
> However, the concept of "close happy" obviously
> comes from someone that has
> never had to write anything that needs to be
> resource-conservative as
> possible.  

[snip]

I would consider that an example of needing to close
the lookup(s).  If resources are a problem then close
that lookup.  Be sure to know where you need to put
the close though.

> 
> CLOSE() is -not- just for the system-level language
> programmer (C, etc.).
> It's a good practise to use as few resources as
> possible at any given point
> in -any- environment.  Doing so leads to faster,
> leaner, more efficient
> software.

Methinks you are close happy :-)  Here is an example
of what I am talking about.  Say you have an parts
file where you look up static information for a given
part number, and you are in the process of entering a
number of orders that have multiple parts on each
order.  Here is a bad subroutine to do this:

getpart:::
::lookup inv = parts k=ky i=a -nx:
::aa=inv(1); ab=inv(2)  '... etc.:
::close inv:
::return:

or even the customer file...

getcust:::
::lookup cus = customer k=kz i=a -nx
::ba=cus(1); bb=cus(2)  ' ... etc:
::return:

This is stupid.  You are going to need to look to the
parts file and the customer file again and again.  Why
close and re-open it all the time?  This would be VERY
inneficient.

> 
> > In my opinion you should only close lookups when
> there
> > is a need to do so.  Failed or not I would
> GENERALLY
> 
> Only bother closing your door if you see someone has
> come in and stolen
> your stereo?  Is that about it?
> 
> It's all about the old ounce of prevention saw.  A
> close (without requiring
> another lookup or open -if- the resource is not
> going to be needed again)
> costs you nothing and can net you increased
> stability and efficiency.

All I'm saying is that you should know when to use the
close statement.  I have no problem with using a close
after a one-time lookup (although I usually don't even
do that unless it is necessary).  Unfortunately, that
is not what I see out there.

> 
> "Programmers" that open a cartload of things and let
> the final exit() close
> everything for them are a never-ending source of
> amusement to those of us
> that know better.  The black box of fP magically
> closing files is about the
> same scenario--you're still using far more than you
> need to until the final
> exit if you have 20 or 30 open and don't need more
> than 2 open by the time
> you've gotten there.
[snip]

So what?  You have a few more files open than your
need.   I believe that the alternative of too many
opens and closes is far more costly.  Again, filepro
will close the files as needed.  If it does not, then
it is a bug in my opinion and should be fixed.


> The more I hear sometimes, the more I believe 4GL
> coding is akin to AOL or
> WebTV.  It lets any idiot do it--and thus too many
> do.  Some of the things
> I've heard full-time professionals argue in favour
> of are things that any
> halfway seasoned part-time hobbyist should know
> better than to do.  A fact
> that never ceases to astound and depress me, I might
> add.
> 
> mark->

Funny, I feel the same way.

Jeff Harrison
jeffaharrison at yahoo.com

Author of JHExport and JHImport.  The easiest and
fastest ways to generate code for filePro exports and imports.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Filepro-list mailing list