I'm looking for some best practices for readability (and clean code in general) for naming modules/classes within more extensive projects. More specifically, is it reasonable to add the package's name to the module/class name?
For example, which of the following two structures is preferable?
|-- my_application
| |-- endpoints
| | |-- contact.py
| | |-- change_order.py
| | |-- ticket.py
| |-- models
| | |-- contact.py
| | |-- change_order.py
| | |-- ticket.py
OR
|-- my_application
| |-- endpoints
| | |-- contact_endpoint.py
| | |-- change_order_endpoint.py
| | |-- ticket_endpoint.py
| |-- models
| | |-- contact_model.py
| | |-- change_order_model.py
| | |-- ticket_model.py
Adding the package as a suffix improves the readability by making the purpose of the module unmistakably clear. That said, it also adds visual noise. Knowing that you're working on the my_application/endpoints/contact.py file should be enough to deduct you're working on the contact endpoint and not the model.
-
1Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.Community– Community Bot2023年07月24日 18:18:49 +00:00Commented Jul 24, 2023 at 18:18
1 Answer 1
Neither?
This is a symptom of being starved for good names. You are attempting to dramatically increase the number of good names by multiplying them together. The result is now every thing is paired with another thing. And nothing is truly it’s own thing.
This is true regardless of where you pair the names. If I say "I’m done updating the contact module" you don’t know what I mean under either system.
Entire system libraries have been written in many languages without colliding shorted names. Yes, coming up with those names is work. But it’s worth doing.
But fine. Right now you just can’t think of the names. Pick the system that doesn’t lock you into this pairing scheme if someone actually starts coming up with unique names later.
Just because you can’t see it now doesn’t mean you won’t later.
Explore related questions
See similar questions with these tags.