C Candela Francisconi Torres

The Importance of Naming Conventions in Small Projects

When starting a new project, especially a small one, it can be tempting to skip over seemingly trivial details like naming conventions. However, even in a single-file project, consistent and descriptive naming can significantly improve readability and maintainability.

The Temptation to Skip Conventions

In small projects, the urge to dive straight into the code and worry about "details" later is strong. For example, when creating a simple script to automate a task, you might be tempted to use short, ambiguous names for variables and functions to save time.

An Example of the Impact

Consider this scenario: you have a Python script for a small data processing task. Initially, it's a single file. The initial version might look like this:

def proc_data(file):
    # Process data from the file
    # ...
    return result

def save_res(result, output_file):
    # Save the processed result to a file
    # ...

# Main part of the script
file = "input.txt"
result = proc_data(file)
output_file = "output.txt"
save_res(result, output_file)

While this might seem fine at first glance, the names proc_data and save_res are not very descriptive. What kind of processing is being done? What kind of result is being saved? As the script grows, these vague names can make it harder to understand the code.

A better approach would be:

def process_input_data(input_file):
    # Process data from the input file
    # ...
    return processed_data

def save_processed_data(processed_data, output_file):
    # Save the processed data to the output file
    # ...

# Main part of the script
input_file = "input.txt"
processed_data = process_input_data(input_file)
output_file = "output.txt"
save_processed_data(processed_data, output_file)

Here, the names are more explicit, making the script easier to understand.

The Lesson

Even in small, single-file projects, adopting clear and consistent naming conventions pays off. It improves readability, reduces cognitive load, and makes the code easier to maintain and extend. Choose descriptive names that accurately reflect the purpose of variables and functions. Your future self (and anyone else who reads your code) will thank you.


Generated with Gitvlg.com

The Importance of Naming Conventions in Small Projects
Candela Francisconi Torres

Candela Francisconi Torres

Author

Share: