Developer 101 - Naming Conventions for Variables and Methods

Discover the importance of clean, consistent naming conventions in your code. Learn the best practices for naming variables and methods in different programming languages. From camelCase to PascalCase, make your code more readable and maintainable. Join us at TechWayFit to level up your developer hygiene.

Developer 101: Naming Conventions for Variables and Methods

Published by TechWayFit

Discover the importance of clean, consistent naming conventions in your code. Learn the best practices for naming variables and methods in different programming languages. From camelCase to PascalCase, make your code more readable and maintainable.

Why Naming Conventions Matter

  • Improves readability and understanding across teams
  • Makes debugging and refactoring easier
  • Ensures consistency across projects and languages

Popular Naming Styles

Convention Example Used For
camelCase userName Variables, methods (JavaScript, Java)
PascalCase UserProfile Classes, constructors (C#, TypeScript)
snake_case user_name Variables, functions (Python)
UPPER_CASE MAX_LIMIT Constants (Java, C)

💡 Naming Is for Humans, Not Machines

Machines don’t care what your variable is called — they'll execute your code whether it’s x, temp1, or totalCustomerRevenue.

But your colleague, support engineer, or future self does care. Coding practices like naming conventions aren’t for the computer — they’re for the people who read, maintain, debug, and build on your code.

⚠️ Common Bad Naming in C#

// ❌ Bad Examples
int a = 25;
string str1 = "hello";
bool isIt = true;
float t1 = 9.8f;
var tmp = GetData();

// ✅ Good Examples
int maxRetryCount = 25;
string userGreeting = "hello";
bool isEmailVerified = true;
float gravityConstant = 9.8f;
var customerList = GetCustomerData();

👽 Alien Variables — What NOT to Do

Variable Name Looks Like Why It's Alien
xx1, aa, z0 int xx1 = 10; No context or meaning
flag1 bool flag1 = true; Flag for what?
doit void doit() Do what exactly?
data1 var data1 = Get(); Data of what?
obj object obj = new(); Extremely generic, not helpful

Code Readability in Action: Leap Year Example

❌ Bad Naming
public class C
{
    public bool F(int y)
    {
        return (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
    }
}
✅ Good Naming
public class LeapYearChecker
{
    public bool IsLeapYear(int year)
    {
        return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
    }
}

Code Readability in Action: Prime Number Example

❌ Bad Naming
public class P
{
    public bool C(int n)
    {
        for (int i = 2; i < n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
}
✅ Good Naming
public class PrimeNumberChecker
{
    public bool IsPrime(int number)
    {
        for (int divisor = 2; divisor < number; divisor++)
        {
            if (number % divisor == 0) return false;
        }
        return true;
    }
}

Code Readability in Action: Real Example

❌ Bad Naming Example
public class A {
    public void Do() {
        var x = Get();
        foreach (var i in x) {
            if (i.f1 > 18 && i.f2 == true) {
                Console.WriteLine("OK");
            }
        }
    }
    private List<B> Get() {
        return new List<B>();
    }
}

public class B {
    public int f1;
    public bool f2;
}
Problems: Names like A, x, i, f1 are meaningless. It's unclear what the code does.
✅ Good Naming Example
public class CustomerService {
    public void PrintAdultVerifiedCustomers() {
        var customers = GetAllCustomers();
        foreach (var customer in customers) {
            if (customer.Age > 18 && customer.IsEmailVerified) {
                Console.WriteLine("OK");
            }
        }
    }
    private List<Customer> GetAllCustomers() {
        return new List<Customer>();
    }
}

public class Customer {
    public int Age;
    public bool IsEmailVerified;
}
Why it works: The method, variables, and class names clearly express intent. Anyone reading this can instantly grasp the logic and purpose.
💬 Join the discussion on our TechWayFit Discord to share your naming tips!