Skip to content

Commit cb0760c

Browse files
author
LeoFR
committed
Add some naming conventions
1 parent 3be62c9 commit cb0760c

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Our styles are based on the excellent [javascript guide from Airbnb](https://git
1111
## Exceptions
1212

1313
### Whitespace
14-
- Limit your lines to 105 characters. eslint: [max-len](http://eslint.org/docs/rules/max-len).
14+
- Limit your lines to 100 characters (with a 5 characters tolerance). eslint: [max-len](http://eslint.org/docs/rules/max-len).
1515
> This ensures readability and maintainability.
1616
1717
```javascript
@@ -27,4 +27,29 @@ Our styles are based on the excellent [javascript guide from Airbnb](https://git
2727
```
2828

2929
## Naming conventions
30-
For sure, there are things we'd like to add here.
30+
### Consistency and disambiguation
31+
32+
As soon as a concept as a name, this name should always be used to refer to that concept, and that name shouldn't be used to refer
33+
to anything else.
34+
35+
Example:
36+
- A `globalRouteId` is a unique identifier to a route. One should never call it `routeId` since it is another concept (used in the GTFS,
37+
the tGTFS and the bgtfs with different meaning).
38+
- A `feed` is an instance of the `transit_production.feeds` table. An `alertFeed` is an instance of the `service_update.alert_feeds` table.
39+
40+
41+
If some external tools/library/api uses the same name for another concept, then at least the foreign name should be prefixed for disambiguation, or even both.
42+
- When we match the stops from the GTFS to the stop from some real-time API, we call the first one `gtfsStop` and the second one `apiStop` even if the first one is usually just called stop.
43+
44+
45+
### The name should describe the content
46+
As much as possible:
47+
- an array of `value` should be called just `values`;
48+
- an object of `value` index by some `key` should be called `valueByKey`.
49+
50+
As soon as you start to have different representations of the same thing in the same function, disambiguation on the content should be done. For example:
51+
- `timestampAsMoment` vs `timestampAsString`
52+
- `stopSequenceAsString` vs `stopSequenceAsInt`
53+
54+
With some reasonable limits, one shouldn't be afraid to have long variable name, and be more afraid of meaningless names. For example:
55+
- `apiStopByStopIdByTripHeadsignByRouteId` should be still prefered as `dict` or `apiStops`.

0 commit comments

Comments
 (0)