Skip to Content
Clean Code Cookbook
book

Clean Code Cookbook

by Maximiliano Contieri
September 2023
Intermediate to advanced
430 pages
8h 6m
English
O'Reilly Media, Inc.
Book available
Content preview from Clean Code Cookbook

Chapter 7. Naming

There are only two hard things in Computer Science: cache invalidation and naming things.

Phil Karlton

7.0 Introduction

Naming is a critical aspect of software development. It directly impacts the readability, understandability, and maintainability of code. You need to choose good names for objects, classes, variables, functions, etc. Good names help reduce confusion and errors and make it easier for other developers to use, modify, and debug code. Names are irrelevant for compilers and interpreters. But writing code is a human-centric activity. Poor naming choices can lead to confusion, misunderstandings, and defects. If a name is too generic or unclear, it may not accurately reflect the purpose or behavior of the code element it represents and makes it more difficult for other developers to understand how to use or modify it, leading to errors and wasted time.

7.1 Expanding Abbreviations

Problem

You have ambiguous abbreviated names.

Solution

Use strong, sufficiently long, unambiguous, and descriptive names.

Discussion

Bad naming is a problem programmers face in most software projects, and abbreviations are contextual and ambiguous. In the past, programmers used short names because memory was scarce but now you seldom face this problem. You should avoid abbreviations in all contexts: variables, functions, modules, packages, namespaces, classes, etc.

Review the following example in standard Golang naming conventions:

package main

import "fmt"
type ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

GitOps Cookbook

GitOps Cookbook

Natale Vinto, Alex Soto Bueno
Data-Oriented Programming

Data-Oriented Programming

Yehonathan Sharvit

Publisher Resources

ISBN: 9781098144715Errata PageSupplemental Content