Which is a better practice? (I\'m coding in .Net if that makes a difference)
IF condition = true THEN
...true action--even if rare...
ELSE
...action
E
The better practice is the second option - most common action first.
It makes it easier to read the code as you are not distracted by the code for the less used/exceptional case.
Generally, I would always put the true clause first. Something like this, for me, obfuscates meaning:
If not something Then
'do something 1
Else
'do something 2
End If
This results in a double-negative, much better to write it like this:
If something Then
'do something 2
Else
'do something 1
End If
I believe this recommendation comes from code complete. A great book well worth reading
http://www.cc2e.com/
If you're going to have more than one else then it might be better to consider a case statement.
You have received some pretty good answers already. I'm going to approach the question from a different angle.
First, as far as performance goes it may not matter as much as you think in modern CPUs. That's because they use a feature called branch prediction in which the CPU attempts to predict the most likely direction the code will take. Of course, I still agree that you should place the most likely branch at the top if performance is your main concern.
Second, I prefer readability over trivial performance enhancements. In most cases the benefit of readability outweigh those of performance.
Third, use guard clauses when possible. It makes the code more readable.
According to Steve McConnell, author of Code Complete, you should
"Put the case you normally expect to process first. This is in line with the general principle of putting code that results from a decision as close as possible to the decision...[putting the normal case after the if] puts the focus on reading the main flow rather than on wading through the exceptional cases, so the code is easier to read overall."
Code Complete, 2nd Edition, pages 356-357.
If the most common case isn't the simplest to express, you might have an opportunity for re-factoring
One useful re-factoring I've found:
if (a.getFoo() == 1 && a.getBar() == 2)
can be re-factored to
if (a.isFooBar())
In come cases something nasty like this,
if (!(fooSet.contains(a.getValidFoo())))
could be
if (a.hasInvalidFoo(fooSet))
This can make option 1 also be option 2 by simplifying the evaluation of the most common condition.
As others have said readability is generally more important. However, readability means different things to different people.
For me, it typically means arranging the if statement so that the shorter action (in terms of lines of code) comes first, so that if the statement is near the bottom of the window I'm more likely to see the "Else" on screen.
For others, placing a "Not" in the condition can really throw them, and so they'll prefer to list it so the the If condition is always as positive as possible.