On Sun, Feb 14, 2021, 5:46 PM Steven D'Aprano <st...@pearwood.info> wrote:

> I'm curious why you say that if and with are "almost" orthogonal concepts?
> They seem completely orthogonal to me. You can mix and match them in
> literally every combination:
>

I mean in a conceptual sense, not as a matter of Python grammar.

Grammatically, I can nest 'for' and 'while' inside each other in any
combination, but they do "kinda the same thing." I genuinely need to decide
sometimes whether to use one or the other for greater clarity in a certain
bit of code. I never need to make that decision between 'if' and 'with'.

Python wouldn't be that much worse a language if it dropped one of 'for'
and 'while'. Of course I don't advocate such, but it's easy to write:

for _ in itertools.repeat(None):
    if something: break

Or alternatively,

while True:
    loopvar = next(stuff)

The only sense in which I grant "almost" to with/if is that *occasionally*
I want to perform an if test on a context object right after it's bound. In
that uncommon case, they are slightly non-orthogonal. But the same is true
of for/if and other combos.

>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/2Z4C46BBJD4XUBQQGBJFXO4AYU5EHVFG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to