Created
May 2, 2022 10:28
-
-
Save tuanpmt/48d5a9669ee7190892624424ca1e6761 to your computer and use it in GitHub Desktop.
CONDITION BREAKDOWN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* BAD */ | |
if ((food.status == 'available' | |
&& user.status == 'active' | |
&& user.money > food.price | |
&& shipper.status == 'free') | |
|| (user.sos && user.call911 | |
&& food.status == 'available' | |
&& shipper.status == 'free') | |
) { | |
deliver(food); | |
} | |
/* GOOD */ | |
bool user_can_buy_food = user.status == 'active'\ | |
&& user.money > food.price; | |
bool user_need_help = user.sos && user.call911; | |
bool we_can_deliver_food = food.status == 'available'\ | |
&& shipper.status == 'free'; | |
if ((user_can_buy_food || user_need_help) | |
&& we_can_deliver_food) { | |
deliver(food) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment