Sitemap

Member-only story

7 Deadly Sins of Variable Naming (And How to Fix Them)

7 min readJun 9, 2025

--

credit goes to the owner: https://blog.geekster.in/java-identifiers/
source: blog.geekster.in

Writing good code is like writing a story. You want people to read it and understand what happens without getting confused. One of the biggest mistakes programmers make is giving bad names to their variables. Bad variable names make code hard to read and even harder to fix later.

In this article, we will look at 7 common mistakes people make when naming variables in Java. We will also show you how to fix these problems with simple examples.

Sin #1: Using Single Letters for Everything

Many new programmers think using single letters like a, b, c, x, or y is fine. This is wrong in most cases.

Bad Example:

int a = 25;
int b = 30;
int c = a * b;
System.out.println("Total: " + c);

What do these variables mean? Nobody knows! You have to read the whole code to guess what they do.

Good Example:

int studentAge = 25;
int hoursWorked = 30;
int totalPay = studentAge * hoursWorked;
System.out.println("Total: " + totalPay);

Now anyone can read this code and understand what each variable does right away.

When Single Letters Are OK:

  • Loop counters: for (int i = 0; i < 10; i++)

--

--

Naveen Metta
Naveen Metta

Written by Naveen Metta

I'm a Full Stack Developer with 3+ years of experience. feel free to reach out for any help : mettanaveen701@gmail.com

No responses yet