3 ms·
you dont reduce nesting by moving all checks to the beginning, you reduce nesting by moving the contents into methods. if (product.hasPrice){ if (someOtherC
by thecatspaw 8y ago
you dont reduce nesting by moving all checks to the beginning, you reduce nesting by moving the contents into methods.
if (product.hasPrice){
if (someOtherCondition){
Cart cart = cartService.getCartForCurrentUser();
cartService.addToCart(product,1);
}
}
to
if(canSellProduct(product)){
addToCurrentCart(product)
}