carta / styleguide

Carta's style guides
26 stars 5 forks source link

One file per class #2

Open bhardin opened 6 years ago

bhardin commented 6 years ago

Discussion on best practice of One file per class.

adambom commented 6 years ago

Inside of the file /apps/vehicles/models.py there is a Car class. The tests for this class are easily found in the file: /apps/vehicles/models/test_car.py

I think this is confusing because you break parity between the source code file hierarchy and the test directories. I like being able to look at a file (and without opening it) know where to find the tests. It just so happens that I'm not particularly fond of defining multiple classes in a single file either. Thus, I propose the following structure:

In source code: eshares/models/car.py eshares/models/__init__.py

(instead of eshares/models.py with countless classes embedded in one confusing megafile)

In test code: test/models/test_car.py

bhardin commented 6 years ago

@adambom Agreed. I also don't like multiple classes per file and think the bloat in models.py is an anti-pattern. Unfortunately, we inherited the bloat in these files and needed a way to bridge our testing until we have good file/class parity.