Nested ifs, down to three levels if they are short, aren't all that bad if the code is sanely indented. The problems come when the ifs are long (more than 10 lines per alternative) or the code is badly formatted.
I agree. Good (not to mention correct) indentation makes a big difference. It's quite common to need two levels. Personally, if I have to go to three levels, I rethink the code so it can be done in two levels or less. When I see more than 3 levels, odds are really good that code is going to be very short lived. Of course, the more statements present in the belly of each if, the worse it gets (and the shorter its life if it's my hands.)
C/C++ programmers seem to be particularly prone to having if else if else if else ad nauseum.
I have always hated the default completion for propertiy setters:
procedure TSomeClass.SetSomeProperty(const Value: String);
begin
if Value = FString then
Exit;
FString := Value;
end;
IMO it should be just:
procedure TSomeClass.SetSomeProperty(const Value: String);
begin
if Value <> FString then
FString := Value;
end;
I like the other way (the one you don't like) because the statement that sets the value is not in the if statement. That way the statements are independent. IMO, the less coupling, the better.