aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • Engineering
  • Programming

Writing Clean Code: Naming

  • root
  • October 23, 2021
  • 5 minute read

When you start learning how to code your main focus is writing code that works correctly for the problem you are solving. Yes, code needs to work correctly and that is a good place to start learning. However, in a real work environment, you also want to ensure you write clean code.

Clean code is readable, extensible, changeable, and maintainable. These are all important qualities for a codebase to have.


Partner with aster.cloud
for your next big idea.
Let us know here.



From our partners:

CITI.IO :: Business. Institutions. Society. Global Political Economy.
CYBERPOGO.COM :: For the Arts, Sciences, and Technology.
DADAHACKS.COM :: Parenting For The Rest Of Us.
ZEDISTA.COM :: Entertainment. Sports. Culture. Escape.
TAKUMAKU.COM :: For The Hearth And Home.
ASTER.CLOUD :: From The Cloud And Beyond.
LIWAIWAI.COM :: Intelligence, Inside and Outside.
GLOBALCLOUDPLATFORMS.COM :: For The World's Computing Needs.
FIREGULAMAN.COM :: For The Fire In The Belly Of The Coder.
ASTERCASTER.COM :: Supra Astra. Beyond The Stars.
BARTDAY.COM :: Prosperity For Everyone.

In many professional settings, you are not writing code in complete isolation. There are other people you work with on a team. Your teammates need to be able to easily understand the code you write. They need to understand what it does, how it works, and why it was written that way. It may also be your future self coming back to code you wrote in the past and you will also need to easily understand your code.

Code is read more than it is written. To write code we are constantly reading it. So even if readable code is harder to write we should invest time to do it instead of writing easy unreadable code. Writing clean code is an important skill for any professional developer.

In this article, we are going to learn about the importance of Naming in writing clean code.

Naming is a crucial and daily task for developers in any programming language. It can either make code very hard to understand or if done well, easy to understand.

Names are all over the software developers write. When coding, you should consider naming variables, functions, arguments, classes, packages, source files, and directories that contain those source files, etc.

Below are some popular quotes on naming in programming.

“There are only two hard things in Computer Science: cache invalidation and naming things.” – Phil Karlton

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand” — Martin fowler

Names are the smallest building block of code. Names are the basic building block of clean code. There are some recommended rules for good naming in code. Let us discuss these rules for the rest of this article.

Use intention revealing names

The names you use in your code must be clear and understandable. Choose descriptive and unambiguous names. You should focus on the principle of least surprise. Aim to write code that other people would expect and try not to surprise them with some clever complexities.

The name of a variable, function, or class, should answer all the big questions. It should tell you why it exists, what it does, and how it is used. If a name requires a comment, then the name is not intention revealing.

Below is an example of code that is not intention revealing because it requires a description comment. Just below it, you’ll find a cleaner version with better naming that does not require a description comment.

let rf = 5000 //the rental fee paid by the tenant

use the cleaner version below

let rentalFee = 5000

Classes and objects should have noun or noun phrase names

Classes and objects describe things so their names in code should be a noun or noun phrase. Names such as User, Student, Account, and ErrorLogger are good names for classes and objects. Avoid words like Manager, Processor, Data, or Info in the name of a class. A class name should not be a verb.

Methods/Functions should have verb or verb phrase names

Methods/Functions perform an action in the code so their names should be a verb or verb phrase. Names such as deleteApplication, createUser, or save are good names for methods/functions. By design, a function should have only one responsibility. If the name is anything other than a verb, then either you are naming it wrong or there are some problems in the architecture.

Make meaningful distinctions

You should try to use the same word for the same purpose across the codebase. Avoid using different but similar words to define the same concepts. For example, the three method/function calls below could mean the same thing.

FetchResult() vs GetResult() vs RetrieveResult()

Don’t use fetch, get and retrieve in the same project for the same responsibility.

Use pronounceable and searchable names

When naming things in your code use words that can be pronounced rather than using non-pronounceable words.

Below is an example of a variable name that is not easily pronounceable and a cleaner version with a more pronounceable name.

Date modymdhms;

use the cleaner version below

Date modificationTimestamp;

Replace magic numbers with named constants

When you are using some constant values define them using searchable words. It makes them more understandable to other developers.

Instead of writing code like this:

let totalLoanDays = gracePeriod + 7;

create a named constant and use it like this:

const NUMBER_OF_DAYS_IN_WEEK = 7;
let totalLoanDays = gracePeriod + NUMBER_OF_DAYS_IN_WEEK;

