Avoid brackets for conditionals

Curly brackets take additional brain power that could be used for better things.

If you encounter some conditional code in curly brackets in your code, chances are that it could be broken up in order to create smaller “bites” for your brain to chew on. Consider this:

void ReactToCustomerInnput()
{
    if(customerConfirmedOrder)
    {
        UdateOrderStatus(order);    
        RegisterOrderInSystem();
        OpenOrderConfirmedView();
    }
    else GoBackToOrderOverview();
}

And compare with this:

void ReactToCustomerInnput()
{
    if(customerConfirmedOrder) FinalizeOrder();
    else GoBackToOrderOverview();
}

This rule isn’t about the brackets themselves at all – it’s just about using brackets as an indicator where we can split some logic in the spirit of the Principle of Least Distraction.

Next Article: Favor early Returns over Short-Circuits