You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Are there plans to add support for labeled for, while, break, and continue statements?
Reasons
This feature is primarily intended for correctness' sake, but also convenience.
Correctness: Say I'm refactoring:
while ...:
# big code block 1for ...:
# big code block 2# big code block 3break# big code block 4
into something like
while ...:
# big code block 1# big code block 3break# big code block 4
The break statement was intended to only apply to the inner loop, but amidst the KLOC's I accidently left the break statement inside the outer loop. This is not correct. Labeled break's would prevent this issue.
Convenience: I often write small loops to check any possible valid condition and apply this check to an entire sequence. Usually, simplicity requires lifting the entire nested loops into their own function. For example,
"""Checks if a board state ever had a 1 adjacent to the player"""defreadable_check(trajectory):
forpos, boardintrajectory:
fordirin [N, S, E, W]:
ifboard[pos+dir] ==1:
returnTruereturnFalsetrajectory= ...
# check if player was ever touching a 1check=readable_check(trajectory) # readable, not concise, not inlinecheck=any(board[pos+dir] ==1forboardintrajectoryforposin [N, S, E, W]) # concise, not super readable, inline# readable, not concise, inlinecheck: boolforpos, boardintrajectory:
fordirin [N, S, E, W]:
ifboard[pos+dir] ==1:
check=Truebreakifcheck:
breakelse:
check=False
Maybe it's just my opinion, but I think labeled breaks and continues would be a more pleasant way to express myself here:
Are there plans to add support for labeled
for
,while
,break
, andcontinue
statements?Reasons
This feature is primarily intended for correctness' sake, but also convenience.
Correctness: Say I'm refactoring:
into something like
The
break
statement was intended to only apply to the inner loop, but amidst the KLOC's I accidently left the break statement inside the outer loop. This is not correct. Labeled break's would prevent this issue.Convenience: I often write small loops to check any possible valid condition and apply this check to an entire sequence. Usually, simplicity requires lifting the entire nested loops into their own function. For example,
Maybe it's just my opinion, but I think labeled
break
s andcontinue
s would be a more pleasant way to express myself here:The text was updated successfully, but these errors were encountered: