Skip to content

Commit e02465d

Browse files
Add a kind-of conclusion.
1 parent c160782 commit e02465d

1 file changed

Lines changed: 56 additions & 1 deletion

File tree

contingent/chapter.rst

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,62 @@ and did not get re-invoked.
12801280
Conclusion
12811281
==========
12821282

1283-
1283+
There exist languages and programming methodologies
1284+
under which Contingent would be a suffocating forest of tiny classes
1285+
giving useless and verbose names to every concept in the problem domain.
1286+
1287+
When programming Contingent in Python, however,
1288+
we skipped the creation of a dozen classes that could have existed,
1289+
like ``TaskArgument`` and ``CachedResult`` and ``ConsequenceList``.
1290+
We instead drew upon Python’s strong tradition
1291+
of solving generic problems with generic data structures,
1292+
resulting in code that repeatedly uses a small set of ideas
1293+
from the core data structures tuple, list, set, and dict.
1294+
1295+
But does this not cause a problem?
1296+
1297+
Generic data structures are also, by their nature, anonymous.
1298+
Our ``project._cache`` is a set.
1299+
So is every collection of upstream and downstream nodes
1300+
inside the ``Graph``.
1301+
Are we in danger of seeing generic ``set`` error messages
1302+
and not knowing whether to look in the project or the graph
1303+
implementation for the error?
1304+
1305+
In fact, we are not in danger!
1306+
1307+
Thanks to the careful discipline of encapsulation —
1308+
of only allowing ``Graph`` code to touch the graph’s sets,
1309+
and ``Project`` code to touch the project’s set —
1310+
there will never be ambiguity if a set operation
1311+
returns an error during a later phase of the project.
1312+
The name of the innermost executing method at the moment of the error
1313+
will necessarily direct us to exactly the class, and set,
1314+
involved in the mistake.
1315+
There is no need to create a subclass of ``set``
1316+
for every possible application of the data type,
1317+
so long as we put that conventional underscore in front of data
1318+
structure attributes and then are careful not to touch them
1319+
from code outside of the class.
1320+
1321+
Contingent demonstrates how crucial the Facade pattern,
1322+
from the epochal *Design Patterns* book,
1323+
is for a well-designed Python program.
1324+
Not every data structure and fragment of data in a Python program
1325+
gets to be its own class.
1326+
Instead, classes are used sparingly,
1327+
at conceptual pivots in the code where a big idea —
1328+
like the idea of a dependency graph —
1329+
can be wrapped up into a Facade
1330+
that hides the details of the simple generic data structures
1331+
that lie beneath it.
1332+
1333+
Code outside of the Facade
1334+
names the big concepts that it needs
1335+
and the operations that it wants to perform.
1336+
Inside of the Facade,
1337+
the programmer manipulates the small and convenient moving parts
1338+
of the Python programming language to make the operations happen.
12841339

12851340
.. Links
12861341
.. _Sphinx: http://sphinx-doc.org/

0 commit comments

Comments
 (0)