<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tea-Driven Development &#187; patterns</title>
	<atom:link href="http://blog.mattwynne.net/tag/patterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mattwynne.net</link>
	<description>Matt Wynne taking it one tea at a time</description>
	<lastBuildDate>Tue, 10 Jan 2012 20:07:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Two Truths I&#8217;ve Learned About Writing Clean Rails Apps</title>
		<link>http://blog.mattwynne.net/2011/03/04/two-truths-ive-learned-about-writing-clean-rails-apps/</link>
		<comments>http://blog.mattwynne.net/2011/03/04/two-truths-ive-learned-about-writing-clean-rails-apps/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 13:28:01 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.mattwynne.net/2011/03/04/two-truths-ive-learned-about-writing-clean-rails-apps/</guid>
		<description><![CDATA[In summary: Implement every feature without javascript first, add javascript as a progressive enhancement Stick to REST. Always. Now I&#8217;m as suspicious of absolute rules as you probably are, but these two have served me extremely well in keeping my Rails code clean and easy to maintain. I&#8217;m happy to push the boat out and [...]]]></description>
			<content:encoded><![CDATA[<p>In summary:</p>

<ul>
<li>Implement every feature without javascript first, add javascript as a progressive enhancement</li>
<li>Stick to REST. Always.</li>
</ul>

<p>Now I&#8217;m as <a href="http://fragmental.tw/2011/01/04/rules_of_thumb_are_warning_bells.html">suspicious of absolute rules</a> as you probably are, but these two have served me extremely well in keeping my Rails code clean and easy to maintain. I&#8217;m happy to push the boat out and call them truths, my truths anyway.</p>

<p>Let me explain.</p>

<h1>Progressive Enhancement</h1>

<p>When I first started at Songkick, Cucumber was just emerging and webrat was the new kid on the testing block. Although using Selenium for full-stack javascript testing was possible with webrat, it wasn&#8217;t easy and we quickly made a decision: we would build the first iteration of every feature to work without javascript. This was mainly driven by pragmatism: we could easily use webrat to test the app through Rails integration testing stack, and these tests ran quickly rather than waiting for a browser to start up.</p>

<p>What happened surprised us. We would receive fancy designs from our designers which could only be implemented with fairly complex javascript. Because of our rule, we had to figure out how to deliver the same behaviour using basic HTTP posts and gets of forms and URLs. This required us to simplify the designs for our first iteration. We got a little push-back at first but we were a tight team and the designers quickly caught on. Especially when we started shipping these iteration one features quickly and reliably. And funnily enough, it turned out that often these simple HTTP-only versions of the features were actually fine, and the designers decided we should move onto other stuff, instead of building all that complex javascript that had been implied by their earlier designs.</p>

<p>So this rule had helped us to do the simple thing. We shipped features and moved on.</p>

<p>When we did have to add javascript, we added it on top of the existing working HTTP-only implementation, and we got another surprise: it was easy! Nearly every time, because we&#8217;d built the server-side infrastructure to a clean, standard pattern, the javascript we needed was clean and simple to write.</p>

<p>Which leads me to my next truth&#8230;</p>

<h1>Stick to REST. Always.</h1>

<p>I&#8217;ve always felt a little uncomfortable with Rails&#8217; controllers. They violate the Single Responsibility Principle for me. I&#8217;d prefer a pattern where I had a separate Request class for each action, rather than a few largely unrelated methods on the same controller class. But Rails is there and there&#8217;s a lot else to like, so let&#8217;s not get into that.</p>

<p>We all know it&#8217;s a bad idea to <a href="http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model">let our controllers bloat</a> and something I&#8217;ve been enjoying greatly lately is <a href="http://blog.plataformatec.com.br/author/josevalim/">Jose Valim</a>&#8216;s <a href="https://github.com/josevalim/inherited_resources">Inherited Resources</a>. By sticking to this pattern, you push all the logic into your domain model, and keep the controllers focussed on what they need to do: handling web requests.</p>

<p>You end up with more controllers, and more models too. You create model objects that &#8212; Gosh! &#8212; don&#8217;t represent database tables, but represent other domain concepts instead. Altogether though, you end up with smaller, more focussed classes that are easier to test and easier to read and understand.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattwynne.net/2011/03/04/two-truths-ive-learned-about-writing-clean-rails-apps/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Software as an Art Form</title>
		<link>http://blog.mattwynne.net/2007/09/27/software-as-an-art-form/</link>
		<comments>http://blog.mattwynne.net/2007/09/27/software-as-an-art-form/#comments</comments>
		<pubDate>Thu, 27 Sep 2007 06:59:54 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[quality]]></category>

		<guid isPermaLink="false">http://blog.mattwynne.net/2007/09/27/software-as-an-art-form/</guid>
		<description><![CDATA[I just came across an article written five years ago by Richard Gabriel proposing a university course run along the lines of his own Master&#8217;s in Fine Arts in poetry. The idea evidently gathered some momentum at the time, but now seems to have come to a halt. What a shame. I&#8217;ve had an idea [...]]]></description>
			<content:encoded><![CDATA[<p>I just came across <a href="http://www.dreamsongs.com/MFASoftware.html">an article written five years ago</a> by Richard Gabriel proposing a university course run along the lines of his own Master&#8217;s in Fine Arts in poetry. The idea evidently gathered <a href="http://www.testing.com/cgi-bin/blog/2003/10/02">some</a> <a href="http://simonwillison.net/2003/Oct/3/mfaInSoftware/">momentum</a> at the time, but now seems to have come to a <a href="http://groups.yahoo.com/group/software-mfa/">halt</a>.</p>

<p>What a shame. I&#8217;ve had an idea to get back to university on a &#8216;some day&#8217; list for a while, and this would have been pretty much exactly my thing, I think. Seems to me like it was just an idea ahead of its time&#8230; I wonder how popular something like that would be now, with the increased focus on <a href="http://www.amazon.co.uk/Zen-Motorcycle-Maintenance-Robert-Pirsig/dp/1559275561">Quality</a> that is sneaking in the back door behind the noisy razzmatazz of agile adoption.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattwynne.net/2007/09/27/software-as-an-art-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Model-View-Presenter (MVP) Anti-Patterns</title>
		<link>http://blog.mattwynne.net/2007/06/13/mvp-smells/</link>
		<comments>http://blog.mattwynne.net/2007/06/13/mvp-smells/#comments</comments>
		<pubDate>Wed, 13 Jun 2007 19:07:50 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[mvp]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[presenter]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://blog.mattwynne.net/?p=5</guid>
		<description><![CDATA[As I work with the MVP / Passive View / Humble View pattern more in ASP.NET, I&#8217;m gaining an understanding of some common smells or anti-patterns that can happen when you try to implement this pattern and haven&#8217;t quite grokked it yet. Some of these are problems I&#8217;ve had to pull out of my own [...]]]></description>
			<content:encoded><![CDATA[<p>As I work with the MVP / <a href="http://www.martinfowler.com/eaaDev/PassiveScreen.html">Passive View</a> / Humble View pattern more in ASP.NET, I&#8217;m  gaining an understanding of some common smells or anti-patterns that can happen when you try to  implement this pattern and haven&#8217;t quite grokked it yet. Some of these are  problems I&#8217;ve had to pull out of my own code:
<h3>TOO MANY PRESENTERS SPOIL THE BROTH</h3>
When you re-use a user-control or even just a view interface on different  pages, it&#8217;s tempting to re-use a special  little presenter inside each of those  pages whose sole responsibility is for presenting that usercontrol. If you have  two different flavours of page, you might even put the call to the presenter  into a BasePage.</p>

<p>This is fine as long as those pages need no other pesenter logic, but there  are usually other controls on the page too, and they&#8217;ll need to be presented,  and before you know it you have two or three or a whole crowd of presenters  yelling at different bits of your page, telling them what to do.</p>

<p>Lesson: This is the path of darkness and complexity on the tightrope of your  untestable UI layer. Re-use presenter logic by all means, but do it inside the  presenter layer, where you can test. Everybody say Ahh&#8230; Tests&#8230;</p>

<p>Maxim: No more than one presenter to be constructed per page /  request.
<h3>THE SELF-AWARE VIEW</h3>
Within a request / response cycle, only the Page should be aware of the  existence of a presenter. The HUMBLE VIEW (implemented in a UserControl) does  what it&#8217;s told without any knowledge of who is dishing out the instructions.  Find this smell by looking for UserControls which construct their own private  little presenters, or worse still accept them as properties (usually so that  they can do filthy things like call methods on them &#8211; see ARROGANT VIEW,  below).
<h3>ARROGANT VIEW</h3>
The arrogant view is not only SELF-AWARE, but has the temerity to imagine  that it has the right to give the presenter direct instructions. Thus a  presenter can easily be relegated to nothing more that a PROXY MODEL, with logic  creeping up into the untestable view layer. Find this smell by looking for  presenters which offer public methods. Replace these direct method calls from  view-&gt;presenter with a more humble OBSERVER PATTERN, where the view raises  events containing the relevant information in the EventArgs, and the presenter  reacts accordingly (or decides not to, as is its privilege).
<h3>PRESENTER BECOMES PROXY MODEL</h3>
When you have an ARROGANT VIEW that commits the crime of directly calling  methods on a presenter, you start to see the logic in the presenter thin down to  the point where it becomes little more than a proxy for the &#8216;model&#8217; (in classic  MVC terminology) or service layer. The whole idea of MVP is to delegate the  responsibility of figuring out what to fetch from the service layer and when to  fetch it, so that the view just gets on with displaying whatever the presenter  decides it should display. When an ARROGANT VIEW gets these kind of notions,  logic that belongs in a (testable) presenter is tangled up with display logic in  the view, and it&#8217;s time to roll up your sleeves and refactor.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattwynne.net/2007/06/13/mvp-smells/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

