Meaningful names: some tips for creating good names in your code.

Dina Farouk
DSC Alexandria
2 min readJan 1, 2021

--

Names are used frequently in your code. You give names to your variables, functions, arguments, classes, packages, source files, and directories so it's important to create good ones, here are some tips which may help you learned from “Clean Code by Robert C.Martin”.

Creator: filo | Credit: Getty Images

1.Use Intention-Revealing Names

The name you choose should tell what your variable stores or what your function does. Note that the need to comment on your name to be understood means that you better change it.

Example:

Var n ; // n stores number of students

You better change your variable name to “numberOfStudents”. This will make it easier to understand without a comment.

2.Class Names

Classes and objects names should be nouns like:

Car, Account, Customer,Student.

they should not be a verb.

3.Method Names

- Methods names should be verbs like:

postJob(),deleteUser() ,borrowBook()

-Accessors and Mutators should be named for their value and prefixed with get and set like:

String id =student.getId();

student.setName(‘Ahmed”)

4. Avoid using the same word for two purposes.

  • it is better to use one word per concept.

5. Use Solution Domain Names

-Since your code will be read by programmers you can use Computer Science terms like algorithm names, data structures names, pattern names.

Example:

JobQueue or studentsList .

choosing technical names increases your code readability.

6. Use Problem Domain Names

If technical or solution names wouldn’t express your code, you can use problem domain names so that if the other programmer doesn’t know what it means he can ask an expert what it means.

There are more rules you can follow to make your code more readable, always remember that the readability of your code will save other programmers time and effort

--

--