<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">

<channel>
	<title>Hadi Hariri's Blog</title>
	
	<link>http://hadihariri.com</link>
	<description />
	<lastBuildDate>Wed, 16 May 2012 04:43:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain="hadihariri.com" port="80" path="/?rsscloud=notify" registerProcedure="" protocol="http-post" />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Hadi Hariri's Blog</title>
		<link>http://hadihariri.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://hadihariri.com/osd.xml" title="Hadi Hariri's Blog" />
	
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/HadiHariri" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="hadihariri" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://hadihariri.com/?pushpress=hub" /><item>
		<title>Instant HTML/CSS Updating</title>
		<link>http://hadihariri.com/2012/05/15/instant-htmlcss-updating/</link>
		<comments>http://hadihariri.com/2012/05/15/instant-htmlcss-updating/#comments</comments>
		<pubDate>Tue, 15 May 2012 04:40:51 +0000</pubDate>
		<dc:creator>hhariri</dc:creator>
				<category><![CDATA[JetBrains]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[WebStorm]]></category>

		<guid isPermaLink="false">http://hadihariri.com/?p=2550</guid>
		<description><![CDATA[Want instant updating to HTML / CSS pages you&#8217;re editing? See it in action You can now have it. I&#8217;ve &#8230;<p><a href="http://hadihariri.com/2012/05/15/instant-htmlcss-updating/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2550&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Want instant updating to HTML / CSS pages you&#8217;re editing?</p>
<p><a href="http://www.screenr.com/L3K8">See it in action</a></p>
<p>You can now have it. I&#8217;ve tried it on both IntelliJ IDEA and WebStorm successfully. It should most likely work on our other IDE&#8217;s too (PhpStorm, PyCharm).</p>
<p>To install:</p>
<p>1. <a href="http://plugins.intellij.net/plugin/?&amp;id=7006">Download Web Browser</a> Connector plugin for JetBrains plugin repo. This is needed for the actual Instant HTML editing plugin.</p>
<p>2. <a href="http://plugins.intellij.net/plugin/?&amp;id=7007">Download Instant HTML editing</a> plugin.</p>
<p>3. Open up WebStorm (or IDEA) and click on Preferences. Search for &#8216;plugin&#8217;</p>
<p><a href="http://hhariri.files.wordpress.com/2012/05/plugin.png"><img title="plugin" src="http://hhariri.files.wordpress.com/2012/05/plugin.png?w=393&h=222" alt="" width="393" height="222" /></a></p>
<p>4. Install the plugins previously downloaded from disk. First install the Web Browser Connector*</p>
<p><a href="http://hhariri.files.wordpress.com/2012/05/pluginfile.png"><img class="alignnone size-full wp-image-2555" title="pluginfile" src="http://hhariri.files.wordpress.com/2012/05/pluginfile.png?w=529" alt=""   /></a></p>
<p>5. Restart WebStorm (or IntelliJ)</p>
<p>6. Open up your Web Project. Under the Run menu select Instant HTML editing</p>
<p><a href="http://hhariri.files.wordpress.com/2012/05/menu.png"><img class="alignnone size-full wp-image-2553" title="menu" src="http://hhariri.files.wordpress.com/2012/05/menu.png?w=529" alt=""   /></a></p>
<p>7. Launch Chrome**. If all has gone well you should now see this below the URL bar</p>
<p><a href="http://hhariri.files.wordpress.com/2012/05/sample.png"><img class="alignnone size-full wp-image-2556" title="sample" src="http://hhariri.files.wordpress.com/2012/05/sample.png?w=529&h=251" alt="" width="529" height="251" /></a></p>
<p>As you make changes (to both HTML and CSS) you should now be able to see them updating live in Chrome.</p>
<p>It&#8217;s still early days of the plugin so there might be quirks with it, but I&#8217;m sure Vladmir will appreciate any and all feedback.</p>
<p>* You could in principle just install this directly from WebStorm by clicking on Browse Repositories without having to download. However for some reason, Web Browser Connector is not listed.</p>
<p>** Currently only works in Chrome.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2550/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hhariri.wordpress.com/2550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hhariri.wordpress.com/2550/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hhariri.wordpress.com/2550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hhariri.wordpress.com/2550/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hhariri.wordpress.com/2550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hhariri.wordpress.com/2550/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hhariri.wordpress.com/2550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hhariri.wordpress.com/2550/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hhariri.wordpress.com/2550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hhariri.wordpress.com/2550/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hhariri.wordpress.com/2550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hhariri.wordpress.com/2550/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2550&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/05/15/instant-htmlcss-updating/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/05/plugin.png" medium="image">
			<media:title type="html">plugin</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/05/pluginfile.png" medium="image">
			<media:title type="html">pluginfile</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/05/menu.png" medium="image">
			<media:title type="html">menu</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/05/sample.png" medium="image">
			<media:title type="html">sample</media:title>
		</media:content>
	</item>
		<item>
		<title>What BDD has taught me</title>
		<link>http://hadihariri.com/2012/04/11/what-bdd-has-taught-me/</link>
		<comments>http://hadihariri.com/2012/04/11/what-bdd-has-taught-me/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 16:16:24 +0000</pubDate>
		<dc:creator>hhariri</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://hadihariri.com/?p=2495</guid>
		<description><![CDATA[Every so often I hear comments such as the one below: I don&#8217;t get what BDD offers me over TDD &#8230;<p><a href="http://hadihariri.com/2012/04/11/what-bdd-has-taught-me/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2495&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Every so often I hear comments such as the one below:</p>
<blockquote><p>I don&#8217;t get what BDD offers me over TDD</p></blockquote>
<p>and it usually is in the context of some framework. I had this happen the other day and like many things that take place on Twitter, it led to more conversations about what BDD is and what it means to different people.</p>
<h3>far from the horse&#8217;s mouth</h3>
<p><a href="http://dannorth.net/introducing-bdd/">Dan North coined the term BDD</a> many years ago, and I by no means aim to redefine it. As such, nothing of what I claim here necessarily coincides with Dan&#8217;s definition. This post is exclusively my own opinion. My only certainty is that he at least somewhat agrees with me on this statement:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/04/dannorth.png"><img class="alignnone size-full wp-image-2496" title="dannorth" src="http://hhariri.files.wordpress.com/2012/04/dannorth.png?w=529" alt=""   /></a></p>
<p>Dan&#8217;s paper taught me a few things and confirmed that other things I was doing were on the right track:</p>
<h1>It&#8217;s about communication</h1>
<p>First and foremost: communication, at all levels.  It is talking to the customer, the business, understanding their needs, asking them why they need that feature, 5 times to make sure they really do. Understanding what exactly the feature is, understanding who it is that needs the feature.</p>
<p>Writing the Story cards in a specific format is about asking the right questions, not having a pretty format on a Kanban board or in a <em>Cucumber </em>test.</p>
<p>Whether your customer is the business owner or a developer, is irrelevant. The only difference is the context changes. Whereby a customer doesn&#8217;t care about the term exception appearing in a story, but does care about an error page, a developer cares about an exception being part of the text.</p>
<h1>It&#8217;s about specifications</h1>
<p>The tests I write are about defining the <strong>specification</strong> of the system. They are the <strong>documentation</strong>, they are the contract. As my system updates, so do my tests, my specifications. I make no distinction between a user interface or a call to a message queue. They are all specifications.</p>
<h3>Misconceptions I have seen</h3>
<p>Some things which I feel are misconceptions (or at least what I don&#8217;t necessarily agree with), and are somewhat putting people on the wrong track:</p>
<h1>BDD is a framework</h1>
<p>Dan came out with JBehave in an attempt to dissociate Test Driven Design with Testing. To make his students focus on using TDD as a means in defining the behavior of the software they were writing, and prevent a continuous focus on testing.</p>
<p>As such, nothing forces people into using a BDD framework, because there really is no such thing. Unfortunately the continuous appearance of more and more so-called &#8220;BDD Frameworks&#8221; and guidance as the one below, do not help</p>
<p><a href="http://hhariri.files.wordpress.com/2012/04/mocha.png"><img class="alignnone size-full wp-image-2497" title="mocha" src="http://hhariri.files.wordpress.com/2012/04/mocha.png?w=529&h=134" alt="" width="529" height="134" /></a></p>
<p>Much like BDD is not about frameworks, it is also not about keywords or flavors.</p>
<h1>BDD is for defining system behavior</h1>
<p>Dan emphasizes the word <strong>behavior</strong> and this is also apparent in the naming of the framework JBehave. This often leads to comments of the type:</p>
<blockquote><p>I use BDD to define more the system&#8217;s behavior and use TDD for lower level components</p></blockquote>
<p>Every single part of a system, from the user interface, down to the individual method on a class has behavior. As such, saying one is for defining behavior and another for defining &lt;insert_alternative_to_behavior_here&gt; makes little sense.</p>
<p>Software has specifications. We define specifications.</p>
<h1>BDD is for Business Applications</h1>
<p>Here is a common meme</p>
<blockquote><p>I use BDD for Business applications. For libraries I use TDD</p></blockquote>
<p>Assuming that BDD is defining a specification, why is that a library does not require its specification to be defined? Maybe the answer to that question is the next item:</p>
<h1>BDD is too explicit</h1>
<blockquote><p>BDD frameworks are too explicit. They are too verbose. For Customers this is great, but for developers it&#8217;s too much to cope with</p></blockquote>
<p>How is more bad?</p>
<p>Most likely because we <em>assume</em> that developers are smarter, they are more familiar with the domain they are working in. Yes. Every developer has seen a DAL. Every developer has worked with that specific logging component. Every developer has worked with that specific Message queue. They don&#8217;t expect detailed specification of how the libraries work, they just <em>assume</em> things. There&#8217;s that word again: <em>assumption</em>.</p>
<p>Everyone agrees that 100% test coverage or all tests green mean nothing. You could have everything working, but have the wrong thing working. The only one that can truly confirm that something is correct is the person asking for it: the consumer.</p>
<p>As such, if we look at a unit test that passes, with no clear description of what the unit does other than the code in it, what have we got to contrast it against? That is why specifying the conditions under which an action takes place, describing the action taking place and defining the expected results serve as a means to verify that the code is doing what the specification is describing.</p>
<p>In Business applications it is true that not all developers are familiar with the domain they work on. However, in software development, where the domain is software, this also holds true. Or you&#8217;re telling me that you&#8217;re familiar with ReSharper&#8217;s PSI subsystem?</p>
<h1>BDD frameworks are for higher level, TDD for lower level components</h1>
<p>This is not only again making a distinction between types of frameworks, but it is also making the assumption that somehow higher level aspects of an application are different than lower level aspects.</p>
<h1>BDD frameworks are for end users to use</h1>
<p>Frameworks such as <em>Cucumber </em>which allow for nicely formatted and descriptive specifications, have led many to believe that customers can end up writing these without the intervention of developers. If communication is key, how can we even begin to imagine that this would be a good idea? Who is there to ask the questions?</p>
<h1>BDD is for Integration Testing, TDD is Unit Testing</h1>
<p>If we accept the term Integration of testing more than one real component of the system at the same time, then BDD is no more of integration test than TDD is depending on the school of thought you follow (i.e. do I mock or do I not mock).</p>
<h1>BDD is GWT, TDD is AAA</h1>
<p>AAA is the typical pattern for unit testing: <strong>Arrange, Act and Assert</strong>, whereby you setup the unit under test, execute the action and verify the result.</p>
<pre>arrange

act

assert</pre>
<p>GWT stands for<strong> Given, When, Then</strong>, which is usually identified with BDD frameworks</p>
<pre>given_a_series_of_conditions

when_I_do_something

then_something_happens</pre>
<p>If you look closely, you can see that there is no real difference between the two. Both are about setting up scenarios, executing and validating. The only difference is one is more explicit.</p>
<h1>TDD is one assert, BDD has more</h1>
<p>There is a spoken rule in Unit Testing that states there should only be one Assert per test. The main reason for this is so that when the test fails, you know where its failed.</p>
<p>There is nothing in the &#8220;BDD World&#8221; that indicates that a test should have more than one assertion. However, if we consider tests for what they are, which is specification, depending on the level at which we are located, i.e. are we talking about user interaction or method calls, there is a potential for more than one result from an action.</p>
<p>For instance:</p>
<p><em>when a user tries to log in to a web site with invalid credentials, he/she should receive an error message and the administrator should get notified</em>.</p>
<p>This specification clearly demands two verifications be made.</p>
<p>Applying the same techniques to a method call:</p>
<p><em>when executing GetCustomerById with an invalid customer, it should return null</em></p>
<p>only requires one assertion.</p>
<p>Doing this does not necessarily make it harder to detect where a failure is. Some frameworks make this easier than others.  For instance, in MSpec, the above test could look something like the following:</p>
<pre>public class when_user_logs_in_with_invalid_credentials {
  Establish context =&gt; {....}
  Because of =&gt; {...}
  It should_redirect_to_error_page =&gt; { // One assert only }
  It should_notify_administrador =&gt; { // One assert only }
}</pre>
<p>Each verification block (<em>It</em>) usually only has one assertion.</p>
<h1>BDD is outside-in. TDD is inside-out</h1>
<p>From the time it clicked for me that TDD was about writing specifications, I have always taken an outside-in approach when developing systems. I start with the most external &#8220;component&#8221; which usually is the user interaction (not UI, but what the UI interacts with such as a Controller in a web application) and start driving the specifications from there inwards. From there I specify internal components and so on and so forth. This allows me to have a usage scenario for every component.</p>
<p>The alternative approach (could be called inside-out) is to start driving out individual components of the system and putting them together. However, if TDD is about trying out a component to see if it fits the need, how could this possibly work if we are not basing the prototyping on an real usage scenario?</p>
<h3>Do frameworks really not matter?</h3>
<p>I started this post pointing to the unnecessary divide between TDD/BDD frameworks and have kept repeating that I am against the BDD vs TDD framework distinction, specially considering that I see no distinction between TDD/BDD.</p>
<p>Having said that, some frameworks make certain things easier, such as built-in support for multiple verification blocks (MSpec), nicely formatted printouts that can be used as specifications which can be understood by all people, technical and non-technical (MSpec, Cucumber). Some also have downsides. For instance MSpec doesn&#8217;t support very well the concept of multiple-input testing.</p>
<p>I normally stick to one framework. If you want to use two, use two, but stop focusing the distinction on TDD vs BDD or on more vs less verbosity.</p>
<h3>what i strive for</h3>
<p>Dan North gave the following definition of BDD in November 2009, in London:</p>
<blockquote><p>BDD is a second-generation, outside–in, pull-based, multiple-stakeholder, multiple-scale, high-automation, agile methodology. It describes a cycle of interactions with well-defined outputs, resulting in the delivery of working, tested software that matters.</p>
<div></div>
</blockquote>
<p>Whether what I do fits in with that or not, I&#8217;m not too worried about.</p>
<p>What is important for me is that when someone else looks at my project, if it is a business application, they clearly, without having to make any assumptions, understand how things work. When they look at my API specifications, they serve as documentation and live examples of how to use my library.</p>
<p>My concern is to perfect this, and over the years, as I come back to projects I&#8217;ve worked on, I see the mistakes I&#8217;ve made (mostly in the form of assumptions, other times in the form of organization of specifications) and I try and improve it on every new project.</p>
<p>There is no difference between BDD and TDD frameworks because there is no difference between BDD and TDD. It&#8217;s just doing things right.</p>
<p>And if I got this whole BDD thing wrong, my bad. However,  I&#8217;m not chasing an acronym.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2495/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hhariri.wordpress.com/2495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hhariri.wordpress.com/2495/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hhariri.wordpress.com/2495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hhariri.wordpress.com/2495/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hhariri.wordpress.com/2495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hhariri.wordpress.com/2495/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hhariri.wordpress.com/2495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hhariri.wordpress.com/2495/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hhariri.wordpress.com/2495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hhariri.wordpress.com/2495/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hhariri.wordpress.com/2495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hhariri.wordpress.com/2495/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2495&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/04/11/what-bdd-has-taught-me/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/dannorth.png" medium="image">
			<media:title type="html">dannorth</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/mocha.png" medium="image">
			<media:title type="html">mocha</media:title>
		</media:content>
	</item>
		<item>
		<title>Dealing with the “Too many dependencies” problem</title>
		<link>http://hadihariri.com/2012/04/09/dealing-wht-the-too-many-dependencies-problem/</link>
		<comments>http://hadihariri.com/2012/04/09/dealing-wht-the-too-many-dependencies-problem/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 16:53:33 +0000</pubDate>
		<dc:creator>hhariri</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://hadihariri.com/?p=2455</guid>
		<description><![CDATA[Earlier I asked whether people thought the issue of passing in too many dependencies into a class was an actual problem. &#8230;<p><a href="http://hadihariri.com/2012/04/09/dealing-wht-the-too-many-dependencies-problem/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2455&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Earlier <a href="http://hadihariri.com/2012/04/09/too-many-dependencies/">I asked</a> whether people thought the issue of passing in too many dependencies into a class was an actual problem. This was in response to another post I did about <a href="http://hadihariri.com/2012/04/07/test-setups-and-design-smells/">test smells</a>. A few people had asked me how the problem of a controller having way too many dependencies should be solved. My <a href="https://twitter.com/#!/hhariri/status/188730907115528194">response</a> to <a href="https://twitter.com/#!/hhariri/status/188705084971028480">them</a> was to apply Single Responsibility Principle, which is pretty much <a href="http://hadihariri.com/2012/04/09/too-many-dependencies/#comments">what others also said</a>.</p>
<h3>The problem</h3>
<p>Here is the problem:</p>
<p><img title="Controller" src="http://hhariri.files.wordpress.com/2012/04/image4.png?w=519&h=470" alt="" width="519" height="470" /></p>
<p>In this case it is a controller, but it can well be any other type of class.</p>
<h3>Dependency Injection does not solve tight coupling</h3>
<p>Why is this a problem? After all, we are applying Dependency Injection.</p>
<p>We are, but we are not decoupling classes. All we are doing is allowing a specific implementation to be swapped out easily. Whether we&#8217;re doing it because we want to change behaviors in tests or at runtime, all we&#8217;re doing is avoiding depending on a specific implementation.</p>
<p>What we are not doing is automagically making our code clean and sustainable.</p>
<p>The more dependencies our class takes in, the higher its efferent coupling to other classes, meaning that it knows a little bit too much. If it knows too much, it is  most likely because it is also doing too much. The class is no longer focused on one thing, and as a consequence we are creating somewhat brittle software that is too tightly coupled, even if we are passing in our dependencies, even if we are not using <em>new</em> anymore.</p>
<h3>How did we get here?</h3>
<p>We all agree that DI is good and so is Composition over Inheritance. And this causes us to end up with classes that act as coordinators or require information or perform actions on these different classes. Other times we end up here because of:</p>
<h2>Framework impositions</h2>
<p>Often, frameworks impose restrictions that take us down the wrong path. Such is the case of ASP.NET MVC when using the default routing conventions. We mostly encapsulate functionality under a specific controller because the routing suites us. In other words, from a user&#8217;s perspective it makes sense to have many things under the <strong>/checkout/<em>{action}</em></strong> path, even if that leads us to bloated controllers<em> </em>that take many dependencies which have little to do with each other.</p>
<div>
<h2>Badly named classes</h2>
<p><em>XYZService</em> or <em>XYZManager</em> named classes are yet another example of ending up with too many dependencies. When we start to encapsulate everything under a <em>service </em>or <em>manager</em>, we find that despite some of the dependencies only being used by one or two methods, still have to be passed in.</p>
<h2>IoC Containers</h2>
<p>As developers we no longer worry about wiring up all the different required dependencies as Containers now do this for us. This allows us to inject and inject and inject.</p>
<h3>Helping solve the problem</h3>
<p>First and foremost, and despite it being beaten to death, we need to apply Single Responsibility Principle. <a href="http://hadihariri.com/2010/12/18/srp-as-easy-as-123/">I&#8217;ve written in the past</a> techniques that have often helped me accomplish this. Taking this into account, there&#8217;s also a series of Do&#8217;s and Don&#8217;ts that can help:</p>
<h1>What you can do</h1>
<ul>
<li><strong>Work around framework limitations</strong>. For instance, in the case of ASP.NET MVC, you can override the routing behavior to not tie you down to using one class just because you need to keep the same URL. This can be done in various ways. Google <em>Controllerless Actions</em> for some examples (just a starting point).</li>
<li><strong>Create small focused classes</strong>. Why create a <em>CustomerServices<strong> </strong></em>that takes in five dependencies as opposed to creating <em>MakeCustomerPreferredCommand </em>and <em>InvalidateCustomerCommand</em> class that takes one dependency and has a single method to do what is required?</li>
<li><strong>Extract infrastructure</strong>. Don&#8217;t pass in dependencies that have to do with infrastructure, specially if these are repetitive. Use techniques such as AOP to apply these at the level where they belong.</li>
<li><strong>Think about Patterns</strong>. Often patterns can help solve the problem of too many dependencies. For instance, many times, what&#8217;s deemed as a large collaborative class can instead be turned into a series of classes using the Chain of Responsibility pattern.</li>
<li><strong>Events. </strong>Event driven architecture is a great way to provide higher decoupling and independence between objects.</li>
<li><strong>CQRS</strong>. Well I just had to mention this one because it&#8217;s fashionable. In all seriousness though, this also allows for lower of dependencies since it separates responsibilities into smaller commands and separate queries, which again is our goal.</li>
</ul>
<h1>What you shouldn&#8217;t do</h1>
<ul>
<li><strong>You shouldn&#8217;t switch to using Service Locator</strong> as opposed to Dependency Injection. All you&#8217;re doing is hiding the problem. Dependency Injection is actually beneficial in that it is showing us that we are breaking SRP and have a high coupling.</li>
<li><strong>You shouldn&#8217;t stop using an IoC Container</strong>. There are other ways to prevent the  Inject Happy Developer. Testing your code is one of them. As you write tests, you&#8217;ll suffer the pain of having to set things up over and over again (and refrain from encapsulating that).</li>
</ul>
<p>These are just some simple guidelines. They are not set in stone.</p>
<h3>Injection Happy Detector</h3>
<p>Finally, while writing the initial post, I came up with an idea of writing a ReSharper plugin that could help detect classes that have too many dependencies. The result is<br />
the <a href="https://github.com/hhariri/ReSharperPlugins">InjectionHappy Detector</a>. Once installed, it gives you a warning if it finds a constructor taking in too many interfaces. This number by default is 3 (just some random value, you can change it yourself under Options). It&#8217;s a very simple plugin and not full-proof. More of an experiment. You&#8217;re free to fork it and enhance it anyway you wish.</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hhariri.wordpress.com/2455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hhariri.wordpress.com/2455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hhariri.wordpress.com/2455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hhariri.wordpress.com/2455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hhariri.wordpress.com/2455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hhariri.wordpress.com/2455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hhariri.wordpress.com/2455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hhariri.wordpress.com/2455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hhariri.wordpress.com/2455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hhariri.wordpress.com/2455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hhariri.wordpress.com/2455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hhariri.wordpress.com/2455/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2455&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/04/09/dealing-wht-the-too-many-dependencies-problem/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/image4.png?w=529" medium="image">
			<media:title type="html">Controller</media:title>
		</media:content>
	</item>
		<item>
		<title>Too many dependencies?</title>
		<link>http://hadihariri.com/2012/04/09/too-many-dependencies/</link>
		<comments>http://hadihariri.com/2012/04/09/too-many-dependencies/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 09:30:46 +0000</pubDate>
		<dc:creator>hhariri</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2449</guid>
		<description><![CDATA[Over the weekend I blogged about a recurrent issue I encounter when looking at tests, which is the encapsulation of &#8230;<p><a href="http://hadihariri.com/2012/04/09/too-many-dependencies/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2449&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Over the weekend <a href="http://hadihariri.com/2012/04/07/test-setups-and-design-smells/">I blogged about a recurrent issue I encounter when looking at tests</a>, which is the encapsulation of the <em>Arrange </em>part of the <em>Arrange-Act-Assert </em>pattern in either setup methods or base classes. Although there are justified use-cases for it, the majority of times it’s a sign of a code smell. </p>
<p>The example I put was one of a Controller having too many dependencies, and I was asked a few times how to avoid this problem. The purpose of the blog post was not around this issue itself but around test setups. However, it is a valid question, and one that has been raised over the past months questioning the usage of IoC Containers.</p>
<p>So I wonder, do you think this is a problem? If so, how many dependencies is too many? How would you avoid it? </p>
<p>&nbsp;</p>
<p><img src="http://hhariri.files.wordpress.com/2012/04/image4.png?w=529"></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hhariri.wordpress.com/2449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hhariri.wordpress.com/2449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hhariri.wordpress.com/2449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hhariri.wordpress.com/2449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hhariri.wordpress.com/2449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hhariri.wordpress.com/2449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hhariri.wordpress.com/2449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hhariri.wordpress.com/2449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hhariri.wordpress.com/2449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hhariri.wordpress.com/2449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hhariri.wordpress.com/2449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hhariri.wordpress.com/2449/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2449&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/04/09/too-many-dependencies/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/image4.png" medium="image" />
	</item>
		<item>
		<title>Test setups and design smells</title>
		<link>http://hadihariri.com/2012/04/07/test-setups-and-design-smells/</link>
		<comments>http://hadihariri.com/2012/04/07/test-setups-and-design-smells/#comments</comments>
		<pubDate>Sat, 07 Apr 2012 17:18:23 +0000</pubDate>
		<dc:creator>hhariri</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2439</guid>
		<description><![CDATA[Reviewing some code today, I keep stumbling across private methods that are encapsulating test setups. A probable reason for this &#8230;<p><a href="http://hadihariri.com/2012/04/07/test-setups-and-design-smells/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2439&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Reviewing some code today, I keep stumbling across private methods that are encapsulating test setups. A probable reason for this is that the authors want to prevent having to repeat the same code over and over again. It seems like common sense. I mean after all, that’s one way of complying with DRY.&nbsp; </p>
<p>The problem however is that often this kind of encapsulation is hiding an underlying design problem.</p>
<p>As an example, I’m going to use one of my all time favorite code-bases that I reference in talks I give on MVC and design in general:</p>
<p>&nbsp;</p>
<p><a href="http://hhariri.files.wordpress.com/2012/04/image5.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://hhariri.files.wordpress.com/2012/04/image_thumb5.png?w=794&h=418" width="794" height="418"></a></p>
<p>&nbsp;</p>
<p>Look at the <em>Authenticated_Shipping_With_EmtpyCart</em> test. It’s short and straightforward. However, notice how the test class has a <em>TestBase: </em></p>
<p><em></em>&nbsp;</p>
<p><a href="http://hhariri.files.wordpress.com/2012/04/image6.png"><img style="background-image:none;border-bottom:0;border-left:0;margin:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://hhariri.files.wordpress.com/2012/04/image_thumb6.png?w=680&h=609" width="680" height="609"></a></p>
<p>&nbsp;</p>
<p>I chopped off the remaining part as it wouldn’t fit on the screen. You can see the <a href="http://erpstore.codeplex.com/SourceControl/changeset/view/88814#1575530">entire class here</a>.&nbsp; It’s just wrong on so many levels.</p>
<p>If you look at the controller this is testing (<em>CheckoutController</em>), you’ll see:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/04/image4.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://hhariri.files.wordpress.com/2012/04/image_thumb4.png?w=519&h=470" width="519" height="470"></a></p>
<p>&nbsp;</p>
<p>If I were to write that out every time I would need to test the controller, alarm signals would raise that I’m doing something wrong. If I’m hiding it away in a base class or a method, it’s harder to notice.&nbsp; </p>
<p>So next time you feel the urge to encapsulate some setup in a method or base class, ask yourself why. If you don’t come up with a good reason, re-think your design. </p>
<p>&nbsp;</p>
<p><strong>Side-note</strong>: Some people have lately been complaining that IoC Containers lead to these kind of design smells also, allowing developers to by injection-happy when dealing with dependencies. It might be true, although I believe that if you are correctly writing the necessary tests, you’d notice this problem early on. The code above also uses a container in the tests (and doesn’t even use conventions for setting it up). That’s another reason I’m against using containers in <em>unit </em>tests<em>. </em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hhariri.wordpress.com/2439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hhariri.wordpress.com/2439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hhariri.wordpress.com/2439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hhariri.wordpress.com/2439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hhariri.wordpress.com/2439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hhariri.wordpress.com/2439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hhariri.wordpress.com/2439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hhariri.wordpress.com/2439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hhariri.wordpress.com/2439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hhariri.wordpress.com/2439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hhariri.wordpress.com/2439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hhariri.wordpress.com/2439/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2439&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/04/07/test-setups-and-design-smells/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Is your identity in your own hands?</title>
		<link>http://hadihariri.com/2012/04/07/is-your-identity-in-your-own-hands/</link>
		<comments>http://hadihariri.com/2012/04/07/is-your-identity-in-your-own-hands/#comments</comments>
		<pubDate>Sat, 07 Apr 2012 09:05:05 +0000</pubDate>
		<dc:creator>hhariri</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2401</guid>
		<description><![CDATA[If you&#8217;re using a @gmail.com address, you should read this For quite a few number of years, I’ve switched my &#8230;<p><a href="http://hadihariri.com/2012/04/07/is-your-identity-in-your-own-hands/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2401&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>If you&#8217;re using a @gmail.com address, you should read this</em></p>
<p>For quite a few number of years, I’ve switched my mail over entirely to GMail. By that, I don’t mean just using the Web Interface, but also making my @gmail.com address my primary one. Prior to that, I was using (and still handing out sometimes) my own domain address (@hadihariri.com).</p>
<p>Although GMail allows management of multiple accounts* when sending out emails, for a variety of reasons, including preventing setting up multiple accounts on different devices and apps, I made my @gmail.com account the default. This meant that every time I&#8217;d send out new email or respond to one, it would be sent out through my @gmail.com address.</p>
<p>Everyone was using GMail and handing out GMail accounts left and right, why shouldn&#8217;t I?</p>
<p align="justify">Even though I&#8217;d switched to GMail, for some time I was still using desktop apps for email, accessing GMail via POP/IMAP. And when it comes to these, I’ve tried them all, be it Outlook Express, then  Outlook, then The Bat, and so on and so forth. My main concern was having access to my email, be it whether I was traveling and didn’t have a connection or for back-up purposes. However, at some point, after being fed up with Outlook PST corrupt files, I gave up and went fully-fledge web. I thought, well Google’s going to do a hell of a better job of storing my email than I would, so forget this whole backup nonsense. Plus, GMail now offered a pretty decent offline experience, so win-win.</p>
<p align="justify">*[If you’re not familiar with this, you can change the setting under <strong>Settings | Account]</strong></p>
<p align="justify"><a href="http://hhariri.files.wordpress.com/2012/04/image.png"><img title="image" src="http://hhariri.files.wordpress.com/2012/04/image_thumb.png?w=961&h=127" alt="image" width="961" height="127" border="0" /></a></p>
<h1>Solving offline experience and backups</h1>
<p>Despite Google never going down and having my mail backed up, the thought that all my email was somewhere where one day I could lose access to it, still haunted me. One solution I came up with was to enable offline storage of GMail for the maximum amount of time possible. Back then this was around 5 years. Guess what? It didn’t work. The experience became horrible (and yes they did warn you). Even with a connection, searching was horrendous. And on slow connections, it was dreadful. I soon gave up on that.</p>
<p>My other option was to use some third-party cloud service to back-up, giving them access to my GMail account. Something just didn’t entice me about that however.</p>
<h2>The local backup</h2>
<p>Having had Thunderbird installed for a secondary account I manage, I decided to switch back to desktop app for a while. So I set up GMail to use IMAP and all was good. I didn&#8217;t last though. A lot of the features in the Web interface made working with mail much easier (grouped conversations, labels, etc.).</p>
<p>However, I did solve my backup problem. I configured Thunderbird to sync all messages and keep local copies:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/04/snaghtml4f44488.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="SNAGHTML4f44488" src="http://hhariri.files.wordpress.com/2012/04/snaghtml4f44488_thumb.png?w=647&h=698" alt="SNAGHTML4f44488" width="647" height="698" border="0" /></a></p>
<p>Every day or every other day, I open up Thunderbird and let it churn away syncing my account. I now combine this with CrashPlan which then backs up my Thunderbird folders in the cloud.</p>
<h2>All is good</h2>
<p>All seemed good. I had my email backed up in three different places, GMail, my local machine and CrashPlan’s servers. I even had offline experience when I wanted using Thunderbird. What could possibly go wrong?</p>
<p><a href="http://hhariri.files.wordpress.com/2012/04/image1.png"><img style="background-image:none;margin:0;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://hhariri.files.wordpress.com/2012/04/image_thumb1.png?w=722&h=410" alt="image" width="722" height="410" border="0" /></a></p>
<p>30 seconds turned into more than 24 hours.</p>
<p>Last week, I lost access to GMail for nearly a day and a half. What was quite scary about it was that for the first 12 hours, it seemed I was the only one. Nobody else was having problems despite multiple times asking on Twitter and <a href="https://plus.google.com/104619260726652709787/posts/3jfQZSeBYmv">Googe+</a>.</p>
<p>At some point though I felt more relieved finding out I was not alone:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/04/better.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="better" src="http://hhariri.files.wordpress.com/2012/04/better_thumb.png?w=510&h=801" alt="better" width="510" height="801" border="0" /></a></p>
<p>Realizing this could actually last for some time, I logged into my domain provider and stopped the forwarding of my @hadihariri.com accounts to @gmail.com. I created individual accounts for them and started using the Web Mail to access these. But guess what? Out of the more than +100 emails that were piled up in the short interval I had no access, only around 5-6 came through to my @hadihariri.com domains.</p>
<p>That’s when it struck me. <strong>Reaching me was in Google’s control</strong>.</p>
<h2>Big deal. You lost email for 24 hours</h2>
<p>Now you might be thinking that this isn’t such a big deal. That losing email for a day is not the end of the world. It is not. I could have actually been quite productive that day if I hadn’t been so concerned about reaching my email. However, what it made me realize is that I am dependent on Google to be reached.  Having switched over to GMail fully, and giving out my GMail account as the primary one, Google now controlled if and when people could reach me.</p>
<p>Now although GMail does not go down very often, and even if we consider they&#8217;d never terminate the free service (at some point when I read the TOS, it indicated that they could stop providing the service when they wanted to), there is always the possibility that Google can explicitly terminate <em>your</em> account, or block it for some unknown reason. I don’t have to link to explicit stories, but I’m sure if you search for accounts being blocked or deleted, you’ll come up with a ton of stories. And if none of that occurs, there is always the risk of someone hacking your account and deleting it.</p>
<p>In other words, your net existence, specially if you’re not very “social” and have Twitter, Facebook accounts, is exclusively in Google’s hands.</p>
<p>The sad thing about this is, that in my case, I put it there.</p>
<h2></h2>
<h2>Steps to take</h2>
<p>After this occurred, I took a few steps. I stopped making @gmail.com my default Reply-From and switched back to using my @hadihariri.com domain. I also took a few other steps, which I&#8217;d recommend you consider too:</p>
<ul>
<li><strong>Have a backup plan</strong>. Don’t rely exclusively on your mail provider. Whether you trust having a cloud service backup your email or go down the route I’ve taken to backup locally, doesn’t matter. But have a backup.</li>
<li><strong>Make sure you own the identity you hand out</strong>. Have your own domain, specially if you are a business. Sure, you might lose your domain, but the chances of that happening are slim. And domains aren’t locked to providers.</li>
<li><strong>Secure your account</strong>. If using Google, enable two-step verification. Also, try and limit who can and cannot access your Google identity as an OpenID provider. Don’t just trust any application.</li>
<li><strong>Provide your domain account as your password </strong><strong>recovery</strong>. One other step I took was change some of the social networks I&#8217;m signed up to and provide an alternate email account for access/password recovery. In fact, even GMail asks for this. Make sure you don&#8217;t lock it to @gmail.com since many services require confirmation of change of email address and if you lose access, you can&#8217;t do it.</li>
</ul>
<p>Of course, everything I say can be applied to Google, Hotmail, Yahoo or any other service providing you with a primary email address. It is far from my intention to single out Google or make Google look evil. I am the primary person responsible for these mistakes.</p>
<p>And while I hope I won&#8217;t have to experience this again, I am glad I did. It was my wake-up call.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hhariri.wordpress.com/2401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hhariri.wordpress.com/2401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hhariri.wordpress.com/2401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hhariri.wordpress.com/2401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hhariri.wordpress.com/2401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hhariri.wordpress.com/2401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hhariri.wordpress.com/2401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hhariri.wordpress.com/2401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hhariri.wordpress.com/2401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hhariri.wordpress.com/2401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hhariri.wordpress.com/2401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hhariri.wordpress.com/2401/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2401&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/04/07/is-your-identity-in-your-own-hands/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/snaghtml4f44488_thumb.png" medium="image">
			<media:title type="html">SNAGHTML4f44488</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/better_thumb.png" medium="image">
			<media:title type="html">better</media:title>
		</media:content>
	</item>
		<item>
		<title>With HTTP, your application is your API</title>
		<link>http://hadihariri.com/2012/04/06/with-http-your-application-is-your-api/</link>
		<comments>http://hadihariri.com/2012/04/06/with-http-your-application-is-your-api/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 22:37:43 +0000</pubDate>
		<dc:creator>hhariri</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://hadihariri.com/?p=2383</guid>
		<description><![CDATA[As of ASP.NET MVC 4.0, the once-named WCF WebAPI project is now part of MVC. To provide a quick summary for &#8230;<p><a href="http://hadihariri.com/2012/04/06/with-http-your-application-is-your-api/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2383&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As of ASP.NET MVC 4.0, the once-named WCF WebAPI project is now part of MVC. To provide a quick summary for those not familiar with either of the two:</p>
<ul>
<li>ASP.NET MVC is a framework that allows you to create applications based on HTTP.</li>
<li>WebAPI is a framework that allows you to create applications based on HTTP.</li>
</ul>
<p>So now, under one roof (the roof being ASP.NET MVC not ASP.NET which would have made a bit more sense) you can use two distinct technologies to create HTTP-based applications. Note that I&#8217;m talking about HTTP, not necessarily what one would call RESTful systems, but plain HTTP.</p>
<h1>Two choices, what to do?</h1>
<p>Which one to choose from though? Well, the problem with that question (or maybe a somewhat answer) is that neither of the two technologies is complete. Each have their own missing features and benefits.</p>
<p>With ASP.NET MVC, out of the box, you don&#8217;t get things like Content Negotiation, Support for Conditional GETs or PUTs, Complete HTTP Response codes, HTTP Authentication, among other things. And in case you&#8217;re wanting to take a resource approach, well you&#8217;re out of luck there too since MVC is focused around operations not resources. You do get nice support for View Engines though.</p>
<p>On the other hand, with WebAPI, you do get some of the previous things, mainly Content Negotiation and a more Resource orientated approach (or so it has been said). You also get self-hosting capabilities and are more &#8220;exposed&#8221; to the raw HTTP. But, you don&#8217;t get a View Engine. What this means is that you can&#8217;t easily throw together some template in Razor and have it display to in a browser as a user interface.</p>
<h1>The Microsoft Guidance</h1>
<p>The general guidance coming out of Microsoft, be it from blog posts, tutorials or generally what members of the ASP.NET team are recommending, is to use the best of both worlds. That is, use MVC to create your user interface and use WebAPI to create your API. You can have a <em>CustomerController </em>to handle the HTML views and interaction with real humans, and have an <em>CustomerAPIController </em>(or whatever is may be called) to deal with non-human software interacting with your system. There are wizards in the product to create the different types of controllers and the main debate going on seems to focus more around what folder each type of controller should reside in. It is also mostly being defended under the Separation of Concerns Act.</p>
<p>To be clear, it is recommended to:</p>
<ul>
<li>Create your user interface with MVC</li>
<li>Create your API with WebAPI</li>
</ul>
<h1>There is no division</h1>
<p>When you&#8217;re creating an application based on HTTP, your application protocol, that is the language that is used to communicate between your application and the consumer of your application is HTTP. HTTP is not a mere conduit to transfer information. It is a fully fledged application protocol.  It has operations, it has request headers, it has responses and response code. It knows how to deal with stale data, it knows how to deal with authentication. It knows what resources are and how to represent these in different way. It is your API.</p>
<p>If you take this into account, your User Interface, is nothing more than another consumer of your API. When you request to see a Customer, if you are a human being, you will be presented with an HTML page to see the customer record. When you are a machine you can request a JSON or XML variant of that customer. However, these are merely two different representations of the same thing. When you update  a customer, be it via a user inputing data into a form, or a machine submitting a POST request, there should be no distinction in the behavior of your application. Why would there by? And if there isn&#8217;t, why add an extra overhead of separating them out? It makes no sense whatsoever to try and artificially separate these two concepts out into UI and an API. The only UI thing you need to do on the server is forms and HTML pages. Not separate controllers.<br />
Well there are two potential reasons you might want to do this:</p>
<ul>
<li>Political, to somehow justify having two ways to implement the same thing</li>
<li>Technical. Shortcomings of one technology prohibiting you from doing it</li>
</ul>
<p>But neither of those stand. The political reason here should be irrelevant to you as a consumer of the ASP.NET MVC stack. More importantly however, the technical reason should not distort the reality.</p>
<h1>So what should you do?</h1>
<p>Personally I am against drawing this artificial non-existing line between the two concepts merely to justify technical shortcomings. The solution I would take is to have one API and use one of the two technologies, or if you&#8217;re open to alternatives, use those (OpenRasta, Nancy, FubuMVC), whatever,  I don&#8217;t care which one you use.</p>
<p>I have been using MVC for some years and the missing pieces such as content negotiation, HTTP authentication, ETag support (conditional requests), are nothing but a bunch of filters that are implemented with a few lines of code. Moving from operations to resources is nothing but a few routing techniques, implemented using some conventions (if you&#8217;re interested I have a lot of code I can share).</p>
<p>Whatever you do use though, don&#8217;t let its shortcoming dictate your design. You are implementing HTTP systems, embrace HTTP.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hhariri.wordpress.com/2383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hhariri.wordpress.com/2383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hhariri.wordpress.com/2383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hhariri.wordpress.com/2383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hhariri.wordpress.com/2383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hhariri.wordpress.com/2383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hhariri.wordpress.com/2383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hhariri.wordpress.com/2383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hhariri.wordpress.com/2383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hhariri.wordpress.com/2383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hhariri.wordpress.com/2383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hhariri.wordpress.com/2383/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2383&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/04/06/with-http-your-application-is-your-api/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>
	</item>
		<item>
		<title>Keyboard shortcuts aren’t always the right approach</title>
		<link>http://hadihariri.com/2012/04/01/keyboard-shortcuts-arent-always-the-right-way/</link>
		<comments>http://hadihariri.com/2012/04/01/keyboard-shortcuts-arent-always-the-right-way/#comments</comments>
		<pubDate>Sun, 01 Apr 2012 21:17:27 +0000</pubDate>
		<dc:creator>hhariri</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://hadihariri.com/?p=2352</guid>
		<description><![CDATA[Scott Hanselman had a post recently about shortcuts and web applications. Going through the list can be somewhat scary, specially &#8230;<p><a href="http://hadihariri.com/2012/04/01/keyboard-shortcuts-arent-always-the-right-way/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2352&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Scott Hanselman had a <a href="http://www.hanselman.com/blog/TheWebIsTheNewTerminalAreYouUsingTheWebsKeyboardShortcutsAndHotkeys.aspx">post recently about shortcuts and web applications</a>. Going through the list can be somewhat scary, specially if you using more than three or four of the applications listed: think about all the shortcuts you have to remember. Nightmare! Seriously, as humans, were we destined to have to remember hundreds of shortcuts? Isn&#8217;t there a better way to spend our time?</p>
<p>Now if you&#8217;re like me, a keyboard fanatic, you&#8217;ll probably say it is worthwhile, that it pays off in the long run, because the mouse, well it&#8217;s just not productive. In fact, the first thing I usually do when teaching a course on TDD or ReSharper is tell students to unplug the mouse. Why? Because the mouse just gets in the way. It makes you lose focus, it takes precious seconds away. Ultimately, the mouse breaks the flow.</p>
<p><a href="http://hhariri.files.wordpress.com/2012/04/d.jpg"><img class="alignnone size-full wp-image-2360" title="Mouse" src="http://hhariri.files.wordpress.com/2012/04/d.jpg?w=529&h=352" alt="" width="529" height="352" /></a></p>
<p>Software developers and UI designers realized this as the graphical interface flourished. That is why the concept of keyboard shortcuts where introduced, to try and avoid menu and submenu navigation galore, specially on repetitive operations.</p>
<h1>One size fits all fallacy</h1>
<p>Keyboard shortcuts, easy to implement on desktop applications, were initially not so popular on the web. However, lately, it&#8217;s hard to find a decent web application (except that lame excuse for what Twitter calls an HTML application, a.k.a. the new Tweetdeck client) that do not have keyboard shortcut support.</p>
<p>And in principle, this might seem good. The problem however is that we have not only taken it too far, but we also seem to be committing the same mistake over and over again: trying to standardize behavior over devices and contexts.</p>
<p>Whether it&#8217;s the laziness of us, as developers, or the ambitious business orientated approach of re-use, we keep trying to apply same the thing in different places. We&#8217;ve seen the mistakes in hardware, such as trying to shrink Windows down to fit on a cigarette box (Windows Mobile), or the more recent approach of Microsoft, which is thinking that the Metro experience will be as pleasant on a desktop devices as it will on a touch-screen ones.</p>
<p>We&#8217;ve also seen this approach with software: think about all the different apps you are using that have Desktop and Mobile versions, where they try and offer the same experience. Does it always work? Why do we do it?</p>
<p>Forgetting the lazy developer or supposedly high ROI aspect, we also have this preconception that if a user learns how to use one interface, it will be easier. It maybe true, but I&#8217;d argue that if a user interface is simple and intuitive enough to not require a steep learning curve, it usually does not pose a problem. A homogenous design is not required to make things easier. It just means you&#8217;re used to the same errors.</p>
<p>Moving beyond devices and interfaces, we have the added misconception that all applications require the same type of interaction. It seems the general rule is that every application requires some icons and some keyboard shortcuts. That way, mouse-friendly-non-technical-savvy-users can be at ease with their pointing devices, be it a mouse, trackball or finger, and the hardcore users can be expert keyboard ninjas.  But not every type of interaction for every application has to be the same.</p>
<h1>Commands: When shortcuts don&#8217;t make sense</h1>
<p>If you&#8217;re old enough to experience buying a ticket at a travel agency, you&#8217;ll no doubt remember the agent whamming away at the keyboard trying to find a flight for you. Much like Scott mentions in his post, the airline industry still is a very keyboard heavy user-base. You hardly see any pointing devices lying around terminals at an airport. Many of these systems used commands, much like commands from the DOS or bash console:</p>
<ul>
<li><strong>dir</strong> to list a directory</li>
<li><strong>mkdir</strong> to make a directory</li>
<li><strong>copy</strong> to copy a file</li>
</ul>
<p>It worked well back then and it still works well today. A comment I left on Scott&#8217;s blog in reference to YouTrack which was listed there, was that although YouTrack has keyboard shortcuts, the main beauty of it is not having to remember these, but the ability to use commands. You see in YouTrack when you want to close a bug, you don&#8217;t have to remember a keyboard combination, you just start typing:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/04/a.png"><img title="YouTrack1" src="http://hhariri.files.wordpress.com/2012/04/a.png?w=529" alt="" /></a></p>
<p>and as you type, YouTrack not only offers command completion, but also displays a list of recently applied commands. Once you type something coherent, it then tries to interpret your command:</p>
<p><a href="http://hhariri.files.wordpress.com/2012/04/b.png"><img title="YouTrack2" src="http://hhariri.files.wordpress.com/2012/04/b.png?w=529" alt="" /></a></p>
<p>It&#8217;s the same principle that was used in older systems, but brought up to date, to be less error-prone and more user-friendly. And of course, this works with any type of command, not only closing a bug.</p>
<h1>Think about the interactions</h1>
<p>A keyboard is not suitable for many scenarios. Imagine using a keyboard or using commands for drawing sketch diagrams or using AutoCad? We&#8217;ve been there, done that, and it wasn&#8217;t very nice. The ideal device for this type of interaction is a mouse or some other pointing device.</p>
<p>On the other hand, a keyboard is the perfect type of interaction for writing code, much like it is for writing a letter. Keyboard shortcuts are also great for these scenarios, where we do not want to lose focus.</p>
<p>Commands also have their place. When keyboards shortcuts are not viable, when focus is not about continous writing, yet we also do not want to be mouse-heavy, commands are a perfect fit.</p>
<p>What is important however to consider is that not all scenarios are equal. We seem to have somewhat learned this lesson by creating touch-specific applications, but we usually only take this into account when thinking about a device, more than thinking about the application. The actual purpose of the software is as important, in order to provide a productive and fluid user experience.</p>
<p>Even when the day comes where voice-controlled systems <a href="http://shitsirisays.com/">do improve</a>, it won&#8217;t mean we need to apply it always.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hhariri.wordpress.com/2352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hhariri.wordpress.com/2352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hhariri.wordpress.com/2352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hhariri.wordpress.com/2352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hhariri.wordpress.com/2352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hhariri.wordpress.com/2352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hhariri.wordpress.com/2352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hhariri.wordpress.com/2352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hhariri.wordpress.com/2352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hhariri.wordpress.com/2352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hhariri.wordpress.com/2352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hhariri.wordpress.com/2352/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2352&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/04/01/keyboard-shortcuts-arent-always-the-right-way/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/d.jpg" medium="image">
			<media:title type="html">Mouse</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/a.png" medium="image">
			<media:title type="html">YouTrack1</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/04/b.png" medium="image">
			<media:title type="html">YouTrack2</media:title>
		</media:content>
	</item>
		<item>
		<title>The Journey of Teaching</title>
		<link>http://hadihariri.com/2012/03/18/the-journey-of-teaching/</link>
		<comments>http://hadihariri.com/2012/03/18/the-journey-of-teaching/#comments</comments>
		<pubDate>Sun, 18 Mar 2012 10:45:05 +0000</pubDate>
		<dc:creator>hhariri</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://hadihariri.com/?p=2337</guid>
		<description><![CDATA[Teaching, in any form, is a voyage, during which you reach different milestones. One of the first ones, is accomplishing &#8230;<p><a href="http://hadihariri.com/2012/03/18/the-journey-of-teaching/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2337&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Teaching, in any form, is a voyage, during which you reach different milestones. One of the first ones, is accomplishing that level of knowledge in order to share what you have learned with certain confidence. From then on, it is about improving, learning, correcting. It is not always about the topic, but often about finding better ways to communicate, to improve techniques to explain topics that are often complex.</p>
<p>One of the great joys of teaching, be it a class or giving a talk is this self-learning experience. Explaining something to someone else really helps in grasping that missing link you had; that uncertainty you weren&#8217;t sure about the first time you gave that talk. The &#8220;Ah, now I understand&#8221; moment you silently think to yourself while standing in front of your audience is very gratifying. This experience can be accomplished in many ways, such as authoring a book, writing an in-depth article or a blog post.</p>
<p>Although you learn as you teach, it doesn’t mean however that you can stand in front of an audience, and give a talk on a subject you&#8217;re not too familiar with, hoping to pick things up as you go along. You need to obtain that certain level of knowledge, reach that first milestone. It is a responsibility you owe not only to yourself, but also to your audience, to provide them with correct and ample information. A somewhat common joking remark is: &#8220;just make sure that you know more than everyone in the room&#8221;. Although amusing, it is a great incentive to push the limits, as it&#8217;s very hard to predicate whom your audience is, and what their background holds.</p>
<p>But it is important to understand that it is always a journey in which you teach but also learn. We are not born experts, whatever that term might mean.</p>
<h3>With success comes responsibility</h3>
<p>As we teach, we improve. As we improve we accomplish goals. These goals can be the respect of our audiences, the respect of our peers. We can start being labeled as experts around certain areas. This is encouraging and can lead to greater things. Being complimented on something we are passionate about, knowing we are succeeding is a great accomplishment, something we should be proud of. As we progress, we start to reach larger audiences. We start to embark on new areas, topics and interests.</p>
<p>Our prior success allows us and motivates us to embark on these new ventures. We have a faithful following. Our past experience shows that we are mostly correct in our teachings and this promotes more respect from our audiences. Our opinions are now taken as authoritative.</p>
<p>As this happens, we often lose sight of a fundamental thing that has made us reach this milestone in our journey: pushing ourselves in understanding things. Researching before teaching. Making sure we comprehend before explaining to others.</p>
<p>This is damaging. In the long run, it will lead to our own demise. The same respect we gained, we lose. But in the short time, and more importantly, we can deceive our audience. We can lead people the wrong way without us fully knowing what the right way is.</p>
<p>We now have a great responsibility and we need to act appropriately. Our status shouldn’t give us permission to take shortcuts, to skip milestones in our journey. We got here by building up the respect on our own merits. If we care about our audience, we should respect them back.</p>
<h3>Skipping that first milestone openly</h3>
<p>Not always do we have the chance or the desire to reach that first milestone before sharing our knowledge. Diverse reasons can warrant us to take a different approach when embarking on the journey of teaching. We can learn in the open. We can write about things and share that knowledge as we do our own investigation.</p>
<p>We should learn by asking questions. We should challenge what we learn, but do so with a proper understanding of what we are challenging. We should debate. We should be open to being proven wrong and most importantly we should learn to listen to others, much the same way we listen to our own voice, that same voice the improves our own understanding.</p>
<p>Arrogance won&#8217;t lead us to success, but it can lead us to failure.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2337/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2337/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hhariri.wordpress.com/2337/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hhariri.wordpress.com/2337/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hhariri.wordpress.com/2337/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hhariri.wordpress.com/2337/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hhariri.wordpress.com/2337/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hhariri.wordpress.com/2337/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hhariri.wordpress.com/2337/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hhariri.wordpress.com/2337/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hhariri.wordpress.com/2337/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hhariri.wordpress.com/2337/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hhariri.wordpress.com/2337/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hhariri.wordpress.com/2337/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2337&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/03/18/the-journey-of-teaching/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>
	</item>
		<item>
		<title>The Kotlin Journey Part II: A premier on classes</title>
		<link>http://hadihariri.com/2012/03/10/the-kotlin-journey-part-ii-a-premier-on-classes/</link>
		<comments>http://hadihariri.com/2012/03/10/the-kotlin-journey-part-ii-a-premier-on-classes/#comments</comments>
		<pubDate>Sat, 10 Mar 2012 22:25:41 +0000</pubDate>
		<dc:creator>hhariri</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JetBrains]]></category>
		<category><![CDATA[Kotlin]]></category>

		<guid isPermaLink="false">https://hhariri.wordpress.com/?p=2314</guid>
		<description><![CDATA[This is a multi-part series on Kotlin, a new statically typed language from JetBrains targeting the JVM and JavaScript Part &#8230;<p><a href="http://hadihariri.com/2012/03/10/the-kotlin-journey-part-ii-a-premier-on-classes/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2314&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a multi-part series on Kotlin, a new statically typed language from JetBrains targeting the JVM and JavaScript</p>
<p><a href="http://hadihariri.com/2012/02/17/the-kotlin-journey-part-i-getting-things-set-up/">Part I: Getting things set up</a><br />
<a href="http://hadihariri.com/2012/02/17/the-kotlin-journey-part-ii-a-premier-on-classes/">Part II: A premier on classes</a></p>
<h2>A small but important note</h2>
<p>Kotlin is still work in progress and not all design decisions are final. That is why your feedback is fundamental. So please provide any feedback via this blog, via our <a href="http://devnet.jetbrains.com/community/kotlin;jsessionid=56D23D3BF26C11C798EE753D17D2844D?view=discussions">forums</a>, via <a href="http://twitter.com/project_kotlin">twitter</a> on what you like, what you dislike.</p>
<h3>Declaring variables</h3>
<p>Before diving into classes, let&#8217;s first see how we can declare variables in Kotlin, as we&#8217;ll eventually need to do so when creating an instance of our class.<br />
In Kotlin, variables can be declared in one of two ways, using the <em>var</em> or <em>val</em> keyword:</p>
<ul>
<ul>
<li><em>var</em> declares a variable that is mutable, that is, the value can change after it has been assigned</li>
</ul>
</ul>
<p><img src="http://hhariri.files.wordpress.com/2012/03/201203101930.jpg?w=241&h=71" alt="201203101930.jpg" width="241" height="71" /></p>
<ul>
<ul>
<li><em>val</em> declares a variable that is immutable, that is, once assigned the value cannot change</li>
</ul>
</ul>
<p><img src="http://hhariri.files.wordpress.com/2012/03/201203101929.jpg?w=207&h=82" alt="201203101929.jpg" width="207" height="82" /></p>
<p>Notice that we have not declared the type. Much like the <em>var</em> keyword in C#, since the variable has been initialized, the compiler can infer the type. However, if we do not initialize the variable, we need to explicitly define the type:</p>
<p><img src="http://hhariri.files.wordpress.com/2012/03/201203101935.jpg?w=166&h=50" alt="201203101935.jpg" width="166" height="50" /></p>
<p>What happens however when we declare an immutable type that has not been initialized?</p>
<p><img src="http://hhariri.files.wordpress.com/2012/03/201203101936.jpg?w=288&h=131" alt="201203101936.jpg" width="288" height="131" /></p>
<p>As expected, the compiler will allow us to set the value, but not change it. So all is good.</p>
<p>Knowing now the difference between <em>val</em> and <em>var</em>, let&#8217;s move on and look at classes.</p>
<h3>Classes</h3>
<p>Classes are the main building blocks for many object-orientated programming languages, and as such, of Kotlin also. An empty class declaration looks pretty much like that in C# and Java</p>
<p><img src="http://hhariri.files.wordpress.com/2012/03/201203101845.jpg?w=217&h=85" alt="201203101845.jpg" width="217" height="85" /></p>
<p>(If you&#8217;re using IntelliJ, you will see items highlighted in the gutter with an icon and letter. In this case C represents Class)</p>
<p>Classes can be <em>public</em>, <em>private</em>, <em>protected</em> or <em>internal</em>. <strong>By default they are <em>internal</em> to modules</strong> (we&#8217;ll cover what modules and accessibility levels are later). This has the initial apparent disadvantage that you would not be able to test your code from outside a module. The team is currently working on a solution for this which would involve building modules in a specific way that would allow test projects to call internal classes. The approach however will not be the same as in C# where the attribute <em>internalsVisibleTo</em> is required.<br />
To use a class, we merely create an instance of it. <em>new</em> keyword does not exist in Kotlin. A constructor call is similar to a function call.</p>
<p><img src="http://hhariri.files.wordpress.com/2012/03/201203101957.jpg?w=223&h=41" alt="201203101957.jpg" width="223" height="41" /></p>
<p>Note that this customer has a default constructor that takes no parameters, which in Kotlin is a known as the <em>primary</em> constructor. We can override this primary constructor by defining a constructor as part of the class definition</p>
<p><img src="http://hhariri.files.wordpress.com/2012/03/201203102138.jpg?w=434&h=196" alt="201203102138.jpg" width="434" height="196" /></p>
<p>with the actual implementation contained inside the anonymous initializer. This anonymous initializer is actually only necessary when we need certain logic. If we are merely using the constructor to initialize properties, we do not need it.</p>
<p>Now that we know how to create a class and define constructors, let&#8217;s add some contents to the class.</p>
<h4>Properties</h4>
<p>Usually classes in C# and Java are composed of fields, properties, methods and nested classes. In Kotlin, classes can contain properties, methods, nested classes and object declarations. We&#8217;ll cover this last one further along in the series. However, the key thing here to notice is that <strong>Kotlin does not allow fields</strong>. As such, everything is a property. It can be internal (default), private, protected or public.</p>
<p><img src="http://hhariri.files.wordpress.com/2012/03/201203102223.jpg?w=311&h=152" alt="201203102223.jpg" width="311" height="152" /></p>
<p>Here we have one internal property and two public ones. Notice how the internal one does not have an explicit type declaration. It is not needed. However, if we were to remove the type declaration for one of the public properties, we&#8217;d get a compiler error</p>
<p><img src="http://hhariri.files.wordpress.com/2012/03/201203102228.jpg?w=356&h=151" alt="201203102228.jpg" width="356" height="151" /></p>
<p>The reason for this is to prevent unintentional breakage of a public API, since it&#8217;s much more likely to change the type of a property without realizing the impact it might have if it&#8217;s not explicit. Another thing to notice is that all properties require explicit initialization, irrelevant of their accessibility or whether they are mutable (<em>var</em>) or immutable (<em>val</em>).</p>
<h4>Was that an AutoProperty?</h4>
<p>If you&#8217;re a C# developer you&#8217;re no doubt familiar with the autoproperties, whereby the compiler internally has a backing field holding the value of a property, without requiring you to define explicit getters and setters unless you want to define explicit behavior. Kotlin is pretty much the same in that way and what we just saw uses an internal backing field which is called the same as the property but prefixed with the character $</p>
<h4>Custom Getters and Setters</h4>
<p>What happens when we want to provide custom behavior when reading or writing to properties? In these cases we can define getters and setters</p>
<p><img src="http://hhariri.files.wordpress.com/2012/03/201203102253.jpg?w=307&h=71" alt="201203102253.jpg" width="307" height="71" /></p>
<p>This is an example of a customer getter which always returns &#8220;Always Jack&#8221; as the value of the property <em>Name</em> irrelevant of what value it has. Notice how we just define it below the property. If our getter requires more than one line, we can use a { } block.<br />
Much like the getter, we can also define a setter. In this setter, we can write any logic that interacts with other properties of the class. But what happens when we want to interact with the actual backing field of this property (the one that the compiler creates automatically)? as mentioned before, we can use the $ prefix to access it</p>
<p><img src="http://hhariri.files.wordpress.com/2012/03/201203102300.jpg?w=281&h=109" alt="201203102300.jpg" width="281" height="109" /></p>
<p>Setters can have different accessibility levels, by prefixing them with the corresponding keyword.</p>
<h3>Functions</h3>
<p>Although we won&#8217;t dive too deeply into all the different aspects of functions in this part (otherwise it would be too long of a blog post), we will see the basics to create functions as part of our classes. A function declaration, in its simplest form is:</p>
<p><img src="http://hhariri.files.wordpress.com/2012/03/201203102307.jpg?w=288&h=82" alt="201203102307.jpg" width="288" height="82" /></p>
<p>consisting of the function <em>name,</em> optional <em>parameters,</em> optional <em>return type</em> and the <em>body.</em> Functions in Kotlin return tuples, that is they can return more than one value. When we do not specify a return type, we are implicitly saying that the return type is a <em>Unit</em> which is a tuple with 0 components.<br />
Below is a full example of a class that takes two parameters in the constructor, initializes some properties and contains a function the prints out the full name.<br />
<img src="http://hhariri.files.wordpress.com/2012/03/201203102316.png?w=452&h=180" alt="201203102316.jpg" width="452" height="180" /></p>
<p>We&#8217;ll dive deeper into functions and all the possibilities they offer in a different post.</p>
<h3>Summary</h3>
<p>In this second part, we&#8217;ve covered the basics of classes, how to declare one, how constructors work and how to define properties and functions. Classes in Kotlin however offer much more and there&#8217;s a lot more to learn about them. In other parts we&#8217;ll cover the difference between open and final classes (hint: default is final), abstract classes, inheritance, as well as traits, which are somewhat similar to interfaces in C#.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hhariri.wordpress.com/2314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hhariri.wordpress.com/2314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hhariri.wordpress.com/2314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hhariri.wordpress.com/2314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hhariri.wordpress.com/2314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hhariri.wordpress.com/2314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hhariri.wordpress.com/2314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hhariri.wordpress.com/2314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hhariri.wordpress.com/2314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hhariri.wordpress.com/2314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hhariri.wordpress.com/2314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hhariri.wordpress.com/2314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hhariri.wordpress.com/2314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hhariri.wordpress.com/2314/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hadihariri.com&#038;blog=11677451&#038;post=2314&#038;subd=hhariri&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hadihariri.com/2012/03/10/the-kotlin-journey-part-ii-a-premier-on-classes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2072a8f90f9fe379ca21c3af39a3757?s=96&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
			<media:title type="html">hhariri</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203101930.jpg" medium="image">
			<media:title type="html">201203101930.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203101929.jpg" medium="image">
			<media:title type="html">201203101929.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203101935.jpg" medium="image">
			<media:title type="html">201203101935.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203101936.jpg" medium="image">
			<media:title type="html">201203101936.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203101845.jpg" medium="image">
			<media:title type="html">201203101845.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203101957.jpg" medium="image">
			<media:title type="html">201203101957.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203102138.jpg" medium="image">
			<media:title type="html">201203102138.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203102223.jpg" medium="image">
			<media:title type="html">201203102223.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203102228.jpg" medium="image">
			<media:title type="html">201203102228.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203102253.jpg" medium="image">
			<media:title type="html">201203102253.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203102300.jpg" medium="image">
			<media:title type="html">201203102300.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203102307.jpg" medium="image">
			<media:title type="html">201203102307.jpg</media:title>
		</media:content>

		<media:content url="http://hhariri.files.wordpress.com/2012/03/201203102316.png" medium="image">
			<media:title type="html">201203102316.jpg</media:title>
		</media:content>
	</item>
	</channel>
</rss>

