Do you follow naming conventions for your Boolean Property?
Updated by Jeoffrey Fischer [SSW] 9 months ago. See history
public bool Enable { get; set; }public bool Invoice { get; set; }
❌ Figure: Bad example - Not using naming convention for Boolean Property
public bool Enabled { get; set; }public bool IsInvoiceSent { get; set; }
✅ Figure: 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.
Need help?
SSW Consulting has over 30 years of experience developing awesome software solutions.