You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In our company we've made it mandatory to always have a else part in all case of statements, even if nothing should be done in that scenario.
If nothing should be done in the else part, we just add an empty statement with a comment, like this example:
case EnumValue of
SomeEnum::First:
Message('Whatever);
SomeEnum:Second:
Message('Some message.');
else
; // No other scenarios need a message
end;
(The empty statement with a comment is hopefully allowed soon if #747 gets implemented)
In this way the code reader know that this is fully intentional, compared to a missing else.
I suggest a new rule that makes else mandatory in all case of statements.
We also do a lot of telemetry (that creates alerts, with stack traces etc.) and throw errors in the else parts that should not be possible.
Like this:
case EnumValue of
SomeEnum::First:
Message('Whatever);
SomeEnum:Second:
Message('Some message.');
else
TelemetryManagement.SendProgrammingErrorTelemetryAndThrowError('SomeEnum "%1" is not supported. This is a programming error.', EnumValue );
end;
A new rule would be a great help to identify if we've missed the else part somewhere.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In our company we've made it mandatory to always have a
else
part in allcase of
statements, even if nothing should be done in that scenario.If nothing should be done in the
else
part, we just add an empty statement with a comment, like this example:(The empty statement with a comment is hopefully allowed soon if #747 gets implemented)
In this way the code reader know that this is fully intentional, compared to a missing
else
.I suggest a new rule that makes
else
mandatory in allcase of
statements.We also do a lot of telemetry (that creates alerts, with stack traces etc.) and throw errors in the
else
parts that should not be possible.Like this:
A new rule would be a great help to identify if we've missed the
else
part somewhere.Beta Was this translation helpful? Give feedback.
All reactions