On Thu, Dec 5, 2013 at 11:25 AM, Santi Raffa <[email protected]> wrote:

> On Thu, Dec 5, 2013 at 10:58 AM, Thomas Thrainer <[email protected]>
> wrote:
> > I don't quite like this 'with' construction here: It hides the fact that
> > there are rather complex operations (mounting and later unmounting) are
> > going on, which can even fail randomly here. Something like try-finally
> or
> > 'with self.volume.Mount()' would make it much more readable (if I were to
> > choose, I'd go for the try-finally approach). What do you think?
> >
> > The same holds true for all other 'with' constructs for mounting.
>
> I personally don't think expectation of non-complexity is necessarily
> there with a with statement; even just a run-of-the-mill "with
> file(foo) as fobj:"


True, there you get a fobj with which you are doing something. IMHO, this
makes it more obvious to the reader that the with actually did something
and returned something to you.
Also, the more prominent example is 'with open(...) as f', where it's
immediately obvious that an 'open' call is issued. In fact, the 'with
file(...) as fobj' form is even discouraged to use in the Python docs (
http://docs.python.org/2/library/functions.html?highlight=file#file).

'with self.volume' doesn't tell the reader, who doesn't know the internals
of the GlusterVolume class, what's happening. That's why I proposed to
change it to 'with self.volume.Mount()', which reads much better IMHO (and
it's not so hard to return a small context object in Mount which unmounts
once going out of the context).


> line requires you to make system calls (and, with
> networked file systems such as Gluster, this can be absolutely
> non-trivial); otoh by using with we get guarantees from the language
> that a volume unmount _will_ be tried no matter what and that
> exceptions within the with: block will be handled correctly - all with
> cleaner, simpler code.
>
> --
> Raffa Santi
> Google Germany GmbH
> Dienerstr. 12
> 80331 München
>
>
> Registergericht und -nummer: Hamburg, HRB 86891
> Sitz der Gesellschaft: Hamburg
> Geschäftsführer: Graham Law, Christine Elizabeth Flores
>



-- 
Thomas Thrainer | Software Engineer | [email protected] |

Google Germany GmbH
Dienerstr. 12
80331 München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores

Reply via email to