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

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

123
<introEmbed body={<> 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

Adam Cogan
Related rules

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star