I hate this style (from the article):
if (...) {
if (...) {
...
} else {
if (...) {
...
} else if (...) {
...
} else {
...
}
}
and prefer this: if (...)
{
if (...)
{
...
}
else
{
if (...)
{
...
}
else if (...)
{
..
}
else
{
...
}
}
}
The first example is confusing and hard to read. The second is clean and easy to read.As to the question of optimization, that's a different matter. Lots of tricks can be used to compress code into fewer statements on a case by case basis:
if(pushbutton == 0)
{
led = 12;
}
else
{
led = 24;
}
can become led = (pushbutton == 0) ? 12 : 24;
or led = (pushbutton * 12) + 12;
or led = 12 * (pushbutton + 1);
etc.