Write less code

时间:2022-12-31 16:54:50

If you find yourself writing a lot of code to do something simple, you’re probably doing it wrong. A good example is the lowly boolean:

if (numMines > 0)
{
enabled=true;
}
else
{
enabled=false;
}

When you could just write:

enabled = numMines > 0;

The less code you write the better. Less to debug, less to refactor, less to go wrong. Use with moderation; readability is just as important, you don’t want to make your code less readable by doing this.

10 steps to becoming a better programmer