@@ -9,7 +9,7 @@ Structure is Key
99----------------
1010
1111Thanks to the way imports and modules are handled in Python, it is
12- relatively easy to structure a python project. Easy, here, means
12+ relatively easy to structure a Python project. Easy, here, means
1313that you do not have many constraints and that the module
1414importing model is easy to grasp. Therefore, you are left with the
1515pure architectural task of crafting the different parts of your
@@ -19,7 +19,7 @@ Easy structuring of a project means it is also easy
1919to do it poorly. Some signs of a poorly structured project
2020include:
2121
22- - Multiple and messy circular dependencies: If your classes
22+ - Multiple and messy circular dependencies: if your classes
2323 Table and Chair in furn.py need to import Carpenter from workers.py
2424 to answer a question such as table.isdoneby(),
2525 and if conversely the class Carpenter needs to import Table and Chair,
@@ -28,13 +28,13 @@ include:
2828 fragile hacks such has using import statements inside
2929 methods or functions.
3030
31- - Hidden coupling: Each and every change in Table's implementation
31+ - Hidden coupling: each and every change in Table's implementation
3232 breaks 20 tests in unrelated test cases because it breaks Carpenter's code,
3333 which requires very careful surgery to adapt the change. This means
3434 you have too many assumptions about Table in Carpenter's code or the
3535 reverse.
3636
37- - Heavy usage of global state or context: Instead of explicitly
37+ - Heavy usage of global state or context: instead of explicitly
3838 passing ``(height, width, type, wood) `` to each other, Table
3939 and Carpenter rely on global variables that can be modified
4040 and are modified on the fly by different agents. You need to
@@ -43,14 +43,14 @@ include:
4343 template code is also modifying this context, messing with
4444 table dimensions.
4545
46- - Spaghetti code: Multiple pages of nested if clauses and for loops
46+ - Spaghetti code: multiple pages of nested if clauses and for loops
4747 with a lot of copy-pasted procedural code and no
48- proper segmentation are known as spaghetti code. Python's
48+ proper segmentation are known as spaghetti code. Python's
4949 meaningful indentation (one of its most controversial features) make
5050 it very hard to maintain this kind of code. So the good news is that
5151 you might not see too much of it.
5252
53- - Ravioli code is more likely in Python: It consists of hundreds of
53+ - Ravioli code is more likely in Python: it consists of hundreds of
5454 similar little pieces of logic, often classes or objects, without
5555 proper structure. If you never can remember if you have to use
5656 FurnitureTable, AssetTable or Table, or even TableNew for your
@@ -186,14 +186,14 @@ objects, they have a type, they can be passed as function arguments, they may
186186have methods and properties. In this understanding, Python is an
187187object-oriented language.
188188
189- However, unlike Java, Python do not impose object-oriented programming as the
189+ However, unlike Java, Python does not impose object-oriented programming as the
190190main programming paradigm. It is perfectly viable for a Python project to not
191191be object-oriented, i.e. to use no or very few class definitions, class
192192inheritance, or any other mechanisms that are specific to object-oriented
193193programming.
194194
195195Moreover, as seen in the modules _ section, the way Python handles modules and
196- namespaces gives the developer a natural way to ensure
196+ namespaces gives the developer a natural way to ensure the
197197encapsulation and separation of abstraction layers, both being the most common
198198reasons to use object-orientation. Therefore, Python programmers have more
199199latitude to not use object-orientation, when it is not required by the business
@@ -208,8 +208,8 @@ In some architectures, typically web applications, multiple instances of Python
208208processes are spawned to respond to external requests that can
209209happen at the same time. In this case, holding some state into instantiated
210210objects, which means keeping some static information about the world, is prone
211- to concurrency problems or race-conditions. Sometime between the initialization of the
212- state of an object, usually done with the __init__() method, and the actual use
211+ to concurrency problems or race-conditions. Sometimes, between the initialization of
212+ the state of an object ( usually done with the __init__() method) and the actual use
213213of the object state through one of its methods, the world may have changed, and
214214the retained state may be outdated. For example, a request may load an item in
215215memory and mark it as read by a user. If another request requires the deletion
@@ -230,7 +230,7 @@ in the persistence layer, it is said to have a side-effect.
230230Carefully isolating functions with context and side-effects from functions with
231231logic (called pure functions) allow the following benefits:
232232
233- - Pure functions are more likely to be deterministic: given a fixed input,
233+ - Pure functions are deterministic: given a fixed input,
234234 the output will always be the same.
235235
236236- Pure functions are much easier to change or replace if they need to
@@ -257,7 +257,7 @@ The Python language provides a simple yet powerful syntax called 'decorators'.
257257A decorator is a function or a class that wraps (or decorate) a function
258258or a method. The 'decorated' function or method will replace the original
259259'undecorated' function or method. Because functions are first-class objects
260- in Python it can be done 'manually' but using the @decorator syntax is
260+ in Python, it can be done 'manually', but using the @decorator syntax is
261261clearer and thus preferred.
262262
263263.. code-block :: python
0 commit comments