@@ -8,6 +8,56 @@ Structuring your project properly is extremely important.
88Structure is Key
99----------------
1010
11+ Thanks to the way imports and module are handled in Python, it is
12+ relatively easy to structure a python project. Easy, here, means
13+ actually that you have not many constraints and that the module
14+ importing model is easy grasp. Therefore, you are left with the
15+ pure architectural task of drawing the different parts of your
16+ project and their interactions.
17+
18+ Easy structuration of a project means it is also easy
19+ to do it poorly. Some signs of a poorly structured projects
20+ include:
21+
22+ - Multiple and messy circular dependencies: if your classes
23+ Table and Chair in furn.py need to import Carpenter from workers.py
24+ to answer to a question such as table.isdoneby(),
25+ and if convertly the class Carpenter need to import Table and Chair,
26+ for example to answer to carpenter.whatdo(), then you
27+ have a circular dependency, and will have to resort to
28+ fragile hacks such has using import statements inside
29+ methods or functions.
30+
31+ - Hidden coupling. Each and every change in Table implementation
32+ breaks 20 tests in unrelated test cases because it breaks Carpenter's code,
33+ which requires very careful surgery to adapt the change. This means
34+ you have too many assumptions about Table in Carpenter's code or the
35+ reverse.
36+
37+ - Heavy usage of global state or context: Instead of explicitely
38+ passing ``(height, width, type, wood) `` to each other, Table
39+ and Carpenter rely on global variables that can be modified
40+ and are modified on the fly by different agent. You need to
41+ scrutinize all access to this global variables to understand why
42+ a rectangular table became a sqaure, and discover that a remote
43+ template code is also modifying this context, messing with
44+ table dimensions.
45+
46+ - Spaghetti code: Multiple pages of nested if clauses and for loops
47+ with a lot of copy-pasted procedural code and no
48+ proper segmentation are known as spaghetti code. Python's
49+ meaningful indentation (one of its most controversial feature) make
50+ it very hard to maintain this kind of code. So the good news is that
51+ you might not see too much of it.
52+
53+ - Ravioli code is more likely in Python: it consists of hundreds of
54+ similar little pieces of logic, often classes or objects, without
55+ proper structure. If you never can remember if you have to use
56+ FurnitureTable, AssetTable or Table, or even TableNew for your
57+ task at hand, you might be swimming in ravioli code.
58+
59+
60+
1161
1262
1363Vendorizing Dependencies
@@ -20,4 +70,4 @@ Runners
2070
2171
2272Further Reading
23- ---------------
73+ ---------------
0 commit comments