Meaningful Names - Code Review Checklist with Example - The Koch Family
The Koch Family The Koch Family

Latest news

جاري التحميل ...

Meaningful Names - Code Review Checklist with Example

"Names are everywhere in software". "The hardest thing about choosing good names is that it requires good descriptive skills"[1]. In my previous post, I emphasized that we should take care our code, so now let's start with naming.

Original code
Revised code
Reveals nothing
int d; //elapsed time in days
int elapsedTimeInDays;
Difficult to understand
public List<Cell> getThem()

public List<Cell> getFlaggedCells()

Specific to programmers
public void copyChars(char a1[], char a2[])
public void copyChars(char source[], char destination[])
Noise words (indistinguishable)
customerInfo vs customer;
accountData vs account
customer, account //distinguish names in such a way that the reader knows what the differences offer
Silly made-up words
class DtaRcrd02{
 private Date genymdhms;
class Customer{
 private Date generationTimestamp;
Poor name
for(int j=0 ;  j<34 ;  j++){
   s += (t[j]*4)/5;
int realDaysPerIdealDay = 4;
const int WORK_DAYS_PER_WEEK = 5;
const int NUMBER_OF_TASK = 34;
Member prefixes
private String m_dsc; 
private String description;
Interfaces prefixes
Constructors with args
Complex point = new Complex(23.0)
Complex point = Complex.FromRealNumber(23.0)
//use static factory that describe the args
Form of colloquialisms or slang
Different methods name of different classes with same code base
fetch(), retrieve(), get()
get() //pick one word for one abstract concept and stick with it
Different class name in the same code base
Controller, manager, driver
The variable names are not clear when they are used alone in a method
street, houseNumber, city, state
//Solution 1: prefix addressStreet, addressHouseNumber, addressCity, addressState
//Solution 2: create a class Address



If you like the content of our blog, we hope to stay in constant communication, just enter your email to subscribe to the blog's express mail to receive new blog updates, and you can send a message by clicking on the button next ...

إتصل بنا

About the site

author The Koch Family <<  Welcome! I'm so glad that you stopped by Your Modern Family blog. Together, we will talk about raising kids, organizing the home and saving money! and Tips & tricks and more…

< Learn more ←

Blog stats

Sparkline 2513183

All Copyrights Reserved

The Koch Family