Skip to content

Instantly share code, notes, and snippets.

@tuanpmt
Created May 2, 2022 10:28
Show Gist options
  • Save tuanpmt/48d5a9669ee7190892624424ca1e6761 to your computer and use it in GitHub Desktop.
Save tuanpmt/48d5a9669ee7190892624424ca1e6761 to your computer and use it in GitHub Desktop.
CONDITION BREAKDOWN
/* 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