[Python-ideas] an unless statement would occasionally be useful

Neil Girdhar mistersheik at gmail.com
Tue May 19 17:42:48 CEST 2015


This is hilarious.

Although to be fair, test might be useful if for example, you test types in 
one thread and run code optimized for that type in another…

On Sunday, May 17, 2015 at 5:40:59 PM UTC-4, Andrew Barnert via 
Python-ideas wrote:
>
> On May 17, 2015, at 11:07, Charles Hixson <charle... at earthlink.net 
> <javascript:>> wrote: 
> > 
> > I'm envisioning "unless" as a synonym for "if not(...):"  currently I 
> use 
> > 
> > if .... : 
> >    pass 
> > else: 
> >  ... 
> > 
> > which works. 
> > 
> > N.B.:  This isn't extremely important as there are already two ways to 
> accomplish the same purpose, but it would be useful, seems easy to 
> implement, and is already used by many other languages.  The advantage is 
> that when the condition is long it simplifies understanding. 
>
> But if you just use not instead of else, it simplifies understanding just 
> as much--and without making the language larger (which makes it harder to 
> learn/remember when switching languages, makes the parser bigger, etc.): 
>
>     if not ...: 
>         ... 
>
> It seems like every year someone proposes either "unless" or "until" or 
> the whole suite of Perl variants (inherently-negated keywords, postfix, 
> do...while-type syntax), but nobody ever asks for anything clever. Think of 
> what you could do with a "lest" statement, which will speculatively execute 
> the body and then test the condition before deciding whether to actually 
> have executed the body. Or a "without" that closes a context before the 
> body instead of after. Or a "butfor" that iterates over every extant object 
> that isn't contained in the Iterable. Or a "because" that raises instead of 
> skipping the body if the condition isn't truthy. Or a "before" that 
> remembers the body for later and executes it a synchronously when the 
> condition becomes true. 
>
>
>
> > _______________________________________________ 
> > Python-ideas mailing list 
> > Python... at python.org <javascript:> 
> > https://mail.python.org/mailman/listinfo/python-ideas 
> > Code of Conduct: http://python.org/psf/codeofconduct/ 
> _______________________________________________ 
> Python-ideas mailing list 
> Python... at python.org <javascript:> 
> https://mail.python.org/mailman/listinfo/python-ideas 
> Code of Conduct: http://python.org/psf/codeofconduct/ 
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150519/71b1341b/attachment.html>


More information about the Python-ideas mailing list