Hacker News new | ask | show | jobs
by thecatspaw 2841 days 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) }