HACKER Q&A
📣 zupzupzup

What's your simple but favourite coding trick?


When I started programming, 5-6 months into it, I was introduced to a very interesting trick/pattern by one of my mentors.

func(){

    if() {

    } else {

    }
}

can be beautifully converted to

func(){

    if() {
    
     
        return; 
    }

    // Write the else code here.
 
}

The reduced indentation gave a weird sense of relaxation. It was such a neat little trick.

What about you guys. Any common tricks which everyone can use.


  👤 catacombs Accepted Answer ✓
From your example, an even more concise way can be written using ternary operations in any C-style language:

    int i = 10;
    bool is_10 = (i === 10) ? TRUE : FALSE;