Do you know how to avoid problems in if-statements?

Updated by Brady Stroud [SSW] 1 year ago. See history

123

Try to avoid problems in if-statements without curly brackets and just one statement which is written one line below the if-statement. Use just one line for such if-statements. If you want to add more statements later on and you could forget to add the curly brackets which may cause problems later on.

if (ProductName == null) ProductName = string.Empty; if (ProductVersion == null)
ProductVersion = string.Empty; if (StackTrace == null) StackTrace = string.Empty;

❌ Figure: Figure: Bad Example

if (ProductName == null)
{
ProductName = string.Empty;
}
if (ProductVersion == null)
{
ProductVersion = string.Empty;
}
if (StackTrace == null)
{
StackTrace = string.Empty;
}

✅ Figure: Figure: Good Example

acknowledgements
related rules