On Sun, Sep 22, 2013 at 5:16 AM, Florian Apolloner <[email protected]>wrote:

>
>
> On Saturday, September 21, 2013 7:50:34 PM UTC+2, Aymeric Augustin wrote:
>>
>> But whenever the with statement spills over two lines, which happens in a
>> majority of cases, I find it worse than two with statements. It's
>> especially bad in the transactions tests — I worked in this area today.
>>
>
> Agreed; as a groundrule I'd say:
>  * If you need backslashes keep them separate
>  * If one is a test assertion keep them separate
>

I think we're all in agreement (or should be!) that backslashes are the
devil, and should be killed with fire. :-)

But I think the case is a little broader than the second one -- it's not
just test assertions, it's when the context is stateful (for want of a much
better word to describe the point).

Some context managers are just setting a local variable -- e.g., using
open() as a context manager. Setting 2+ variables in one statement is a bit
of a value judgement -- you're balancing reading multiple statements in a
single line against the 'cost' of multiple indentations. For example, I
have no problem seeing how:

with self.settings(USE_I18N=True), translation.override('pt-br',
deactivate=True):

could be seen as easier to read as a single statement, with single
indentation.

However, other context managers are heavily stateful, and the indentation
helps to describe that state. A test assertion really does "apply" to
everything "in" it. A transaction context manager wraps a very specific
block of code. In these cases, I know the language is unambiguous, but
there's value in using indentation to reinforce the physical structure,
IMHO.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to