Usually the java libraries explicitly mention not to place OS resource
handles on the finalize() method called by the GC, that why I had the reflex
of thinking it was generally applicable to all languages with a GC.

-- 
Laurent

2009/8/31 Konrad Hinsen <konrad.hin...@fastmail.net>

>
> On 31 Aug 2009, at 14:08, Laurent PETIT wrote:
>
> > [Python]
> >
> > open(filename, 'r').read() # who cares about closing files opened in
> > read-mode?
> >
> > "who cares about closing files opened in read-mode" ?
> >
> > I would say anybody concerned about blowing up the underlying OS if
> > not releasing files handles (especially if you open files in a tight
> > loop), or do I miss something ?
>
> In this particular case, there is no reason to worry: open() returns a
> file object that is fed to the method read(), but after that method
> returns, there is no more reference to the object, so it is garbage
> collected. Upon destruction of the file object, Python closes the
> file. All that is documented behaviour in Python, so it is safe to
> rely on it.
>
> It is another question if relying on a list of reasonable but not
> evident behaviours is good style. Personally, I don't use such
> constructs in library code, but I do in scripts for personal use.
>
> In Clojure, I would be much more careful because I know the Java
> libraries less well than the Python libraries. Which illustrates that
> "good style" also depends on someone's experience.
>
> Konrad.
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to