I don’t want to provide more opportunities to postpone what I would consider to be the necessary refactoring
Please excuse me but “I don’t want this feature to be added because otherwise [I, people] won’t have an incentive not to be lazy anymore” is a pretty poor argument.
I can’t actually picture in my mind real maintainable code where labelled break is significantly better than a reorganisation.
They are not mutually exclusive. People can reorganize their code all they want and if they find they still need labeled breaks, they should be there for them.
As I explained, a reorganization does not solve all issues. You can’t have full loop control with both continue and break unless you split it in completely unnatural ways with lots of handle_this_loop and handle_that_loop functions. If you are doing all this just to get some pretty basic functionality, I think it’s pretty clear the language is lacking in some way.
Learn proper refactoring and your future self (and every else who read your code, including your coworkers who review it) will thank you. Do as Serhiy: create a function and use it only once.
Let’s get back to this “fine control” to jump out of multiple loops. Do you have actual examples of real code that needs this “fine control”, or is this purely hypothetical?
So start with actual code that needs to be written, and THEN figure out what the best way to write it
Do you have actual examples of real code that needs this “fine control”, or is this purely hypothetical?
Here is a minimal example based on my real-life problem, which I solved using flags in actuality. How would you refactor the code below? Let’s compare and see which one is cleaner, easier to read and implement. I already know for a fact, beyond all doubt that this looks MUCH better than using flags, let’s see how your solution compares.
for league in all_basketball_leagues as league_loop:
number_of_incomplete_players = 0
for player in league as player_loop:
for season in player.seasons as season_loop:
number_of_incomplete_game_data = 0
for game_stats in season:
stats_successfully_processed = process_game_stats(game_stats)
# key table not in game_stats or another problem
if not stats_successfully_processed:
number_of_incomplete_game_data += 1
if number_of_incomplete_game_data > 5:
number_of_incomplete_players += 1
if number_of_incomplete_players > 60:
# too much missing data, league unusable
continue league_loop
else:
# too much missing data, season unusable
continue season_loop
# if key table missing, skip game
else:
continue
# no key tables missing, check game stats
number_of_missing_values = 0
for table in game_stats:
if not check_table_integrity(table):
number_of_missing_values += 1
if number_of_missing_values > 5:
number_of_incomplete_game_data += 1
if number_of_incomplete_game_data > 5:
continue season_loop
else:
continue
# table is perfect
else:
do_stuff()