[Python-ideas] Nudging beginners towards a more accurate mental model for loop else clauses (original) (raw)
Rob Cliffe rob.cliffe at btinternet.com
Fri Jun 8 14:05:38 CEST 2012
- Previous message: [Python-ideas] Nudging beginners towards a more accurate mental model for loop else clauses
- Next message: [Python-ideas] Nudging beginners towards a more accurate mental model for loop else clauses
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 08/06/2012 12:53, Nick Coghlan wrote:
On Fri, Jun 8, 2012 at 7:44 PM, Rob Cliffe<rob.cliffe at btinternet.com> wrote:
I think a better scheme would be to have more meaningful keywords or keyword-combinations, e.g.
for x in iterable: # do stuff ifempty: # or perhaps ifnoiter: (also applicable to while loops) # do stuff #ifbreak: # do stuff #ifnobreak: # do stuff which would give all the flexibility while making it reasonably clear what was happening. The way to be clear would actually be to drop the feature altogether (as Guido has noted in the past). Then TOOWTDI becomes: x = nodata = object() result = notfound = object() for x in iterable: if acceptable(x): result = x break if x is nodata: # No data! if result is notfound: # Nothing interesting! # Found a result, process it That's never going to happen in Python though, due to backwards compatibility requirements. FWIW, I wrote an essay summarising some of the thoughts presented in these threads: http://readthedocs.org/docs/ncoghlandevs-python-notes/en/latest/pythonconcepts/breakelse.html Cheers, Nick. Fair enough, but I think my more compact versions are more readable. Rob
- Previous message: [Python-ideas] Nudging beginners towards a more accurate mental model for loop else clauses
- Next message: [Python-ideas] Nudging beginners towards a more accurate mental model for loop else clauses
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]