I'm working on an installation script, and especially there I have many things that need to be checked and actions that only need to be performed in case of related outcomes. For example, a folder only needs to be created if it doesn't exist:
MyDesktopFolderPath := AddBackslash(ExpandConstant('{commondesktop}')) +
'My Folder';
if not DirExists(MyDesktopFolderPath) then
begin
ForceDirectories(MyDesktopFolderPath); //Create full path
end;
if DirExists(MyDesktopFolderPath) then
begin
//Perform other actions
Instead of this, I could use (exploit?) short-circuit evaluation to make it more compact:
MyDesktopFolderPath := AddBackslash(ExpandConstant('{commondesktop}')) +
'My Folder';
IsMyDesktopFolderExisting := DirExists(MyDesktopFolderPath) or
ForceDirectories(MyDesktopFolderPath);
if IsMyDesktopFolderExisting then
begin
//Perform other actions
This would work too, but I wonder if it is bad practice, mostly because it is less obvious that actions might be performed. Any opinions on that?
Edit: As pointed out by Secure, the code is not completely equivalent, but the discussion topic still stands for other cases.