# Clean Code and Naming

> What clean code is, and why the names you choose matter most. Naming conventions, style guides, and writing code in pairs.

**Course:** [Programming Basics](https://learn.benibix.com/learn/development-concepts)  
**Time:** 11 min

**After this lesson you can:**

- Rename a variable so it says what it holds
- Follow a team's rules for names and layout
- Explain how pair programming works

## What makes code easy for someone else to read

Clean code is code that someone else can read and change without help. Code is read far more often than it is written, by teammates and by you, months later. The parts that matter most are clear names, short functions that each do one job, and a layout that looks the same everywhere.

Names do most of the work. A variable called d tells the reader nothing. One called days_since_signup tells them everything. A good name says what a thing holds or does, so the reader does not need a comment. If a name is hard to choose, the code behind it may be doing too much.

A naming convention is a rule a team shares for how names are written. Python writes most names in snake_case, like total_price: all small letters, with _ between words. Names for classes use CapWords, like ShoppingCart. Fixed values use capitals, like MAX_USERS. JavaScript writes totalPrice instead. That style is camelCase.

A style guide is the written rule book for how a team's code should look. Python's is called PEP 8. It asks for 4 spaces per indent and lines of at most 79 characters, among many other things. Tools can check it and even fix the layout for you, so people stop arguing about spaces.

Pair programming is two people writing the same code at one screen. One, the driver, types. The other, the navigator, reads each line, thinks ahead and spots mistakes. They swap often. It sounds slower, but many bugs are caught the moment they are typed, and two people learn the code.

Clean code is not short code. Squeezing a function into one clever line often makes it harder to read. The test is simple: could a new teammate change this safely tomorrow? If not, the code needs a better name, a split, or a plainer way of saying it.

The common mistake is leaving the clean-up for later. Later rarely comes. Rename the thing while the meaning is fresh in your head. It takes a few seconds, and every reader after you saves minutes.

```python
# Hard to read
def f(l):
    t = 0
    for x in l:
        t = t + x
    return t / len(l)

# Clean
def average_score(scores):
    total = sum(scores)
    return total / len(scores)
```
Both functions do the same job. Only the second one tells the reader what that job is.

![Three rows, each a naming style with its job. snake_case, as in total_price, for Python variables and functions. CapWords, as in ShoppingCart, for classes. UPPER_CASE, as in MAX_USERS, for constants. Below, the line d = 14 is struck through and days_since_signup = 14 is picked out instead.](https://learn.benibix.com/diagrams/prog-naming.svg)

### Example: Emma and Jack pair on a bug fix

Emma drives and Jack navigates on a fix to the checkout page. After 20 minutes, Jack spots that a test checks > where it should check >=.

They swap roles every 25 minutes. The fix ships the same day, and both of them now know that part of the code.

**Words in this lesson:** [Clean Code](https://learn.benibix.com/term/development/clean-code), [Naming Convention](https://learn.benibix.com/term/development/naming-convention), [Code Style Guide](https://learn.benibix.com/term/development/style-guide), [Pair Programming](https://learn.benibix.com/term/development/pair-programming)

**Question:** Which of these is how Python likes a name to look?

**Answer:** total_price. Python writes variable and function names in lower case with _ between words, which is called snake_case. CapWords is kept for classes.

---

Source: https://learn.benibix.com/learn/development-concepts/clean-code-and-naming
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
