liveBook · Manning

Convention

As explained in The Well-Grounded Python Developer: How the pros use Python and Flask

A naming convention is a shared pattern for constructing identifiers consistently so their form communicates information.

A naming convention is a shared pattern for constructing identifiers so their form communicates what they contain and how they are used. Good names preserve intent even when a declaration and its use are far apart, helping future readers understand code without reconstructing its context. section 2.1.1

Useful conventions make both individual names and larger structures easier to read:

  • Name variables for their contents and roles: table, row_index, column_index, and item reveal more than single-letter alternatives. section 2.1.1
  • Use plural names for iterable collections and singular names for items drawn from them, such as employees and employee. section 2.1.1
  • Make totals explicit by combining total with what is counted, as in total_employees or total_managers. section 2.1.1
  • Apply consistent parts-based names when a value needs more detail, such as first_name, middle_name, and last_name. section 2.1.1

From shorthand to intent

A nested loop becomes easier to follow when t, i, j, r, and it become table, row_index, column_index, row, and item. The same principle applies to files: when every expense report must be named expenses.xlsx, directories can provide the meaningful separation and hierarchy. section 2.1.1 section 2.1.2

table = [[12, 11, 4], [3, 22, 105], [0, 47, 31]]
for row_index, row in enumerate(table):
    for column_index, item in enumerate(row):
        process_item(row_index, column_index, item)

Compare a nested loop using descriptive names for the table, row, column, and item. section 2.1.1

How The Well-Grounded Python Developer: How the pros use Python and Flask covers it

How deep it goes
Explains naming patterns through variables, collections, totals, people, files, and directories, then connects naming to refactoring.
Examples
Uses nested loops, employee totals, person-name parts, expense reports, and fixed filenames to demonstrate naming choices.
What you can do after
Apply naming conventions to create more readable identifiers and organize fixed-name files without collisions.
How it connects
Connects identifiers with variables, collections, directories, namespaces, and refactoring.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Python Developer: How the pros use Python and Flask. The section links point to the parts of the book it draws on.