To be truthful, I've been upset with the direction that PHP was following for quite some time. PHP took the web by storm as an entry level server sides scripting language simply because it provided the base functionality that that people need to script web pages. Due to the ease of use, PHP captured 80% of the market.
In their zeal to capture the lucrative enterprise market, the developers of PHP appear to have turned their back on their install base and have been transforming PHP into a language that is as terse and unforgiving as Java and C++.
I could not figure out why PHP was so eager to toss out the baby with the bath water until I was reading a series of derisive posts on StackOverflow.com. The posts started with newbie programmers asking legitimate questions about the PDO object. The brownshirts on StackOverflow.com would divert from the question as deride the newbie programmer for using "anti-patterns."
I read a dozen posts of the same form and suddenly it dawned on me.
"Design Patterns" and "Antipatterns" have evolved beyond simple buzzwords and have transformed into entrenched ideologies. The designers of PHP appear to be succumbing to the dictates of ideologues.
The Resource Model for Web Design will present a tutorial on web design. This model states that "the database connection" is a resource that should be available at any point in a program's design. To accomplish this goal, I will encapsulate the PDO object in a function.
The mathematics behind this trick is the simple observation that every path through an object can be represented by a procedure.
Patternists hold that procedural programming is a lower form of thought than object programming and that the ability to access a resource, willy-nilly, at any point in a program is an "anti-pattern." Creating a procedure that encapsulates an object shows that procedures and objects are just programmatic forms. Just as it is possible to roll up a group of procedures into an object, it is possible to represent paths through the object as a procedure. There is no intellectual superiority involved in it, there is basic logic.
I am deeply troubled by the ideology of Design Patterns. Patternism (a term which I am openly developing as a pejorative) seems to have the same basic form as Hegelian Dialectics.
Hegel (1770-1831) was a royalist philosopher loyal to King Frederick William III of Prussia. Hegel was tasked with creating a new philosophical system to counter the liberal ideas behind the American and French Revolution. Hegel created a really bizarre system of new think which has become the base for the modern ideologies that have come to dominate our society including Conservatism, Nationalism, Capitalism, Fascism, Marxism, Communism, and, of course, Progressivism. (My work The Two Sides of a Coin will show how Conservatism and Progressivism grew from the same roots.)
Hegel's philosophy was essentially rewording the Divine Right of Kings into philosophical language. The philosophy holds that the state is the driving force of progress. Hegel's philosophy of history holds that society evolves through a predictible series of thesis/anti-thesis conflicts that played out on the world stage. The ideology presents a conflict driven view of history with the German people evolving into an uber class ... a master race ... if you like.
The ideals of liberals in 1776 were based on Aristotelian logic (Aristotelian logic is often called "analytics") and experiences of the Western Tradition at large. I like to call this tradition "classical liberalism." Classical liberals were winning the hearts and minds of the people in both the American and French Revolution. Hegel realized that the cause of the monarchy was unlikely to win in an open debate, so he created a "modern logic" which directly attacked the foundations of classical logic.
For example, classical logic held to a concept called "The Law of the Excluded Middle." This law holds that, for a syllogism to be valid, the major and minor premise in the proposition must evolve to "true" or "false."
The "if/then" statement is a form of the syllogism. The "Law of the Excluded Middle" holds that, for an "if/then" statement to work, the condition used in the statement must resolve to "true" or "false."
Imagine writing the line of code: "If conditionX then do this else do that." Now imagine that conditionX could not resolve to "true" or "false." If you tried to execute this code your program would stall.
The fact that you can use unresolveable conditions in a computer does not mean there are no unanserable questions. It just means you need to avoid them.
There are numerous unresolvable conditions. For example the statement "This sentence is false" is a self-negating paradox. If the sentence is true, it is false. If it is false it is true. Trying to resolve the proposition leads to and endless recursive loop.
If you wrote a line of code that said "if (resolve infinite loop) then do this else do that;" your computer will hang for infinity or until an administrat r kills the process.
The "Law of the Excluded Middle" says that if you use an infinite loop as your condition, your computer program will freeze. This is not absolutism. This is just the way things work. You want to avoid infinite loops, division by zero errors and other logical paradoxes.
Classical thinkers sought to avoid paradoxes. Most absolutes lead to a paradox. Most thinkers in the Aristotelian tradition sought to avoid absolutes. Those that didn't would find their line of reasoning caught in infinite loops.
To turn the tide on the classical liberals, Hegel made extensive use of paradoxes. He was particularly fond of combining a negation with a self reference.
For example a common criticism of Democracy is that an absolute democracy would empower the people to end the Democracy. People, given this power, are apt to vote in a tyrant who ends the Democracy.
Of course, all forms of governance are prone to a self-negating paradox. If the leaders do something to destroy the government, then the government gets destroyed. A king with absolute authority could empower the people with the vote and end his reign.
Famously, the leaders of East German Communist Government ushered in there demise when they gave into pressures to let their people travel abroad in 1989, The people ran across the border in droves, turned around and tore down the Berlin Wall causing the East German government to implode.
Hegel loved using negating self references to prove that freedom was slavery and slavery freedom. After all, free people often have to suffer the consequences of their free choices.
Patternism is an Ideology
Back to the subject at hand. While I was reading stackoverflow.com it dawned on me that the theory of Patterns and Anti-Patterns seemed to have the same basic form as Hegel's theory of history and logic.
The theory of Design Patterns starts with the claim that computer science evolves through a series of conflicts.
The first generations of computing machines used primative based on physical properties of the machines used. One can add with a abacus or navigate with an astrolabe, but these primative devices had limited functionality.
Early computer scienttists began creating devices with enumerated registries and complex algorithms that would jump between registries during execution.
As the algorithms grew in complexity, they grew unweildy. This early type of programming is symobolized by the GOTO statements. People began to call this style of coding speghetti code.
Procedural programming gives precise entry and and exit points for programs creating code that is easier to debug than speghetti code.
Objects oriented programming groups procedures and related data into discrete units called objects.
The Theory of Design Patterns presents this history of computer programming in the same way that Hegel presented Western history. The claim of patternists is that computer programming evolved through a system of thesie/anti-thesist conflicts with each conflict resolving into a higher state (this is the catharsis).
Patternists claim that in the evolutionary stage after object-oriented-programming, an über-kind will evolve within the object-oriented community that can see patterns and that (just as the Germanic race was destined to become the master race) this über-kind is destined to become a ruling class within software engineering.
To be honest with the readers. I was thrilled when "The Gang of Four" (Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides) published the work "Design Patterns" in 1994. I hoped that the work would provide useful metaphors to help describe commonly used structures in programming.
For that matter, I even found it useful when Andrew Koenig coined the term "Antipattern" to refer to commonly occuring mistakes in code.
I believe that various tools and methaphors that people use to discuss code are beneficial. For years I encouraged people to discuss design patterns and antipatterns.
Truthfully, it did not dawn on me that this concept of "Design Patterns" had evolved into an ideology until I saw people on StackOverflow.com using design patterns to intimidate people online. The people who I've come to call "patternists" were using a system of thought that followed the same pattern as Hegelian dialectics.
This next argument might only make sense to people who've studied transfinite theory and the works of Bertrand Russell. Most statements, when pushed to an absolute create a self-reference. Russell liked pointing out that a catalog of catalogs is itself a catalog. The catalog of all catalogs would, by necessity include itself.
Now, lets imagine the catalog of all catalogs that do not include a self reference. If it doesn't include a self-reference, it must belong to itself. But if it includes a self-reference it violates the condition of the catalog.
The catalog of all catalogs that includes itself is also paradoxical. The negation simply brings the paradox to light.
The ideology of design patterns has the same form as Russell's catalog problem.
Every thought we have about software design could be considered pattern. The theory of antipatterns now has a self reference and paradox.
The Resource Model of Web design says that certain elements of a web based program such as the database connection and output buffer should be available throughout the program. The idea that programmers can access the database (willy nilly) at any point in a web page is an anti-pattern.
Creating a robust programming structure based on an anti-pattern might highlight the the ideologues who are pushing Patternism are just repeating a tired old ideology that leads nowhere.
The consequence of what I am doing is that anyone who uses the code I present in this work will derided by elitists who've fallen for the line that, by using the buzzwords of Design Patterns, they are the über-kind of the programming world. I don't mind being derided by elitist snobs, but might find it uncomfortable.
Notes on Class Structure
In one of those strange accidents in history, Bjarne Stroustrup (1950-present) used the term "class" to denote an object when he began programming "C with Classes" in 1978. This terminology used in C++ was copied was copied in Java, PHP and other languages.
"Conservatism" is an ideology that was created by King William IV of England in 1831. The term "conservative" comes from the French word "conservatif" which refers to efforts to restore the French Monarchy after the Napoleonic Wars. The goal of Conservatism from King William IV to the present has been to conserve the class structure in an age demanding social change.
People who are enthusiastic about "Design Patterns" tend to become preoccupied with the structure of classes in code. Many "design patterns" involve organizing classes in hiearchical structures. I realize that this is just a play on words, but I think I ought to be able to do something with the line:
"Just as monarchists believed the society should be orgainized in rigid hierarchical class structure, patternists believe that the objects in a program need to be organized in a rigid hierarchical class structure."
Object and Relation Conflict
The ongoing conflict between object-oriented programming and relational databases need to be recognized as well.
Many of the ideas object oriented programming were formulated specifically to handle the memory management problems faced by early computer programmers.
Early computer languages would allow programmers to access any area of memory. Conflicts would arise when two programs tried to access the same resource. The ideal of object-oriented programming was to have all of the code that affects a single piece of data in a single place.
Relational Database were built around the structure of data. Relational design allows multiple programs to access and modify the same data so long as the access does not break the relational integrity. Since relational databases and object-oriented programming were created from different perspectives and were created to do different things, there has always been a little bit of conflict between the object and relational world.
Web design is built upon a client/server model. There is a huge physical separation between the data siting on a server and web pages.
Web developers end up using a mishmash of ideas from the object and relational world, and there is absolutely nothing wrong with that.
I believe that it is a mistake to get too caught up in the discussion of patterns and antipatterns. People who become too obsessive in discussing patterns act more like political ideologues than rational software engineers.
If you find yourself in a situation where a person is browbeating and intimidating people with "pattern-speak" it might be worthwhile to call them out as "patternists." Who knows, it might help.
Finally, if ever you are in a situation where people are trying to force a set of ideas on you in the name of "patterns," I strongly encourage you to resist.