-
Notifications
You must be signed in to change notification settings - Fork 309
Open
Description
On your youtube video "10 Tips to Keep Your Software Simple" timing 11:32 you state that it is better to have single responsibility functions and split one function into two. But as before split and so much after it these functions contradict DRY principle. To that, they have magic numbers. Which is not good at all.
A better solution might be with a dictionary:
HOLIDAY_CONFIG = {
"single": {"days": 1, "msg": "Have fun on your holiday..."},
"payout": {"days": 5, "msg": "Paying out a holiday. Left: {remaining_days}"},
}
def take_holiday(self, holiday_type: str) -> None:
config = HOLIDAY_CONFIG[holiday_type] # Raises KeyError if invalid
if self.vacation_days < config["days"]:
raise ValueError(f"Not enough holidays for {holiday_type}.")
self.vacation_days -= config["days"]
print(config["msg"].format(remaining_days=self.vacation_days))Metadata
Metadata
Assignees
Labels
No labels