Do you follow naming conventions for your Boolean Property?

Last updated by Tom Bui [SSW] 2 months ago.See history

Boolean Properties must be prefixed by a verb. Verbs like "Supports", "Allow", "Accept", "Use" should be valid. Also properties like "Visible", "Available" should be accepted (maybe not). See how to name Boolean columns in SQL databases.

public bool Enable { get; set; }
public bool Invoice { get; set; }

Bad example - Not using naming convention for Boolean Property

public bool Enabled { getset; }
public bool IsInvoiceSent { get; set; }

Good example - Using naming convention for Boolean Property

Naming Boolean state Variables in Frontend code

When it comes to state management in frameworks like Angular or React, a similar principle applies, but with a focus on the continuity of the action.

For instance, if you are tracking a process or a loading state, the variable should reflect the ongoing nature of these actions. Instead of "isLoaded" or "isProcessed," which suggest a completed state, use names like "isLoading" or "isProcessing."

These names start as false, change to true while the process is ongoing, and revert to false once completed.

const [isLoading, setIsLoading] = useState(false); // Initial state: not loading

Note: When an operation begins, isLoading is set to true, indicating the process is active. Upon completion, it's set back to false.

This naming convention avoids confusion, such as a variable named isLoaded that would be true before the completion of a process and then false, which is counterintuitive and misleading.

We have a program called SSW CodeAuditor to check for this rule.

We open source. Powered by GitHub