Re: Extension of while syntax

2014-12-13 Thread Steven D'Aprano
Nelson Crosby wrote: > I was thinking a bit about the following pattern: > > value = get_some_value() > while value in undesired_values: > value = get_some_value() > > I've always hated code that looks like this. Partly due to the repetition, > but partly also due to the fact that without be

Re: Extension of while syntax

2014-12-12 Thread Marko Rauhamaa
c...@isbd.net: > Marko Rauhamaa wrote: >> Chris Angelico : >> >> > You could deduplicate it by shifting the condition: >> > >> > while True: >> > value = get_some_value() >> > if value not in undesired_values: break >> > >> > But I'm not sure how common this idiom actually is. >> >> Ext

Re: Extension of while syntax

2014-12-12 Thread cl
Marko Rauhamaa wrote: > Chris Angelico : > > > You could deduplicate it by shifting the condition: > > > > while True: > > value = get_some_value() > > if value not in undesired_values: break > > > > But I'm not sure how common this idiom actually is. > > Extremely common, and not only i

Re: Extension of while syntax

2014-12-12 Thread Marko Rauhamaa
Chris Angelico : > On Fri, Dec 12, 2014 at 6:10 PM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> You could deduplicate it by shifting the condition: >>> >>> while True: >>> value = get_some_value() >>> if value not in undesired_values: break >>> >>> But I'm not sure how common this id

Re: Extension of while syntax

2014-12-12 Thread Chris Angelico
On Fri, Dec 12, 2014 at 7:00 PM, Mark Lawrence wrote: > It won't happen as different format loops have been discussed and rejected > umpteen times over the last 20 odd years, mainly because the code can be > restructured using break as others have already pointed out. Unless of > course you fork

Re: Extension of while syntax

2014-12-12 Thread Mark Lawrence
On 12/12/2014 02:21, Nelson Crosby wrote: I was thinking a bit about the following pattern: value = get_some_value() while value in undesired_values: value = get_some_value() I've always hated code that looks like this. Partly due to the repetition, but partly also due to the fact that wi

Re: Extension of while syntax

2014-12-11 Thread Chris Angelico
On Fri, Dec 12, 2014 at 6:10 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> You could deduplicate it by shifting the condition: >> >> while True: >> value = get_some_value() >> if value not in undesired_values: break >> >> But I'm not sure how common this idiom actually is. > > Extremel

Re: Extension of while syntax

2014-12-11 Thread Marko Rauhamaa
Chris Angelico : > You could deduplicate it by shifting the condition: > > while True: > value = get_some_value() > if value not in undesired_values: break > > But I'm not sure how common this idiom actually is. Extremely common, and not only in Python. Marko -- https://mail.python.org

Re: Extension of while syntax

2014-12-11 Thread Ben Finney
(Please don't top-post; instead, interleave responses inline with the quoted material and trim the excess. See https://en.wikipedia.org/wiki/Posting_style#Interleaved_style>.) "Clayton Kirkwood" writes: > I would prefer: > while value = initial_value in undesired_values: > value = get_so

Re: Extension of while syntax

2014-12-11 Thread Terry Reedy
On 12/11/2014 9:21 PM, Nelson Crosby wrote: I was thinking a bit about the following pattern: value = get_some_value() while value in undesired_values: value = get_some_value() This is do_while or do_until. In Python, write it as do_until in this form. while True: value = get_some_v

RE: Extension of while syntax

2014-12-11 Thread Clayton Kirkwood
Of Ben Finney >Sent: Thursday, December 11, 2014 6:38 PM >To: python-list@python.org >Subject: Re: Extension of while syntax > >Nelson Crosby writes: > >> I was thinking a bit about the following pattern: >> >> value = get_some_value() >> while value in unde

Re: Extension of while syntax

2014-12-11 Thread Chris Angelico
On Fri, Dec 12, 2014 at 1:21 PM, Nelson Crosby wrote: > I was thinking a bit about the following pattern: > > value = get_some_value() > while value in undesired_values: > value = get_some_value() > > I've always hated code that looks like this. Partly due to the repetition, > but partly also

Re: Extension of while syntax

2014-12-11 Thread Ben Finney
Nelson Crosby writes: > I was thinking a bit about the following pattern: > > value = get_some_value() > while value in undesired_values: > value = get_some_value() I think that's an anti-pattern (because of the repetition, as you say). An improvement:: value = some_default_value_such_

Extension of while syntax

2014-12-11 Thread Nelson Crosby
I was thinking a bit about the following pattern: value = get_some_value() while value in undesired_values: value = get_some_value() I've always hated code that looks like this. Partly due to the repetition, but partly also due to the fact that without being able to immediately recognise th