Skip to content

Instantly share code, notes, and snippets.

@hectorcanto
Created January 24, 2020 13:07
Show Gist options
  • Save hectorcanto/d1fe7aca20ab287ddc8b92cdc9f03734 to your computer and use it in GitHub Desktop.
Save hectorcanto/d1fe7aca20ab287ddc8b92cdc9f03734 to your computer and use it in GitHub Desktop.
Naming Tips
app: for application, many things are considered an application. Use adjectives like web_app, phone_app, django_app
api: application programming interface (any communication protocol may be labelled an API, user rest_api when possible)
rel: relation or relative?
srv: server or service?
# Avoid 's' plurals
When a 's' is missing or added mistakenly, it is hard to spot afterward and sometimes it will fail silently.
~~~python
for config in configs:
do_this(configs) # TypeError is a list
~~~
## Use proper grammar
Code editors usually come with grammar checkers, the checker will hint you any typo if it is a grammar error
# Know your letter-case
Depending on the programming language there are rules that apply for using uppercase, camelcase or snakecase. First of all
know them, but anyway use them, with special love for snake_case
UPPERCASE:
lowercase
l33t
CamelCase
lowerCamelCase
snake_case (or UPPER_SNAKE_CASE)
Title Case
## Use collective names and adjective
### collective names
_list
_items
_element
_instances
_vector
_iterable
Be careful with "type" names like list, dict that may confuse you about the nature of the given variable
### adjectives
raw_
original_
initial_
processed_
normalized_
filtered_
parsed_
# Use only well-know abbreviations
Some examples (more in other file:
- msg: messages
- kph: kilometres per hour
## It is ok to use well-know algrebraic letters or scientific abbreviations
- a,b,c
- i,j,k (but index is better sometimes)
- x,y,z
- g,m,k (Giga, Mega (million), Kilo (thousand)
## Avoid confusing names
Some recurrent confusing names and abbreviations:
- app vs web_app android_app django_app ...
- api: you probably mean rest_api, other cases: clas_intervice
- service: ddd_service, microservice, external_service
- srv: service or server?
## Use your patterns
Name the class/module/packege with what it is, not only with what it interacts
TwitterAPI -> TwitterAPIClient
Consumer/Producer
## Use verbs for actions (methods, functions) and nouns for elements (objects, variables, classes ...)
## Explain all that something do
validate_name vs validate_and_serialize_name
!note: ideally, each function should have only one responsability, but you know this happens.
msg: message
mw: malware
conf/config: configuration
py: python
doc: document
docs: documentation
pre: preproduction
pro(d): production (better prod)
s: seconds?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment