<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Xblog: Leading the Horse to the Fountain of Knowledge</title>
    <link>http://xblog.xman.org/articles/2008/05/01/leading-the-horse-to-water</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>hey, if it has a capital X in it, it has to be great!</description>
    <item>
      <title>Leading the Horse to the Fountain of Knowledge</title>
      <description>&lt;p&gt;While truly great rants are mostly entertaining, some rants can be enlightening for the insight they provide during rare moments of candor about things that aren&amp;#8217;t obvious to those who don&amp;#8217;t share the ranter&amp;#8217;s paradigm. Such is the case with &lt;a href="http://realtimecollisiondetection.net/blog/?p=44"&gt;Design patterns are from hell!&lt;/a&gt;. I&amp;#8217;ve seen a lot of critiques of &lt;a href="http://realtimecollisiondetection.net/blog/?p=44" title="Design Patterns: Elements of Reusable Object-Oriented Software"&gt;Design Patterns&lt;/a&gt;, and I&amp;#8217;ve seen a lot of misuse of Design Patterns, but I totally didn&amp;#8217;t grok what the real problem was until reading this rant. Now I finally get it.&lt;/p&gt;

&lt;p&gt;The killer insight that I was lacking was the notion that people reading the books would &lt;em&gt;focus on the wrong thing&lt;/em&gt;. I was blinded by what I found to be very clear statements by the authors of the book about the benefits and purposes of patterns, how one should select patterns, how they differed from other reuse techniques, and indeed even the title itself. It seemed clear to me that it was all about design, all about practical solutions to common problems encountered in OO designs (and yes, the authors explicitly state that these solutions are nothing new, but rather well established), and most importantly: not about the code.&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;What the Design Patterns book teaches is for people to think in the box instead of outside of it; just as I did on that exam. Pattern thinking has now permeated and perverted peoples&#8217; thinking to the extent where patterns are perceived as being an ends; something you &lt;em&gt;need&lt;/em&gt; to use to correctly solve problems.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First, I don&amp;#8217;t get how that principle related to &amp;#8220;the Plank&amp;#8221;, because it seems clear from the statement that he knew how to solve the problem using a different one of the cookie-cutter solutions he&amp;#8217;d learned. Rushing to judgment before understanding a problem doesn&amp;#8217;t strike me as &amp;#8220;thinking in the box&amp;#8221;. Normally, people &amp;#8220;thinking in the box&amp;#8221; spend most of their effort on careful consideration of how a problem resembles and differs from problems they&amp;#8217;ve seen before, giving up if it is too different from anything they&amp;#8217;ve worked with before. Secondly, he jumps from talking about &amp;#8220;Design Patterns&amp;#8221; the book to &amp;#8220;Patterns&amp;#8221; in general, apparently failing to recognize that Design Patterns was just one book detailing commonly encountered design techniques of OO developers and comes far short of representing all patterns (indeed, the PLoP books detail new patterns presented each year), they were just the low-lying fruit. Even if you forgo this misnomer, it somehow misses the very logical conclusion one should reach in not finding a pattern that fits your problem: your problem isn&amp;#8217;t a commonly recurring one. It boggles the mind to think one would instead think to apply a pattern to a problem it was explicitly not designed for.&lt;/p&gt;

&lt;p&gt;Now I understand why people gripe about the Singleton all the time: they&amp;#8217;ve too often run in to developers who use it because they can, not because they need to, developers who think of the Singleton solution instead of the kinds of problems the pattern addresses.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s the problem, if one is the sort of person who tries to figure out the minimal amount of studying to get through one&amp;#8217;s statistics class (ironically applying approaches to achieving this that could have been derived from statistical principles ;-), one probably skimmed (or worse skipped) over the beginning of the book that takes the time to explains how to use the patterns. One probably went straight to the patterns themselves, and after looking at several of them, one probably decided the real meat of the patterns was in the code itself, because one&amp;#8217;s main use for programming books was to look for code samples and apply them to your work without having to think so carefully to avoid making mistakes.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://regex.info/blog/2006-09-15/247" title="Source of the famous \&amp;quot;Now you have two problems\&amp;quot;"&gt;To paraphrase JWZ&lt;/a&gt;: &lt;strong&gt;now they have two problems&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;Thinking in patterns is exactly the wrong thing to do! It makes you think in terms of the solution instead of in terms of the problem! Pattern thinking makes you try to fit a round, square, or oval hole (your choice of patterns) to the triangular peg (your problem). When all you have is a hammer&#8230;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A designer who goes around thinking about design in terms of trying to shove a bunch of pre-built solutions in to a problem is screwed whether they&amp;#8217;ve read Design Patterns or not. A designer&amp;#8217;s first focus should always be on what problems they have to solve, and only think about solutions as a consequence of addressing said problems. If you focus on the solutions instead, you will inevitably be wandering around with a hammer, thinking all the problems you face are pegs.&lt;/p&gt;

&lt;p&gt;What was curious to me when first reading the quoted text above was that I thought it was odd to think of Patterns as solutions looking for a problem. The book quotes about the specific way that patterns are documented, and right there at the beginning of each pattern is talk about the kinds of problems the pattern is appropriate before. Heck, the pattern catalog was even grouped by the kinds of problems each pattern solved! It seemed obvious that the proper way to organize your thinking about patterns was in terms of the problems they solved (indeed, I&amp;#8217;d often forget details of specific aspects of designs or implementation techniques for patterns I didn&amp;#8217;t use much, but I tended to remember their applicability quite clearly). It&amp;#8217;s odd to me that one would think one &lt;em&gt;had&lt;/em&gt; to organize your thinking in terms of the solution, particularly since the solution was inevitably so much more complex than the problems it solved. What I was missing of course, was that to someone trying to find the &amp;#8220;meat&amp;#8221; of a pattern without reading and understanding the whole thing, they&amp;#8217;d tend to of course focus on where the biggest sections of the pattern description were, and where the complexity was. So now you&amp;#8217;ve compounded the problem: you&amp;#8217;ve dramatically increased the cognitive load necessary to select appropriate patterns &lt;em&gt;and&lt;/em&gt; you are focused on the wrong thing for coming up with a good design.&lt;/p&gt;

&lt;p&gt;But wait, it gets worse!&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;For example, before dumb and dumber decided to call it the &#8220;visitor pattern&#8221; every programmer worth his salt would just call it a &#8220;map&#8221; operation (as in the LISP functions &#8220;map&#8221;, &#8220;mapcar&#8221;, &#8220;maplist&#8221;, etc). That&#8217;s just, oh, something like 1994-1960(?) = 34 years of previously established terminology! Twits.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yup, he just completely missed that the visitor pattern is primarily about double dispatch, and even talks about how CLOS does this natively. It talks about how Smalltalk&amp;#8217;s do: (the moral equivalent of map/mapcar/maplist) won&amp;#8217;t get you double dispatch support. Most importantly, it even talks about how putting traversing behavior in the Visitor, as done in the sample code, only really makes sense if the logic for determining what to traverse depends on results of the algorithm itself (i.e. when map/mapcar/maplist won&amp;#8217;t work).&lt;/p&gt;

&lt;p&gt;So, by focusing on the code, rather than the discussion of the problem, it&amp;#8217;s various facets, and how they effect possible solutions, one not only misses out on understanding the &lt;em&gt;problem&lt;/em&gt;, but also in understanding the &lt;em&gt;solution&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It &lt;em&gt;really is&lt;/em&gt; a poor craftsman who blames his tools. The problem is being focused on solutions, and that doesn&amp;#8217;t come from Design Patterns, it was there before hand (as demonstrated by The Plank).&lt;/p&gt;

&lt;p&gt;In retrospect, I think the real mistake some pattern advocates may have made was in encouraging people who just didn&amp;#8217;t get it, or didn&amp;#8217;t want to get it, to use patterns anyway. To really mix up some metaphors: once you&amp;#8217;ve brought the horse to the fountain of knowledge, if it doesn&amp;#8217;t drink, just shoot it and put it out of its misery. If you force it, it&amp;#8217;s just going to pretend to drink while secretly gargling, and you&amp;#8217;re going to find yourself stuck in the middle of the desert with a dehydrated horse. ;-)&lt;/p&gt;</description>
      <pubDate>Thu, 01 May 2008 22:48:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:25513304-d43a-4fb8-81b8-af0609375290</guid>
      <author>Christopher Smith</author>
      <link>http://xblog.xman.org/articles/2008/05/01/leading-the-horse-to-water</link>
      <category>Programming</category>
      <category>design</category>
      <category>patterns</category>
      <category>of</category>
      <category>gof</category>
      <category>gang</category>
      <category>four</category>
    </item>
    <item>
      <title>"Leading the Horse to the Fountain of Knowledge" by Christer Ericson</title>
      <description>&lt;p&gt;Bingo, Chris. My issue isn&amp;#8217;t with design patterns per se, but the large number of people who wield them as hammers. (That said, as long as such people exist, I&amp;#8217;ll be against design patterns in the same way I&amp;#8217;m against guns.) A rant just isn&amp;#8217;t as good if you simply spell it out, so I didn&amp;#8217;t. Spoilsport!&lt;/p&gt;</description>
      <pubDate>Sun, 04 May 2008 23:20:37 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:02817655-75b5-445a-86c3-bd78e82d4f50</guid>
      <link>http://xblog.xman.org/articles/2008/05/01/leading-the-horse-to-water#comment-378</link>
    </item>
  </channel>
</rss>