Don’t append type information

When you name your variables avoid appending type information to them. It should be clear from the name of the variable what data it stores and developers can infer the type from there. There is no need to mention the data type in the name.

Instead of writing code like this:

let firstNameString;
let lastNameString;

Use the cleaner version below:

let firstName;
let lastName;

Don’t Be Offensive / Don’t Be A Comedian

Remain professional in how you name things in your code. Do not be offensive or try to be a comedian by giving a variable a funny name. Remember, you are writing production code that other software developers will need to understand easily in the future. Your naming conventions should be generic and should not include any cultural slang.

Avoid writing code like this:

function killThemAll();

use the cleaner and professional version below

function deleteAllUsers();

Closing thoughts

In this article, we have explored some of the best practices for naming things in your code, and some things you should avoid doing. Naming may appear to be a small part of a software developer’s job but it is very important and can be the main difference between having a clean codebase that is a joy to work with or a complex codebase that is difficult to understand and navigate.

“One difference between a smart programmer and a professional programmer is that the professional understands that clarity is king. Professionals use their powers for good and write code that others can understand.”

You should never ignore the importance of naming practices in your codebase as bad names will become a big hurdle in future development plans. Changing the codebase at that point is unnecessary overhead and can be avoided in the very beginning by following good practices.

Read More  Apple Launches Inaugural Entrepreneur Camp For Black Founders And Developers

This article was originally published on The New Developer.


For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!

Our humans need coffee too! Your support is highly appreciated, thank you!

root

Related Topics
  • Coding
  • Computer Science
  • Developers
  • Programming
  • writing clean code
You May Also Like
View Post
  • Engineering

Just make it scale: An Aurora DSQL story

  • May 29, 2025
View Post
  • Engineering
  • Technology

Guide: Our top four AI Hypercomputer use cases, reference architectures and tutorials

  • March 9, 2025
View Post
  • Computing
  • Engineering

Why a decades old architecture decision is impeding the power of AI computing

  • February 19, 2025
View Post
  • Engineering
  • Software Engineering

This Month in Julia World

  • January 17, 2025
View Post
  • Engineering
  • Software Engineering

Google Summer of Code 2025 is here!

  • January 17, 2025
View Post
  • Data
  • Engineering

Hiding in Plain Site: Attackers Sneaking Malware into Images on Websites

  • January 16, 2025
View Post
  • Computing
  • Design
  • Engineering
  • Technology

Here’s why it’s important to build long-term cryptographic resilience

  • December 24, 2024
IBM and Ferrari Premium Partner
View Post
  • Data
  • Engineering

IBM Selected as Official Fan Engagement and Data Analytics Partner for Scuderia Ferrari HP

  • November 7, 2024

Stay Connected!
LATEST
  • 1
    Just make it scale: An Aurora DSQL story
    • May 29, 2025
  • 2
    Reliance on US tech providers is making IT leaders skittish
    • May 28, 2025
  • Examine the 4 types of edge computing, with examples
    • May 28, 2025
  • AI and private cloud: 2 lessons from Dell Tech World 2025
    • May 28, 2025
  • 5
    TD Synnex named as UK distributor for Cohesity
    • May 28, 2025
  • Weigh these 6 enterprise advantages of storage as a service
    • May 28, 2025
  • 7
    Broadcom’s ‘harsh’ VMware contracts are costing customers up to 1,500% more
    • May 28, 2025
  • 8
    Pulsant targets partner diversity with new IaaS solution
    • May 23, 2025
  • 9
    Growing AI workloads are causing hybrid cloud headaches
    • May 23, 2025
  • Gemma 3n 10
    Announcing Gemma 3n preview: powerful, efficient, mobile-first AI
    • May 22, 2025
about
Hello World!

We are aster.cloud. We’re created by programmers for programmers.

Our site aims to provide guides, programming tips, reviews, and interesting materials for tech people and those who want to learn in general.

We would like to hear from you.

If you have any feedback, enquiries, or sponsorship request, kindly reach out to us at:

[email protected]
Most Popular
  • Understand how Windows Server 2025 PAYG licensing works
    • May 20, 2025
  • By the numbers: How upskilling fills the IT skills gap
    • May 21, 2025
  • 3
    Cloud adoption isn’t all it’s cut out to be as enterprises report growing dissatisfaction
    • May 15, 2025
  • 4
    Hybrid cloud is complicated – Red Hat’s new AI assistant wants to solve that
    • May 20, 2025
  • 5
    Google is getting serious on cloud sovereignty
    • May 22, 2025
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.