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

<channel>
	<title>Elegant Code &#187; Architecture</title>
	<atom:link href="http://elegantcode.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quinine For Sale</title>
		<link>http://elegantcode.com/2012/01/18/monitoring-an-mmo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-an-mmo</link>
		<comments>http://elegantcode.com/2012/01/18/monitoring-an-mmo/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:45:32 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MMO]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2012/01/18/monitoring-an-mmo/</guid>
		<description><![CDATA[I’ve been working on a free-to-play MMO Quinine For Sale, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I’ve been working on a free-to-play <a href="http://www.heroup.com" target="_blank">MMO</a> <b>Quinine For Sale</b>, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before they become serious and fixing problems when they inevitably do.&#160; So, there are two questions.&#160; “Is there a problem in the game?” “What is causing the problem?”&#160; </p>  <p>When trying to debug something on our development and test clusters, typically you can tail log files.&#160; We have a python script that can monitor the communication between various parts of the game and pretty-print it along with color to highlight “this is a problem!”&#160; Attaching a debugger to a running process is also not uncommon.&#160; However, looking at logs and bus traffic in realtime on a production environment gives you this neat “Matrix-y” experience.&#160; Attaching a debugger to a production process (assuming you could, which you can’t) would get you smacked with a rolled-up newspaper.&#160; “Bad Developer!&#160; No treat!”&#160; So, what can you do?</p>  <h4>Monitoring</h4>  <p>When you’ve got clusters full of machines, using <a href="http://www.nagios.org/" target="_blank">Nagios</a> to monitor things is an obvious solution.&#160; Beyond making sure the power is on and other sysadmin things, we’ve written other checks to see if the login process is working, the parts are working together, and automating typical in-game functions.&#160; For example, if nagios can’t successfully log into the game do basic game activity, then alerts happen.</p>  <h4>Metrics for EVERYTHING</h4>  <p>Anything that happens in game has metrics reporting tied to it, generating piles of data constantly.&#160; We use <a href="http://www.cacti.net/" target="_blank">Cacti</a> to visualize game activity.&#160; An example metric is concurrent users, or CCU.&#160; We graph how many people are in the game over time, which when things are healthy should be a nice smooth curve climbing to peak game hours, then descending nicely through the night.</p>  <p>We can tell by sight if the game looks healthy or not – if the CCU graph is jaggy, has a sudden drop or spike, or drops to zero then we know that something is wrong.&#160; Typically nagios alerts accompany the graphs, giving more data points on where to look.&#160; But this has also pointed out areas where a nagios check was missing or wasn’t working as intended.</p>  <h4>Log Files</h4>  <p>When a player gets an error in game, the error dialog box gives them the opportunity to submit the error details back to us.&#160; If we see a spike in user-reported errors through this or other customer service means, we know we have something of interest to look for.&#160; </p>  <p>The game server components make use of log4j and similar logging frameworks.&#160; Anything that you’d want to watch happening in game needs to be aggressively logged.&#160; All components are configured so that operations can change the log level on the fly.&#160; That’s still quite a bit of data across many machines though, so all that information is run through <a href="http://www.splunk.com/product" target="_blank">Splunk</a> to be indexed and searchable.&#160; This gives us a great tool for searching through log data, examining trends, or watching selected activity in real time.&#160; Unfortunately it is very expensive so we are selective about the data that passes through it.&#160; </p>.  Buy Quinine from mexico.  Buy Quinine no prescription.  No prescription Quinine online.  Online buying Quinine.  Quinine no prescription.  Quinine street price.  Buy no prescription Quinine online.  Quinine coupon.  Quinine over the counter.  Where can i buy Quinine online.  Quinine steet value.  Where to buy Quinine.  Order Quinine online overnight delivery no prescription.  Quinine recreational.  Quinine canada, mexico, india.  Ordering Quinine online.  Quinine without prescription.  Quinine price, coupon.  Quinine description.  Order Quinine from mexican pharmacy.  Quinine pics.  What is Quinine.  Japan, craiglist, ebay, overseas, paypal.  Order Quinine from United States pharmacy.  Order Quinine online c.o.d.  Quinine trusted pharmacy reviews.  Quinine treatment.  Buy Quinine from canada.  Quinine used for.  Discount Quinine.  Is Quinine addictive.  Quinine forum.  Buy Quinine online no prescription.  Is Quinine safe.  Purchase Quinine for sale.  Effects of Quinine.  Buy Quinine online cod.  Quinine australia, uk, us, usa.  Buy Quinine without prescription.  Quinine online cod.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4721'>Buy Flonase Without Prescription</a>. <a href='http://elegantcode.com/?p=4234'>Buy Periactin Without Prescription</a>. <a href='http://elegantcode.com/?p=4203'>Buy Armour Without Prescription</a>. <a href='http://elegantcode.com/?p=4899'>Buy Macrobid Without Prescription</a>. <a href='http://elegantcode.com/?p=4534'>Xalatan For Sale</a>. <a href='http://elegantcode.com/?p=4302'>Phenergan wiki</a>. <a href='http://elegantcode.com/?p=4268'>Soma maximum dosage</a>. <a href='http://elegantcode.com/?p=4602'>Zovirax treatment</a>. <a href='http://elegantcode.com/?p=4578'>Cialis price, coupon</a>. <a href='http://elegantcode.com/?p=4189'>Flexeril price</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.leaduganda.org/?p=514'>Quinine For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=4820'>Quinine For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2780'>Quinine For Sale</a>. <a href='http://www.thegriffonnews.com/?p=10177'>Quinine For Sale</a>. <a href='http://www.independentworldreport.com/?p=2409'>Quinine For Sale</a>. <a href='http://changecamp.ca/?p=295'>Quinine description</a>. <a href='http://social-blend.com/?p=624'>Quinine price, coupon</a>. <a href='http://blog.farmland.org/?p=3946'>Online buying Quinine hcl</a>. <a href='http://4realz.net/?p=1595'>Quinine from canada</a>. <a href='http://reversemortgagedaily.com/?p=14535'>Where to buy Quinine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2012/01/18/monitoring-an-mmo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temovate Cream For Sale</title>
		<link>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-software-development-will-never-be-engineering</link>
		<comments>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 03:37:48 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/</guid>
		<description><![CDATA[I always find it rather interesting when academics try to quantify generalized metrics about software development. Temovate Cream For Sale, Things like: per lines of code, there will be X number of bugs. Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.” These are all interesting [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I always find it rather interesting when academics try to quantify generalized metrics about software development.</p>  <p> <b>Temovate Cream For Sale</b>, Things like: per lines of code, there will be X number of bugs.</p>  <p>Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.”</p>  <p>These are all interesting thoughts, but software development will never conform to rigid engineering principles like many other engineering practices.&#160; The longer I work in the field, the more and more I realize that software development has nothing to do with engineering.&#160; We just happen to attend some of the same math classes in school.</p>  <h2>Building bridges</h2>  <p>One of the main arguments I hear people make about the current state of software development as an engineering practice is based around its relative maturity to other engineering fields.</p>  <p>There is a huge problem with this line of thinking.</p>  <p>The argument goes something like this:&#160; “<em>Engineering has been around for hundreds of years and has matured to the point where it is a measurable science, but software development has only been around in earnest for the last few decades or so, therefore it is relatively immature as an engineering discipline.”</em></p>  <p>On the surface this argument seems sounds.&#160; And certainly in 50 years software development will be different than it is now.&#160; Heck, it is much more different than it was just 10 years ago.</p>  <p>But, here is the problem.&#160; We build much more software than we do bridges.</p>  <p><img src="http://www.nps.gov/glca/historyculture/images/Navajo_Bridges_1.gif" width="589" height="442" /></p>  <h6 align="center">&#160;</h6>  <p>Let me give you an example that came to light in another area of my interest… poker.</p>  <h1></h1>  <h2>The poker quickening</h2>  <p>An interesting thing happened in the poker community in the last 10 years; poker pros with decades of experience started getting beat time and time again by 19 year old poker prodigies.</p>  <p>From an outside perspective it looks like the poker world opening up just widened the search for talent and there it was.&#160; But, a closer examination of the evidence leads to the truth.</p>  <p>Before the online poker industry was born, poker was played in card rooms and casinos in states where it was legal and occasionally at small home games throughout the US.</p>  <p>A poker pro might play poker tournaments perhaps 100 times to 150 times a year.&#160; The sum knowledge of the poker community and the meta game around it was based on this base of professional poker players playing tournaments and gaining experience at this mediocre rate.</p>  <p>Once the internet poker rooms started opening up, things changed, and they changed rapidly.&#160; Now anyone could play poker from their home PC.&#160; Not only could they play poker, they could play poker tournaments at all hours of the day.</p>  <p>Here is a list of some of the major changes that took place:</p>  <ul>   <li>Hands are dealt at 60-80 hands per hour instead of 10-30</li>    <li>Players can play in many tournaments at one time, 10 tournaments at once is not unheard of</li>    <li>Players can analyze hand histories and historical data about their play and opponents play through the use of software </li>    <li>Age requirements are out the window, technically any one of any age could be playing online</li>    <li>Players can play 24 hours a day</li>    <li>The professional online tournament player could easily play over 3000 tournaments in a year, while a brick and mortar pro would be lucky to reach 100 in a year.</li>   <img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://t1.gstatic.com/images?q=tbn:ANd9GcRj9uGNWSyqGWEneiH6xaBAyS6COwGYicdNadZu-06KWQLhIi6LMw&amp;t=1" width="316" height="270" /></ul>  <p>&#160;</p>  <p>So where am I going with all this?</p>  <p>The point is that as a whole more hands were dealt and more poker knowledge and experience was obtained in 1 year of online poker than probably the entire history of poker before that.&#160; We reached such an accelerated pace of play that all previous knowledge of poker became obsolete.&#160; </p>  <p>The strategy of tournament poker completely changed.&#160; The game evolved perhaps 500 years into the future in a matter of 5 years time.</p>  <p>The same has happened with software development.</p>  <h2>Back to the bridge building</h2>  <p>So let’s take that poker example and look at it through the lens of software development.</p>  <p>Let us compare the engineering maturity to software development to the engineering maturity of the engineering discipline of building bridges.</p>  <p>I think most people would agree that bridge building is a very mature engineering discipline but many people would argue that software development is not.</p>  <p><strong>How many bridges do you think have been built in the world?</strong></p>  <p>Well there are <a href="http://www.betterroads.com/category/bridge-inventory/erroads.randallreillycms.com/files/2009/11/BR1109_BridgeInventory.pdf">about 600,000 bridges in the United States alone</a>, so the world figure must be at least somewhere around 10 times that number perhaps 20.</p>  <p><strong>How many software programs have been written?</strong></p>  <p>This is a very hard number to estimate, but lets take a rough guess based on <a href="http://stackoverflow.com/questions/453880/how-many-developers-are-there-in-the-world">how many software developers there are in the world</a>.&#160; </p>  <p>If we say there are about 12 million software developers and each software developer has written approximately 3 programs, we can estimate that a large amount more programs have been written than bridges built.</p>  <p>My point is not to knock bridge building, we are pretty good at it as a whole, but rather to show that collectively, even though we have been building bridges for hundreds of years, we have probably devoted an equivalent amount of time to building software.</p>  <p>This line of thinking may lead you to argue back that software development and bridge building are very different.&#160; Bridge building has a fixed set of requirements that are pretty close to the the same for each bridge you build, but software development is a big open void of whims and ambiguously contradictory statements.</p>  <p>I agree with you 100%!&#160; And in essence that is my point.</p>  <h2>Software development is different</h2>  <p>And we have had enough time to realize that.&#160; Waiting for software development to gel into some kind of engineering discipline like other engineering disciplines is like waiting for water without gelatin mix to turn into Jello.&#160; </p>  <p>It’s just not going to happen!</p>  <p>In my mind it is clear that the argument that we haven’t given it enough time is just wishful thinking.&#160; The nature of software development, just like online poker, leads itself to rapid evolution.</p>  <p>Consider what direction software development is evolving.&#160; Is it even evolving in the direction of rigid engineering practices or is it evolving in the exact OPPOSITE direction?</p>  <p>Ten years ago, we tried to use UML diagrams and CASE tools to develop software.&#160; Ten years ago waterfall was all the rage.&#160; Ten years ago, we thought that ten years in the future we would have programs that would allow us to build software in the same way that CAD tools allow for building machine parts.</p>  <p>Not only did it not happen.&#160; It went completely the other way.&#160; Now we are all talking about Agile.&#160; Now people don’t even remember what CASE tools are.&#160; Now we are building software without trying to define the whole system in UML diagrams.</p>  <p><strong>The fact of the matter is software systems are unruly beasts!</strong></p>  <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://aznbadger.files.wordpress.com/2010/06/beast.jpg" /></p>  <p>In my mind it comes down to one simple distinction.&#160; Software is living, bridges aren’t.&#160; When you are done building a bridge, you are done building the bridge.&#160; </p>  <p>Sure someone, probably not you, will have to come along and do some routine maintenance on it.&#160; Sure, some small things might change about it, but for all intents and purposes the work is done.</p>  <p>In most software development scenarios, this is not the case.&#160; In most software development scenarios, releasing V1 is not even close to the end.&#160; Sometimes V1 and V2 don’t even look that same at all.&#160; Software development is about operating on a living breathing thing and all the while keeping it alive.</p>  <p>The truth is, we software developers have more in common with surgeons than with other engineers.</p>  <h6>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com/">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>.  Buy Temovate Cream without a prescription.  Temovate Cream trusted pharmacy reviews.  Temovate Cream over the counter.  Where can i order Temovate Cream without prescription.  Online buy Temovate Cream without a prescription.  Temovate Cream no rx.  Buy cheap Temovate Cream no rx.  Temovate Cream photos.  Buy Temovate Cream online no prescription.  Order Temovate Cream online c.o.d.  Herbal Temovate Cream.  About Temovate Cream.  Australia, uk, us, usa.  Cheap Temovate Cream.  Temovate Cream class.  Temovate Cream brand name.  Online Temovate Cream without a prescription.  Buy Temovate Cream without prescription.  Buy Temovate Cream from canada.  After Temovate Cream.  Order Temovate Cream from mexican pharmacy.  Temovate Cream without a prescription.  Purchase Temovate Cream.  Temovate Cream natural.  Temovate Cream overnight.  Temovate Cream online cod.  Where can i buy cheapest Temovate Cream online.  Purchase Temovate Cream for sale.  Online buying Temovate Cream.  Purchase Temovate Cream online.  Temovate Cream used for.  Temovate Cream coupon.  Temovate Cream description.  Order Temovate Cream no prescription.  Temovate Cream maximum dosage.  Cheap Temovate Cream no rx.  Temovate Cream images.  Temovate Cream blogs.  Buy Temovate Cream online cod.  Buy generic Temovate Cream.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4472'>Bactroban For Sale</a>. <a href='http://elegantcode.com/?p=4632'>Armour For Sale</a>. <a href='http://elegantcode.com/?p=4639'>Buy Estrace Vaginal Cream Without Prescription</a>. <a href='http://elegantcode.com/?p=4668'>Buy Augmentin Without Prescription</a>. <a href='http://elegantcode.com/?p=4535'>Buy Tindamax Without Prescription</a>. <a href='http://elegantcode.com/?p=4931'>Fast shipping Diclofenac</a>. <a href='http://elegantcode.com/?p=4240'>Combivent brand name</a>. <a href='http://elegantcode.com/?p=4417'>Levaquin overnight</a>. <a href='http://elegantcode.com/?p=4597'>Purchase Toradol online</a>. <a href='http://elegantcode.com/?p=4221'>Australia, uk, us, usa</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.quarterlives.com/?p=1148'>Temovate Cream For Sale</a>. <a href='http://4realz.net/?p=1972'>Temovate Cream For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=5997'>Temovate Cream For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2476'>Temovate Cream For Sale</a>. <a href='http://www.thegriffonnews.com/?p=9947'>Temovate Cream For Sale</a>. <a href='http://social-blend.com/?p=1160'>Temovate Cream brand name</a>. <a href='http://blog.farmland.org/?p=3812'>Where can i find Temovate Cream online</a>. <a href='http://reversemortgagedaily.com/?p=14136'>Generic Temovate Cream</a>. <a href='http://linuxologist.com/?p=1792'>Temovate Cream photos</a>. <a href='http://home.officesnapshots.com/?p=114'>Order Temovate Cream from mexican pharmacy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
		<item>
		<title>Christmas Light Architectures Are Not That Shiny</title>
		<link>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=christmas-light-architectures-are-not-that-shiny</link>
		<comments>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:00:00 +0000</pubDate>
		<dc:creator>Jan Van Ryswyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/</guid>
		<description><![CDATA[I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way [...]]]></description>
			<content:encoded><![CDATA[<p>I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way overdue :-).</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb1.png" width="202" height="172" /></a> </p>  <p><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a>What's the major malfunction with those old, classic Christmas lights? We've all experienced it at some point. When one goes out, all the others go out as well. This is due to the fact that these lights are wired in series. The difference compared with today's Christmas lights is that every bulb has a shunt, which basically prevents this kind of failure caused by one or more lamps. Enough about the Christmas lights for now. Where am I going with this? Back in enterprise IT, I'm seeing the same kind of failures as with those classic, old Christmas lights.</p>  <p>The diagram below shows a classic RPC style architecture, much like those classic, old Christmas lights. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb2.png" width="565" height="329" /></a> </p>  <p>This is all fine and dandy as long as every part of the chain runs without too much hassle. But what happens if for some reason the centralized back-end web service goes down (light bulb goes out). This means that every smart client, website and batch application that uses this web service gets affected by this, like some sort of chain reaction. Parts of these client applications will no longer function correctly or they might even go down entirely. Same thing happens when the database of the centralized back-end web service goes down or any other external system that it depends on. When being confronted with this kind of architecture, how would one go about preventing this doomsday scenario to happen?</p>  <p>Suppose you’re a developer that has to work on the centralized back-end web service. This is usually a complex system as it obviously has to provide features for all kinds of applications. When this centralized back-end web service also has to deal with and depend on other external systems that might expose some unexpected behavior, how could one prevent the sky from falling down when things go awry in production?</p>  <p>Well for starters, you could start building in some stabilization points. Suppose for some reason, the centralized web service needs to incorporate some functionality offered by a highly expensive, super enterprise system that for some reason behaves very unstable and unpredictably on every full moon (expensive enterprise software not behaving correctly sounds ridiculous, but bare with me ;-) ). For example, we could use a message queue as a stabilization point. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb3.png" width="570" height="157" /></a> </p>  <p>This means that we put a message on a queue that is processed by some sort of worker process or service that does the actual communication with the misbehaving system. When the external system goes down, the message is either left on the message queue or put on an error queue for later processing when the external system comes back up again. There are some other things you need to think about like idempotent messaging, consistency, message persistence when the server goes down, etc. … . But if one of these dependencies goes down, the centralized back-end web service is still up-and-running which means that the systems that depend on its functionality can also continue to serve their users as they are able to keep doing their work.</p>  <p>Earlier this week I overheard this conversation that somewhat amazed me. I changed the names of the persons involved as well as the exact words used in order to protect the guilty.</p>  <blockquote>   <p><em>George: </em><em>We want to incorporate a message queue in order to guarantee stability and&#160; integrity between several non-transactional systems that our system depends on. It will also improve performance as these systems behave very slow at times and become unstable under pressure. This also gives us the opportunity to root out some major points friction that our end-users are experiencing right now.</em></p>    <p><em>Stan: But this means that the end-users are not completely sure if their actions are indeed fully carried out by the system. </em></p>    <p><em>George: End-users can always check the current state of affairs in their applications. If something goes wrong, their request is not lost and things will get fixed automatically later on as soon as the cause of the error has been fixed. </em></p>    <p><em>Stan:&#160; I don’t think that’s a very good idea. End-users have to wait until everything is processed synchronously, even if that means that they’ll need to wait for a long time. And if one of the external systems goes down, they should stop sending in new requests. Everything should come to a halt. They just have to stop doing what they are doing.</em></p>    <p><em>George: This means that because you lose the original request, some external systems might be set up correctly while others are not. Then someone has to manually fix these issues.</em></p>    <p><em>Stan: Then so be it!</em>&#160;</p> </blockquote>  <p>For starters, I was shocked by this conversation. This is just insane. Everything should come to a halt? Think about this scenario for a while: suppose you’re finding yourself in a grocery store with a cart full of food, drinks and other stuff. You come at the cash register where the lady kindly says “Can you put everything back on the shelves please? There are some issues with the cash register software and we are instructed to stop scanning items and serve customers until these issues are fixed. Can you come back tomorrow please?”. Uhm, no! How much money do you think this is going to cost compared to the system that makes use of stabilization points? An end-user that is able to keep doing its work, whether the entire production system is down or not has tremendous business value. </p>  <p>I’m not saying that message queues are a silver bullet. I’m just using these as an example. As always, there is a time and place for using them. There are other things a developer can incorporate in order to increase the stability of the system he’s working on, like <a href="http://davybrion.com/blog/2008/05/the-circuit-breaker/" target="_blank">the circuit breaker pattern</a>. I’m also not saying that every system should be built using every stabilization point one can think of. This become a business decision depending on the kind of solution. As usual, it depends.</p>  <p>But the point that I’m trying to make here is that we should stop putting software systems into production and just hoping for the best. That’s just wishful thinking. Software systems are going to behave badly and at some point they will go down. It’s just a matter of when this is going to happen and how much damage this is going to make.</p>  <p>The first step to take is awareness. I encourage you to pick up this book titled ‘<a href="http://www.amazon.com/exec/obidos/ASIN/0978739213/elegantcode-20" target="_blank">Release It!</a>’, written by <a href="http://www.michaelnygard.com/" target="_blank">Michael Nygard</a>. This book is all about designing software that can survive this though environment called production. I can only hope that Stan picks up a copy as well along with some common sense.</p>  <p>Till next time.&#160;&#160;&#160; </p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Could sealing a class be a sign of a good design</title>
		<link>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=could-sealing-a-class-be-a-sign-of-a-good-design</link>
		<comments>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:50:15 +0000</pubDate>
		<dc:creator>Andreas Håkansson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/</guid>
		<description><![CDATA[I recently attended this years Øredev conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, Philip Laureano. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended this years <a title="Read more about the Øredev conference" href="http://oredev.com/2010" target="_blank">Øredev</a> conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, <a title="Visit the twitter profile of Philip Laureano" href="http://twitter.com/philiplaureano" target="_blank">Philip Laureano</a>. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do not know the full details of his exact opinions). Anyway, the short version is that the person suggested that classes should be sealed by default, or at least have the developer explicitly state if the class should be sealed or closed.</p>  <p>My immediate reaction was that this was a terrible idea and that I had been struck down too many times by sealed classes before. But then I started thinking that maybe it was not such a bad idea after all. Maybe it even was a sign of a well designed class and that more developers would be better of by sealing their classes.</p>  <p>Now let me inform you that I am still on the ropes about this, but I would like your thoughts on it. In fact I am hoping that the most interesting part of this post will end up being the discussion in the comment section.</p>  <p>So when you take a moment to think about the <em>S.O.L.I.D principles</em>, most specifically the <em>Open-Closed Principle</em> and <em>Dependency Inversion Principle</em>, a long with the old design principle of ‘Favor <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> over <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)">class inheritance</a>’ then maybe it is not such a bad thing after all. Throw in interfaces into the mix and program to an interface and not an implementation, and it will enables you to create different branches if needed. If your classes can flourish while being sealed, chances are that you have some pretty nice structures code in your hands.</p>  <p>There probably are some legit reasons to not seal classes at time, despite the reasoning above, so I am not going to be definitive and say that is never the case. Voice your thoughts in the comments and let us see where this ends up – who knows, I might be left standing as a fool!</p>  <p>As always, you can find me on twitter by the name of <a title="Visit me on twitter" href="http://twitter.com/thecodejunkie" target="_blank">@thecodejunkie</a></p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
		<comments>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 22:40:49 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/</guid>
		<description><![CDATA[Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended? I was working on building an automated testing framework for a welfare system in which cases could be added [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended?</p>  <p>I was working on building an automated testing framework for a welfare system in which cases could be added and benefits run for a given month.</p>  <p>A typical scenario might be something like:</p>  <ol>   <li>Create a new case for this month. </li>    <li>Add some people, do some things. </li>    <li>Run benefits for this month. </li>    <li>Run benefits for the next month.&#160; Something should happen because the child on the case is now 19. </li> </ol>  <p>Seems pretty straightforward until you consider what happens if someone hard codes dates into the test.</p>  <p>I am sure you can imagine plenty of scenarios in a situation like this where hard coded dates would eventually cause all kinds of problems.</p>  <p>The problem is… </p>  <p><strong>If you create an API which takes in various dates, how do you ensure the dates passed in are calculated and not just hard coded?</strong></p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pigsinblanket" border="0" alt="pigsinblanket" src="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket_thumb.jpg" width="514" height="514" /></a> </p>  <h2>Why convention doesn’t work</h2>  <p>Your first response might be to create some documentation that describes the importance of making dates “float” forward with time, and not be hard coded.</p>  <p>You might clearly describe how you should not hard code July 7th 1990 to be the birth date of a 20 year old for a test case.</p>  <p>You might give some guidelines of how to properly calculate ages.</p>  <p>But, you have no way of making sure the users of your API will follow those conventions or even read your document.</p>  <p>What if we do the hard work for them?</p>  <h2>Why utilities are still not good enough</h2>  <p>The next idea you might have is to create utilities that would do date conversions and calculate ages for the user of your API, so that they just have to remember to use them and all will be good.</p>  <p>This solution is better than one relying purely on convention, but still has some major flaws.&#160; Part of the problem of utility methods is that they are not self-discoverable.&#160; I’ve <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">talked about before</a> how DateUtilities like classes can get overlooked if you don’t know the utility class is there.</p>  <p>If you are relying on your users to go out and find your utility methods to make life easier for them, you are putting a large amount of responsibility in the wrong place.&#160; In my experience, it is very unlikely that anyone but yourself will actually use the utility methods.</p>  <p>You really need a way to stop them from being able to hard code dates.</p>  <h2>How can you stop someone from hard coding dates?</h2>  <p>Don’t accept dates in your API.</p>  <p>It is simple.</p>  <p>What?&#160; What do you mean?&#160; You can’t just stop accepting dates, you need dates.&#160; Not just dates, but integers, or strings.&#160; You can’t just not accept the bad data… or can you?</p>  <p>Consider wrapping the data type in another data type which creates your desired data type, but only using the convention or rules you desire.</p>  <p>Let me show you an example with the dates:</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(DateTime applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>    DoSomethingWithTheDate(applicationDate);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(<span style="color: #0000ff">new</span> DateTime(1990, 7, 8));</pre>
<!--CRLF--></div>
</div>

<p></p>

<p>In the above example, you can see that I am directly taking a .NET DateTime object.&#160; You can also see that I am directly hard coding a date when calling this method.</p>

<p>Let’s see if we can fix that.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(CaseDate applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     DoSomethingWithTheDate(CaseDate.ToDateTime());</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(CaseDate.YearsAgo(20));</pre>
<!--CRLF--></div>
</div>

<p></p>

<h2>What happened?</h2>

<p>Here is what we did:</p>

<ol>
  <li>We created a custom type called CaseDate. </li>

  <li>We replaced all the external usages of DateTime with CaseDate. </li>

  <li>We provided methods on CaseDate which allow the creation of dates, only through the way we want to allow them to be created. </li>
</ol>

<ol>Now we can easily prevent users of the API from being able to create hard coded dates.&#160; The API only will take CaseDate objects and internally creates DateTime objects from the CaseDate objects.</ol>

<ol>We can add other methods to CaseDate to allow the creation of dates from x number of months ago or in the future, or any other valid creation method we want.</ol>

<p>By doing this, we are restricting the valid set of inputs to our methods at compile time, not throwing exceptions at run time.</p>

<p>We are achieving the same kind of valuable input constrictions that we have been able to <a href="http://elegantcode.com/2010/05/08/the-power-of-enum/">achieve with enumerations</a>, except we are adding more complex restrictions than a simple list of selections.</p>

<h2>Where can I use this?</h2>

<p>Not just dates.&#160; There are many places where restricting the input to your method or API is going to simplify logic, protect against error conditions, and enforce constraints.</p>

<p>Consider using this pattern in some of these scenarios:</p>

<ul>
  <li>You want to use an enumeration, but your list of possible choices is too large, or repetitive. </li>

  <li>Anywhere you are using a primitive type and that primitive type represents some more complex concept. </li>

  <li>Anywhere you have parameter validation or manipulation repeated in multiple methods. </li>

  <li>Anytime you process some input or repeat a series of steps to transform it before sending it as input. </li>
</ul>

<p>Every time you are about to make a primitive type a parameter to a method you should ask yourself if it makes sense to wrap the primitive type into an class.</p>

<p>Remember, especially when creating an API, any time your method takes a primitive type, you lose the ability to constrain that input, and are forced to validate it instead.</p>

<p>Should you always wrap all primitive types?&#160; No, but it is another tool you can use to provide an extra layer of indirection between the logic of your API and your callers use of it.</p>

<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Prefer Additional Methods Over Additional Overloads</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
		<comments>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 17:35:54 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/</guid>
		<description><![CDATA[If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do. Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do.</p>  <p>Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are conscious of making that code as readable and terse as possible.</p>  <p><strong>Seldom do we think about the use of our code from an API standpoint.</strong></p>  <p>There is a subtle difference between designing your code in a way that will make it easier for someone else to maintain, and designing your code in a way that will make it easier for someone else to use.</p>  <h2>Intellisenselessness</h2>  <p>How often are you working against some API and you type a method name you want to use only to have intellisense present you with 5 overloads for the method all with several different parameters choices?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginOverloads" border="0" alt="LoginOverloads" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads_thumb.png" width="600" height="151" /></a> </p>  <p>Which one do you use?&#160; It is hard to be sure, you end up having to read through the long lists of parameters to figure out what method you should call and what parameters you should pass it.</p>  <p>Wouldn’t it be better if you were presented with what the method does in the method name rather than guessing what it does in the parameter list?&#160; Something like this?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginMoreMethods" border="0" alt="LoginMoreMethods" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods_thumb.png" width="596" height="261" /></a> </p>  <h2>Perspective</h2>  <p>From the perspective of the person writing the <em>Login</em> method(s), overloads probably seem like the most efficient and correct way to implement the multiple ways the method can be called.</p>  <p>From the perspective of the person using the <em>Login</em> method(s), additional methods are much preferred, because they are easier to understand and know what you are looking for.</p>  <p><strong>Try to think from the perspective of someone using your code when writing your code.</strong></p>  <h2>Extract boolean parameter to two methods</h2>  <p>I want to take a look at a very specific example that can be of great benefit to the readability and use of your code.</p>  <p>Take a look at this code below.</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login(<span style="color: #0000ff">bool</span> rememberMe)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>
Seems like a fine overload of a <em>Login</em> method.&#160; I have written code just like this, you probably have also.&#160; <br />

<p>&#160;</p>

<p>Unfortunately, by adding this overload, we have added some complexity to our API, because now the user of that code has to see that there is an additional overload that take a bool parameter called <em>rememberMe</em>.</p>

<p>Consider this longer alternative.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginDoNotRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Instead of overloading <em>Login</em> and making the user have to decide which overload to call and pass in a parameter, we have elected to create two differently named methods which take 0 parameters and clearly state what they are going to do.</p>

<p>I’m not saying you should never write overloads, but anytime you see an overload in your code base, you should stop and think if it would be more clear to make that overloaded method into two different methods that can eliminate one or more of the parameters.</p>

<p><strong>Any time you are restricting the number of choices someone using your code has to make, you are making that code simpler to use.</strong></p>

<p>If you don’t believe me, consider why the iPhone has only one button.</p>

<h5><strong>As always, you can subscribe to this </strong><a href="http://feeds2.feedburner.com/ElegantCode"><strong>RSS feed</strong></a><strong> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at </strong><a href="http://simpleprogrammer.com"><strong>http://simpleprogrammer.com</strong></a><strong>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Say &#8220;No&#8221; to &#8220;Null&#8221;</title>
		<link>http://elegantcode.com/2010/05/01/say-no-to-null/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=say-no-to-null</link>
		<comments>http://elegantcode.com/2010/05/01/say-no-to-null/#comments</comments>
		<pubDate>Sat, 01 May 2010 19:35:05 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/05/01/say-no-to-null/</guid>
		<description><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after. What do you do if "null” [...]]]></description>
			<content:encoded><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after.
<blockquote>What do you do if "null” is passed in?</blockquote>
My answer may turn out to be a bit of a surprise.
<blockquote><span style="background-color: #f4f5f7;">Nothing, I don’t handle nulls in code that I control the use of.</span></blockquote>
“What?  What?” you say.  “You don’t handle null?  What kind of heresy is that?”  It is the kind of heresy that helps produce elegant code and I will show you why.
<h2>How well do you handle null right now?</h2>
Would you say that in most of the code you write you properly check all arguments for null?

Or, do you like most developers, handle null in certain cases when you happen to think about it, or after the application dumps a “null pointer exception” stack trace?

Be honest, look at your code if you have to.

The problem is “d00d ur d0ing it r0ng!”

<a href="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="john-mccarthy-programming-completely-wrong" src="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong_thumb.jpg" border="0" alt="john-mccarthy-programming-completely-wrong" width="349" height="452" /></a>

Unless you are some kind of anal retentive perfectionist, you are probably not handling null in every single method call.  That means there are huge potential bugs in the code that you are writing which will throw null pointer exceptions.  That is bad, I agree.

So, if you are not handling it correctly right now, then what can you do to fix that?
<h2>Avoiding null in the code you “own”</h2>
You can’t control external libraries.  And you can’t control how people will use your code, but you can control the code you write and you can, to a degree, control the code your shop writes.

The better strategy is to never pass null in the first place.

You can either focus your efforts on:
<ul>
	<li>Checking for null</li>
	<li>Not ever passing null</li>
</ul>
<ul>The more elegant solution is to focus on never passing null.  By doing this you will end up writing less code and avoid decisions about how to handle null inside of a method that doesn’t have enough context to decide what to do.</ul>
Let’s look at an example:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> TransmographyThreeStrings(<span class="kwrd">string</span> first, <span class="kwrd">string</span> second, <span class="kwrd">string</span> third)
{
     <span class="kwrd">if</span>(<span class="kwrd">string</span>.isNull(first) || <span class="kwrd">string</span>.isNull(second) || <span class="kwrd">string</span>.isNull(third))
    {
           <span class="rem">// hmm, I donno, what should I do?  Should I throw an exception?</span>
           <span class="rem">// should I return an empty string?</span>
           <span class="rem">// what if the first string wasn't null, can we still do something meaningful?</span>
           <span class="rem">// how will the caller of the method know what I will do?</span>
    }

}</pre>
You can see there that we are checking each parameter for null.  The problem is we don’t know what we should do.  We have lots of options, but none of them are obvious.

How much better is it to make sure that we never pass null into methods, rather than write this kind of code in every method?
<h2>What about accidentally passing in null?</h2>
Many of you are probably thinking at this point that the main way null gets passed into a method is because someone calls a method without knowing that it contains a null value.
<pre class="csharpcode">TransmographyThreeStrings(<span class="str">"Hello"</span>, <span class="str">"World"</span>, mysteryObject.Text);</pre>
Perhaps <em>mysteryObject.Text </em>is null.  You wouldn’t even know it.

Ah, but you can.  Or you can prevent it at least.  Somewhere <em>mysteryObject </em>gets created.  When it gets created its values either get initialized or not.  You can prevent any of its values from being null, several ways:
<ul>
	<li>Always initialize variables when they are declared.</li>
	<li>Use a <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> to ensure that objects are always fully constructed before being created.</li>
	<li>Use properties to provide default values or lazy initialize.</li>
	<li>Make your objects <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> as much as possible.</li>
</ul>
The practices that prevent null from accidentally being passed in make your code much more elegant than repeating <em>if blah == null</em> code all over the place.

<strong>In general, you should always strive to eliminate the passing of null rather than checking for null.  By doing so you reduce extra lines of code in each method, and are forced to use better design practices.</strong>
<h2>Exceptions</h2>
Yes, there are times when you need to check for null.  If you are writing a library that external developers will use, then you will probably want to check for null in all of your methods that are exposed as part of the API.  (On your internal methods, you don’t need to since you have already cleansed the input.)

Also, if your code is being used as a callback to some API and you don’t know if it can ever pass null into your code, you probably should check for null.

A bad excuse is that other developers may pass null to your method. <strong>It is much better as a software shop to put the onus of not passing null on the caller of any method rather than putting it on the writer of the method being called.</strong>

You will also reduce your exception handling code, because you will have less exceptions for invalid parameters.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/05/01/say-no-to-null/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>If Self-Documenting Code is the What, Unit Tests are the Why</title>
		<link>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-self-documenting-code-is-the-what-unit-tests-are-the-why</link>
		<comments>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:09:04 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/</guid>
		<description><![CDATA[It is not enough to just write code that is clean and self-documenting.  Eliminating comments and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it. If you recall from my original post on [...]]]></description>
			<content:encoded><![CDATA[It is not enough to just write code that is clean and self-documenting.  <a href="http://elegantcode.com/2010/04/18/eliminating-comments-the-road-to-clarity/">Eliminating comments</a> and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it.

If you recall from my <a href="http://elegantcode.com/2010/04/09/what-does-elegant-code-mean-to-me/">original post</a> on Elegant code, I stated that elegant code is:
<blockquote>Something that is simple yet effective, delivered with grace.</blockquote>
By writing self-documenting code we are hopefully able to achieve some of the aspects of simplicity and grace, but it tells us nothing about the effectiveness of the code.
<h2>Bringing the dead to life</h2>
<a href="http://elegantcode.com/wp-content/uploads/2010/04/zombies.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="zombies" src="http://elegantcode.com/wp-content/uploads/2010/04/zombies_thumb.jpg" border="0" alt="zombies" width="441" height="295" /></a>

Throwing out comments is a debatable topic.  <a href="http://www.reddit.com/r/programming/comments/bsutx/">It raises quite a bit of controversy</a>, as you can see from some of the comments on my post about the subject.  The reason, perhaps, that so many people are so staunchly opposed to the idea, is because they are worried, and rightly so, that throwing out comments will reduce the documentation of what the code is doing.

Think about that for a second.  Is documentation of what the code is doing important?  It better be.  What we are trying to accomplish by writing self-documenting code instead of comments, is to take the vessel, which is the code itself, and make that same vessel be the documentation of what the code does.  It is by doing this that we creating a living representation of the functionality of the code.  Comments are akin to a dead representation of the functionality of the code because they do not change automatically with the code.

I diverge to talk about comments so that I can draw a parallel to another form of documentation which is valuable and should be considered necessary.  That other set of documentation is requirements.  Have you ever written requirements documents?  Have you ever captured requirements from the customer and put them into UML diagrams, or perhaps plopped them into some templated Word document, which is never updated again, and no one reads, because no one trusts it is correct?  Wouldn’t it be great if we would replace that dead document or set of documents, with a living one?

The good news is we can, and some of us have.  And I fully expect this recommendation will be just as controversial, because <strong>I am suggesting that we don’t have to write low level specifications of the system at all, instead we can write good unit tests. </strong>When we do this, we are taking a dead form of document and bringing it to life.
<h2>Unit tests tell us why and how our code is effective</h2>
If
<pre class="csharpcode">i = 5;  // Widget count defaults to five.</pre>
is replaced with
<pre class="csharpcode">widgetCount = DEFAULT_WIDGET_COUNT;</pre>
<!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

then
<blockquote><span style="background-color: #ffffff;">1.1.5 When a new widget is created, the widget count should be increased by one.</span></blockquote>
is replaced with
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> When_NewWidgetIsCreated_Then_WidgetCountIsIncreasedByOne()
{
     WidgetFactory.Count = 3;
     WidgetFactory.CreateNew();
     assertEquals(4, WidgetFactory.Count);
}</pre>
The unit test is replacing the low level requirement, which is somewhat open to interpretation and untied to the code, with an absolute and completely tied-to-the-code, specific requirement.

The unit test is telling us why our code is built the way it is.  It is telling us what requirement that particular structure of code is trying to address.  <strong>It is telling us what end result that code is trying to accomplish and what the expectations are on the results of a given condition.</strong>

The unit test is telling us how the code is to be used in order to achieve its result.  It is serving as a living reference to the syntax and use of the code we built.  <strong>Instead of providing instructions on how to use our API, we are providing a living example, and proof that it will indeed work.</strong> Examples are often much more effective than instructions anyway.
<h2>What exactly are we replacing?</h2>
At this point we are not trying to replace all the documentation of the system (at this point).

With self-documenting code, we sought to eliminate comments, and replace them with good variable and method names.

With unit tests, we seek to eliminate technical documentation and requirements of the system, that is targeted at a developer or technical audience.

We are NOT trying to eliminate high level specifications of the system, or use cases. <strong>Unit tests DO NOT replace that kind of documentation! </strong>We will talk about replacing that kind of documentation when we talk about automated functional or system tests.

Simply put, any kind of documentation that you would give to a developer so they understand how the system works and how to use the code or APIs, can be easily replaced by writing good unit tests.

Our simple goal is to replace the “dead” documentation (meaning that it does not update automatically with the thing it is documenting), with “living” documentation in the form of unit tests.

One last point.  I want to be clear that I am not saying that having unit tests automatically results in the ability to replace technical documentation.  Just like having long-named methods and variables doesn’t automatically replace the need for comments.  It is a matter of the quality of the unit tests that are written, just as it is a matter of the quality of the self-documenting code.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>REST: Resources, URI&#8217;s and Representations</title>
		<link>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rest-resources-uris-and-representations</link>
		<comments>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 04:00:13 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/</guid>
		<description><![CDATA[In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions. Resources Resources are at the heart of REST.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions.</p>  <h3>Resources</h3>  <p>Resources are at the heart of REST.&#160; You are already used to resources as a web browsing consumer.&#160; A resource is not something specific to REST, instead it is the first thing you probably want to consider when architecting a RESTful application.&#160; A resource is simply the entity, item, or thing you want to expose.</p>  <p>Perhaps you have approached application architecture using one or many of several modeling and design techniques.&#160; Data First practitioners typically begin with databases and data models.&#160; DDD proponents like to begin by modeling around business entities and interactions, while their cousins in the BDD camp model around business activities.</p>  <p>When you decide to apply REST you will need to think a lot more about data entities and domain objects as resources.&#160; Your existing models may or may not closely map to resources.&#160; The shift in thinking may appear slight, but is very important.&#160; It centers around making things&#160; addressable.&#160; Each resources must by uniquely identifiable as we will see in the next section.&#160; We are used to identity with most data entities, but our domain objects may not always be as easily identifiable.&#160; Likewise, our data entites may have identity, but not map to a resource.&#160; </p>  <p>Consider the classic customer and order scenario for example.&#160; If each customer and each order can be identified then it will be easy to design RESTful systems around them.&#160; However, if the model requires a lot of context then our challenge is a little bit larger.&#160; Perhaps we must first identify a partner, then a year, then a customer, and finally the order.&#160; Yes, that is a design smell in general.&#160; It makes fetching an order very difficult.&#160; Developing RESTfuly would only further expose that difficulty.&#160; Identifying your resources up front will help you reduce the possible impedance mismatches you might end up with between what you want to expose and your data or domain models.</p>  <p>REST is about interacting with Resources!</p>  <h3>URI’s</h3>  <p>REST defines the identity of a resource via URI.&#160; Each resources has a unique address in URL form (ie. using the http protocol).&#160; Interaction with a resource will take place at its URI.&#160; As an example, my twitter status feed resource URI is <a title="http://twitter.com/optionstrict" href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; That URI is unique to my feed and that is what you expect to find at that URI.&#160; In the Twitter databases or domain models my account may be referred to by the string optionstrict, or perhaps as some random number or guid.</p>  <p>To consume my status history via a service interface twitter provides another URI at <a title="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict" href="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict">http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict</a>.&#160; I would actually prefer to have access at the same URI for html, json, and xml formats.&#160; Twitter probably has its reasons for distinguishing API access from HTML rendering, but they have actually complicated their architecture by doing so.&#160; When designing the URI’s for your resources, make them easy for your users to work with.&#160; </p>  <h3>Representation</h3>  <p>Lets continue with the twitter example to describe what is meant by Representation.&#160; Given a URI and a Resource, what will your consumers receive when they issue a GET request to the URI?&#160; Twitter chose a representation of my account and included status history and profile for the response at <a href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; They decided to put a representation of my profile photo at <a title="http://twitter.com/account/profile_image/optionstrict" href="http://twitter.com/account/profile_image/optionstrict">http://twitter.com/account/profile_image/optionstrict</a>.&#160; In your REST solutions you will need to consider how you want to represent a resource at its URI.&#160; Each representation will have a unique URI.&#160; </p>  <p>Representations are also important for manipulating resources.&#160; You must define the representation required to create and update resources.&#160; Twitter status updates require a text representation with a maximum of 140 characters.&#160; They allow additional values in the status representation, such as latitude and longitude.&#160; Your REST solutions similarly must define representations for Requests and Responses.</p>  <p>I hope that this short introduction has helped you to see that the core essence of REST is simple and fairly obvious.&#160; As you look at your current solutions what are the resources you are exposing?&#160; Could you make those resources identifiable by URI?&#160; What representation would you place at each URI?&#160; What representation would you require for manipulating a given resource?</p>  <p>Also, notice I did not mention much about data formats, Content Type, Mime, etc.&#160; Those details can cloud your design if you try to start with them. If you can’t wait for my post about how REST handles html, json, xml from the same URI, then start googling Content Negotiation, Accept header, and Content-Type header.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Driven Architecture: Publishing Events using an IOC container</title>
	<atom:link href="http://elegantcode.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Elegant Code &#187; Architecture</title>
	<atom:link href="http://elegantcode.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quinine For Sale</title>
		<link>http://elegantcode.com/2012/01/18/monitoring-an-mmo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-an-mmo</link>
		<comments>http://elegantcode.com/2012/01/18/monitoring-an-mmo/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:45:32 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MMO]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2012/01/18/monitoring-an-mmo/</guid>
		<description><![CDATA[I’ve been working on a free-to-play MMO Quinine For Sale, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I’ve been working on a free-to-play <a href="http://www.heroup.com" target="_blank">MMO</a> <b>Quinine For Sale</b>, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before they become serious and fixing problems when they inevitably do.&#160; So, there are two questions.&#160; “Is there a problem in the game?” “What is causing the problem?”&#160; </p>  <p>When trying to debug something on our development and test clusters, typically you can tail log files.&#160; We have a python script that can monitor the communication between various parts of the game and pretty-print it along with color to highlight “this is a problem!”&#160; Attaching a debugger to a running process is also not uncommon.&#160; However, looking at logs and bus traffic in realtime on a production environment gives you this neat “Matrix-y” experience.&#160; Attaching a debugger to a production process (assuming you could, which you can’t) would get you smacked with a rolled-up newspaper.&#160; “Bad Developer!&#160; No treat!”&#160; So, what can you do?</p>  <h4>Monitoring</h4>  <p>When you’ve got clusters full of machines, using <a href="http://www.nagios.org/" target="_blank">Nagios</a> to monitor things is an obvious solution.&#160; Beyond making sure the power is on and other sysadmin things, we’ve written other checks to see if the login process is working, the parts are working together, and automating typical in-game functions.&#160; For example, if nagios can’t successfully log into the game do basic game activity, then alerts happen.</p>  <h4>Metrics for EVERYTHING</h4>  <p>Anything that happens in game has metrics reporting tied to it, generating piles of data constantly.&#160; We use <a href="http://www.cacti.net/" target="_blank">Cacti</a> to visualize game activity.&#160; An example metric is concurrent users, or CCU.&#160; We graph how many people are in the game over time, which when things are healthy should be a nice smooth curve climbing to peak game hours, then descending nicely through the night.</p>  <p>We can tell by sight if the game looks healthy or not – if the CCU graph is jaggy, has a sudden drop or spike, or drops to zero then we know that something is wrong.&#160; Typically nagios alerts accompany the graphs, giving more data points on where to look.&#160; But this has also pointed out areas where a nagios check was missing or wasn’t working as intended.</p>  <h4>Log Files</h4>  <p>When a player gets an error in game, the error dialog box gives them the opportunity to submit the error details back to us.&#160; If we see a spike in user-reported errors through this or other customer service means, we know we have something of interest to look for.&#160; </p>  <p>The game server components make use of log4j and similar logging frameworks.&#160; Anything that you’d want to watch happening in game needs to be aggressively logged.&#160; All components are configured so that operations can change the log level on the fly.&#160; That’s still quite a bit of data across many machines though, so all that information is run through <a href="http://www.splunk.com/product" target="_blank">Splunk</a> to be indexed and searchable.&#160; This gives us a great tool for searching through log data, examining trends, or watching selected activity in real time.&#160; Unfortunately it is very expensive so we are selective about the data that passes through it.&#160; </p>.  Buy Quinine from mexico.  Buy Quinine no prescription.  No prescription Quinine online.  Online buying Quinine.  Quinine no prescription.  Quinine street price.  Buy no prescription Quinine online.  Quinine coupon.  Quinine over the counter.  Where can i buy Quinine online.  Quinine steet value.  Where to buy Quinine.  Order Quinine online overnight delivery no prescription.  Quinine recreational.  Quinine canada, mexico, india.  Ordering Quinine online.  Quinine without prescription.  Quinine price, coupon.  Quinine description.  Order Quinine from mexican pharmacy.  Quinine pics.  What is Quinine.  Japan, craiglist, ebay, overseas, paypal.  Order Quinine from United States pharmacy.  Order Quinine online c.o.d.  Quinine trusted pharmacy reviews.  Quinine treatment.  Buy Quinine from canada.  Quinine used for.  Discount Quinine.  Is Quinine addictive.  Quinine forum.  Buy Quinine online no prescription.  Is Quinine safe.  Purchase Quinine for sale.  Effects of Quinine.  Buy Quinine online cod.  Quinine australia, uk, us, usa.  Buy Quinine without prescription.  Quinine online cod.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4721'>Buy Flonase Without Prescription</a>. <a href='http://elegantcode.com/?p=4234'>Buy Periactin Without Prescription</a>. <a href='http://elegantcode.com/?p=4203'>Buy Armour Without Prescription</a>. <a href='http://elegantcode.com/?p=4899'>Buy Macrobid Without Prescription</a>. <a href='http://elegantcode.com/?p=4534'>Xalatan For Sale</a>. <a href='http://elegantcode.com/?p=4302'>Phenergan wiki</a>. <a href='http://elegantcode.com/?p=4268'>Soma maximum dosage</a>. <a href='http://elegantcode.com/?p=4602'>Zovirax treatment</a>. <a href='http://elegantcode.com/?p=4578'>Cialis price, coupon</a>. <a href='http://elegantcode.com/?p=4189'>Flexeril price</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.leaduganda.org/?p=514'>Quinine For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=4820'>Quinine For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2780'>Quinine For Sale</a>. <a href='http://www.thegriffonnews.com/?p=10177'>Quinine For Sale</a>. <a href='http://www.independentworldreport.com/?p=2409'>Quinine For Sale</a>. <a href='http://changecamp.ca/?p=295'>Quinine description</a>. <a href='http://social-blend.com/?p=624'>Quinine price, coupon</a>. <a href='http://blog.farmland.org/?p=3946'>Online buying Quinine hcl</a>. <a href='http://4realz.net/?p=1595'>Quinine from canada</a>. <a href='http://reversemortgagedaily.com/?p=14535'>Where to buy Quinine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2012/01/18/monitoring-an-mmo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temovate Cream For Sale</title>
		<link>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-software-development-will-never-be-engineering</link>
		<comments>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 03:37:48 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/</guid>
		<description><![CDATA[I always find it rather interesting when academics try to quantify generalized metrics about software development. Temovate Cream For Sale, Things like: per lines of code, there will be X number of bugs. Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.” These are all interesting [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I always find it rather interesting when academics try to quantify generalized metrics about software development.</p>  <p> <b>Temovate Cream For Sale</b>, Things like: per lines of code, there will be X number of bugs.</p>  <p>Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.”</p>  <p>These are all interesting thoughts, but software development will never conform to rigid engineering principles like many other engineering practices.&#160; The longer I work in the field, the more and more I realize that software development has nothing to do with engineering.&#160; We just happen to attend some of the same math classes in school.</p>  <h2>Building bridges</h2>  <p>One of the main arguments I hear people make about the current state of software development as an engineering practice is based around its relative maturity to other engineering fields.</p>  <p>There is a huge problem with this line of thinking.</p>  <p>The argument goes something like this:&#160; “<em>Engineering has been around for hundreds of years and has matured to the point where it is a measurable science, but software development has only been around in earnest for the last few decades or so, therefore it is relatively immature as an engineering discipline.”</em></p>  <p>On the surface this argument seems sounds.&#160; And certainly in 50 years software development will be different than it is now.&#160; Heck, it is much more different than it was just 10 years ago.</p>  <p>But, here is the problem.&#160; We build much more software than we do bridges.</p>  <p><img src="http://www.nps.gov/glca/historyculture/images/Navajo_Bridges_1.gif" width="589" height="442" /></p>  <h6 align="center">&#160;</h6>  <p>Let me give you an example that came to light in another area of my interest… poker.</p>  <h1></h1>  <h2>The poker quickening</h2>  <p>An interesting thing happened in the poker community in the last 10 years; poker pros with decades of experience started getting beat time and time again by 19 year old poker prodigies.</p>  <p>From an outside perspective it looks like the poker world opening up just widened the search for talent and there it was.&#160; But, a closer examination of the evidence leads to the truth.</p>  <p>Before the online poker industry was born, poker was played in card rooms and casinos in states where it was legal and occasionally at small home games throughout the US.</p>  <p>A poker pro might play poker tournaments perhaps 100 times to 150 times a year.&#160; The sum knowledge of the poker community and the meta game around it was based on this base of professional poker players playing tournaments and gaining experience at this mediocre rate.</p>  <p>Once the internet poker rooms started opening up, things changed, and they changed rapidly.&#160; Now anyone could play poker from their home PC.&#160; Not only could they play poker, they could play poker tournaments at all hours of the day.</p>  <p>Here is a list of some of the major changes that took place:</p>  <ul>   <li>Hands are dealt at 60-80 hands per hour instead of 10-30</li>    <li>Players can play in many tournaments at one time, 10 tournaments at once is not unheard of</li>    <li>Players can analyze hand histories and historical data about their play and opponents play through the use of software </li>    <li>Age requirements are out the window, technically any one of any age could be playing online</li>    <li>Players can play 24 hours a day</li>    <li>The professional online tournament player could easily play over 3000 tournaments in a year, while a brick and mortar pro would be lucky to reach 100 in a year.</li>   <img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://t1.gstatic.com/images?q=tbn:ANd9GcRj9uGNWSyqGWEneiH6xaBAyS6COwGYicdNadZu-06KWQLhIi6LMw&amp;t=1" width="316" height="270" /></ul>  <p>&#160;</p>  <p>So where am I going with all this?</p>  <p>The point is that as a whole more hands were dealt and more poker knowledge and experience was obtained in 1 year of online poker than probably the entire history of poker before that.&#160; We reached such an accelerated pace of play that all previous knowledge of poker became obsolete.&#160; </p>  <p>The strategy of tournament poker completely changed.&#160; The game evolved perhaps 500 years into the future in a matter of 5 years time.</p>  <p>The same has happened with software development.</p>  <h2>Back to the bridge building</h2>  <p>So let’s take that poker example and look at it through the lens of software development.</p>  <p>Let us compare the engineering maturity to software development to the engineering maturity of the engineering discipline of building bridges.</p>  <p>I think most people would agree that bridge building is a very mature engineering discipline but many people would argue that software development is not.</p>  <p><strong>How many bridges do you think have been built in the world?</strong></p>  <p>Well there are <a href="http://www.betterroads.com/category/bridge-inventory/erroads.randallreillycms.com/files/2009/11/BR1109_BridgeInventory.pdf">about 600,000 bridges in the United States alone</a>, so the world figure must be at least somewhere around 10 times that number perhaps 20.</p>  <p><strong>How many software programs have been written?</strong></p>  <p>This is a very hard number to estimate, but lets take a rough guess based on <a href="http://stackoverflow.com/questions/453880/how-many-developers-are-there-in-the-world">how many software developers there are in the world</a>.&#160; </p>  <p>If we say there are about 12 million software developers and each software developer has written approximately 3 programs, we can estimate that a large amount more programs have been written than bridges built.</p>  <p>My point is not to knock bridge building, we are pretty good at it as a whole, but rather to show that collectively, even though we have been building bridges for hundreds of years, we have probably devoted an equivalent amount of time to building software.</p>  <p>This line of thinking may lead you to argue back that software development and bridge building are very different.&#160; Bridge building has a fixed set of requirements that are pretty close to the the same for each bridge you build, but software development is a big open void of whims and ambiguously contradictory statements.</p>  <p>I agree with you 100%!&#160; And in essence that is my point.</p>  <h2>Software development is different</h2>  <p>And we have had enough time to realize that.&#160; Waiting for software development to gel into some kind of engineering discipline like other engineering disciplines is like waiting for water without gelatin mix to turn into Jello.&#160; </p>  <p>It’s just not going to happen!</p>  <p>In my mind it is clear that the argument that we haven’t given it enough time is just wishful thinking.&#160; The nature of software development, just like online poker, leads itself to rapid evolution.</p>  <p>Consider what direction software development is evolving.&#160; Is it even evolving in the direction of rigid engineering practices or is it evolving in the exact OPPOSITE direction?</p>  <p>Ten years ago, we tried to use UML diagrams and CASE tools to develop software.&#160; Ten years ago waterfall was all the rage.&#160; Ten years ago, we thought that ten years in the future we would have programs that would allow us to build software in the same way that CAD tools allow for building machine parts.</p>  <p>Not only did it not happen.&#160; It went completely the other way.&#160; Now we are all talking about Agile.&#160; Now people don’t even remember what CASE tools are.&#160; Now we are building software without trying to define the whole system in UML diagrams.</p>  <p><strong>The fact of the matter is software systems are unruly beasts!</strong></p>  <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://aznbadger.files.wordpress.com/2010/06/beast.jpg" /></p>  <p>In my mind it comes down to one simple distinction.&#160; Software is living, bridges aren’t.&#160; When you are done building a bridge, you are done building the bridge.&#160; </p>  <p>Sure someone, probably not you, will have to come along and do some routine maintenance on it.&#160; Sure, some small things might change about it, but for all intents and purposes the work is done.</p>  <p>In most software development scenarios, this is not the case.&#160; In most software development scenarios, releasing V1 is not even close to the end.&#160; Sometimes V1 and V2 don’t even look that same at all.&#160; Software development is about operating on a living breathing thing and all the while keeping it alive.</p>  <p>The truth is, we software developers have more in common with surgeons than with other engineers.</p>  <h6>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com/">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>.  Buy Temovate Cream without a prescription.  Temovate Cream trusted pharmacy reviews.  Temovate Cream over the counter.  Where can i order Temovate Cream without prescription.  Online buy Temovate Cream without a prescription.  Temovate Cream no rx.  Buy cheap Temovate Cream no rx.  Temovate Cream photos.  Buy Temovate Cream online no prescription.  Order Temovate Cream online c.o.d.  Herbal Temovate Cream.  About Temovate Cream.  Australia, uk, us, usa.  Cheap Temovate Cream.  Temovate Cream class.  Temovate Cream brand name.  Online Temovate Cream without a prescription.  Buy Temovate Cream without prescription.  Buy Temovate Cream from canada.  After Temovate Cream.  Order Temovate Cream from mexican pharmacy.  Temovate Cream without a prescription.  Purchase Temovate Cream.  Temovate Cream natural.  Temovate Cream overnight.  Temovate Cream online cod.  Where can i buy cheapest Temovate Cream online.  Purchase Temovate Cream for sale.  Online buying Temovate Cream.  Purchase Temovate Cream online.  Temovate Cream used for.  Temovate Cream coupon.  Temovate Cream description.  Order Temovate Cream no prescription.  Temovate Cream maximum dosage.  Cheap Temovate Cream no rx.  Temovate Cream images.  Temovate Cream blogs.  Buy Temovate Cream online cod.  Buy generic Temovate Cream.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4472'>Bactroban For Sale</a>. <a href='http://elegantcode.com/?p=4632'>Armour For Sale</a>. <a href='http://elegantcode.com/?p=4639'>Buy Estrace Vaginal Cream Without Prescription</a>. <a href='http://elegantcode.com/?p=4668'>Buy Augmentin Without Prescription</a>. <a href='http://elegantcode.com/?p=4535'>Buy Tindamax Without Prescription</a>. <a href='http://elegantcode.com/?p=4931'>Fast shipping Diclofenac</a>. <a href='http://elegantcode.com/?p=4240'>Combivent brand name</a>. <a href='http://elegantcode.com/?p=4417'>Levaquin overnight</a>. <a href='http://elegantcode.com/?p=4597'>Purchase Toradol online</a>. <a href='http://elegantcode.com/?p=4221'>Australia, uk, us, usa</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.quarterlives.com/?p=1148'>Temovate Cream For Sale</a>. <a href='http://4realz.net/?p=1972'>Temovate Cream For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=5997'>Temovate Cream For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2476'>Temovate Cream For Sale</a>. <a href='http://www.thegriffonnews.com/?p=9947'>Temovate Cream For Sale</a>. <a href='http://social-blend.com/?p=1160'>Temovate Cream brand name</a>. <a href='http://blog.farmland.org/?p=3812'>Where can i find Temovate Cream online</a>. <a href='http://reversemortgagedaily.com/?p=14136'>Generic Temovate Cream</a>. <a href='http://linuxologist.com/?p=1792'>Temovate Cream photos</a>. <a href='http://home.officesnapshots.com/?p=114'>Order Temovate Cream from mexican pharmacy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
		<item>
		<title>Christmas Light Architectures Are Not That Shiny</title>
		<link>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=christmas-light-architectures-are-not-that-shiny</link>
		<comments>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:00:00 +0000</pubDate>
		<dc:creator>Jan Van Ryswyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/</guid>
		<description><![CDATA[I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way [...]]]></description>
			<content:encoded><![CDATA[<p>I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way overdue :-).</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb1.png" width="202" height="172" /></a> </p>  <p><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a>What's the major malfunction with those old, classic Christmas lights? We've all experienced it at some point. When one goes out, all the others go out as well. This is due to the fact that these lights are wired in series. The difference compared with today's Christmas lights is that every bulb has a shunt, which basically prevents this kind of failure caused by one or more lamps. Enough about the Christmas lights for now. Where am I going with this? Back in enterprise IT, I'm seeing the same kind of failures as with those classic, old Christmas lights.</p>  <p>The diagram below shows a classic RPC style architecture, much like those classic, old Christmas lights. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb2.png" width="565" height="329" /></a> </p>  <p>This is all fine and dandy as long as every part of the chain runs without too much hassle. But what happens if for some reason the centralized back-end web service goes down (light bulb goes out). This means that every smart client, website and batch application that uses this web service gets affected by this, like some sort of chain reaction. Parts of these client applications will no longer function correctly or they might even go down entirely. Same thing happens when the database of the centralized back-end web service goes down or any other external system that it depends on. When being confronted with this kind of architecture, how would one go about preventing this doomsday scenario to happen?</p>  <p>Suppose you’re a developer that has to work on the centralized back-end web service. This is usually a complex system as it obviously has to provide features for all kinds of applications. When this centralized back-end web service also has to deal with and depend on other external systems that might expose some unexpected behavior, how could one prevent the sky from falling down when things go awry in production?</p>  <p>Well for starters, you could start building in some stabilization points. Suppose for some reason, the centralized web service needs to incorporate some functionality offered by a highly expensive, super enterprise system that for some reason behaves very unstable and unpredictably on every full moon (expensive enterprise software not behaving correctly sounds ridiculous, but bare with me ;-) ). For example, we could use a message queue as a stabilization point. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb3.png" width="570" height="157" /></a> </p>  <p>This means that we put a message on a queue that is processed by some sort of worker process or service that does the actual communication with the misbehaving system. When the external system goes down, the message is either left on the message queue or put on an error queue for later processing when the external system comes back up again. There are some other things you need to think about like idempotent messaging, consistency, message persistence when the server goes down, etc. … . But if one of these dependencies goes down, the centralized back-end web service is still up-and-running which means that the systems that depend on its functionality can also continue to serve their users as they are able to keep doing their work.</p>  <p>Earlier this week I overheard this conversation that somewhat amazed me. I changed the names of the persons involved as well as the exact words used in order to protect the guilty.</p>  <blockquote>   <p><em>George: </em><em>We want to incorporate a message queue in order to guarantee stability and&#160; integrity between several non-transactional systems that our system depends on. It will also improve performance as these systems behave very slow at times and become unstable under pressure. This also gives us the opportunity to root out some major points friction that our end-users are experiencing right now.</em></p>    <p><em>Stan: But this means that the end-users are not completely sure if their actions are indeed fully carried out by the system. </em></p>    <p><em>George: End-users can always check the current state of affairs in their applications. If something goes wrong, their request is not lost and things will get fixed automatically later on as soon as the cause of the error has been fixed. </em></p>    <p><em>Stan:&#160; I don’t think that’s a very good idea. End-users have to wait until everything is processed synchronously, even if that means that they’ll need to wait for a long time. And if one of the external systems goes down, they should stop sending in new requests. Everything should come to a halt. They just have to stop doing what they are doing.</em></p>    <p><em>George: This means that because you lose the original request, some external systems might be set up correctly while others are not. Then someone has to manually fix these issues.</em></p>    <p><em>Stan: Then so be it!</em>&#160;</p> </blockquote>  <p>For starters, I was shocked by this conversation. This is just insane. Everything should come to a halt? Think about this scenario for a while: suppose you’re finding yourself in a grocery store with a cart full of food, drinks and other stuff. You come at the cash register where the lady kindly says “Can you put everything back on the shelves please? There are some issues with the cash register software and we are instructed to stop scanning items and serve customers until these issues are fixed. Can you come back tomorrow please?”. Uhm, no! How much money do you think this is going to cost compared to the system that makes use of stabilization points? An end-user that is able to keep doing its work, whether the entire production system is down or not has tremendous business value. </p>  <p>I’m not saying that message queues are a silver bullet. I’m just using these as an example. As always, there is a time and place for using them. There are other things a developer can incorporate in order to increase the stability of the system he’s working on, like <a href="http://davybrion.com/blog/2008/05/the-circuit-breaker/" target="_blank">the circuit breaker pattern</a>. I’m also not saying that every system should be built using every stabilization point one can think of. This become a business decision depending on the kind of solution. As usual, it depends.</p>  <p>But the point that I’m trying to make here is that we should stop putting software systems into production and just hoping for the best. That’s just wishful thinking. Software systems are going to behave badly and at some point they will go down. It’s just a matter of when this is going to happen and how much damage this is going to make.</p>  <p>The first step to take is awareness. I encourage you to pick up this book titled ‘<a href="http://www.amazon.com/exec/obidos/ASIN/0978739213/elegantcode-20" target="_blank">Release It!</a>’, written by <a href="http://www.michaelnygard.com/" target="_blank">Michael Nygard</a>. This book is all about designing software that can survive this though environment called production. I can only hope that Stan picks up a copy as well along with some common sense.</p>  <p>Till next time.&#160;&#160;&#160; </p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Could sealing a class be a sign of a good design</title>
		<link>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=could-sealing-a-class-be-a-sign-of-a-good-design</link>
		<comments>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:50:15 +0000</pubDate>
		<dc:creator>Andreas Håkansson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/</guid>
		<description><![CDATA[I recently attended this years Øredev conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, Philip Laureano. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended this years <a title="Read more about the Øredev conference" href="http://oredev.com/2010" target="_blank">Øredev</a> conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, <a title="Visit the twitter profile of Philip Laureano" href="http://twitter.com/philiplaureano" target="_blank">Philip Laureano</a>. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do not know the full details of his exact opinions). Anyway, the short version is that the person suggested that classes should be sealed by default, or at least have the developer explicitly state if the class should be sealed or closed.</p>  <p>My immediate reaction was that this was a terrible idea and that I had been struck down too many times by sealed classes before. But then I started thinking that maybe it was not such a bad idea after all. Maybe it even was a sign of a well designed class and that more developers would be better of by sealing their classes.</p>  <p>Now let me inform you that I am still on the ropes about this, but I would like your thoughts on it. In fact I am hoping that the most interesting part of this post will end up being the discussion in the comment section.</p>  <p>So when you take a moment to think about the <em>S.O.L.I.D principles</em>, most specifically the <em>Open-Closed Principle</em> and <em>Dependency Inversion Principle</em>, a long with the old design principle of ‘Favor <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> over <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)">class inheritance</a>’ then maybe it is not such a bad thing after all. Throw in interfaces into the mix and program to an interface and not an implementation, and it will enables you to create different branches if needed. If your classes can flourish while being sealed, chances are that you have some pretty nice structures code in your hands.</p>  <p>There probably are some legit reasons to not seal classes at time, despite the reasoning above, so I am not going to be definitive and say that is never the case. Voice your thoughts in the comments and let us see where this ends up – who knows, I might be left standing as a fool!</p>  <p>As always, you can find me on twitter by the name of <a title="Visit me on twitter" href="http://twitter.com/thecodejunkie" target="_blank">@thecodejunkie</a></p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
		<comments>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 22:40:49 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/</guid>
		<description><![CDATA[Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended? I was working on building an automated testing framework for a welfare system in which cases could be added [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended?</p>  <p>I was working on building an automated testing framework for a welfare system in which cases could be added and benefits run for a given month.</p>  <p>A typical scenario might be something like:</p>  <ol>   <li>Create a new case for this month. </li>    <li>Add some people, do some things. </li>    <li>Run benefits for this month. </li>    <li>Run benefits for the next month.&#160; Something should happen because the child on the case is now 19. </li> </ol>  <p>Seems pretty straightforward until you consider what happens if someone hard codes dates into the test.</p>  <p>I am sure you can imagine plenty of scenarios in a situation like this where hard coded dates would eventually cause all kinds of problems.</p>  <p>The problem is… </p>  <p><strong>If you create an API which takes in various dates, how do you ensure the dates passed in are calculated and not just hard coded?</strong></p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pigsinblanket" border="0" alt="pigsinblanket" src="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket_thumb.jpg" width="514" height="514" /></a> </p>  <h2>Why convention doesn’t work</h2>  <p>Your first response might be to create some documentation that describes the importance of making dates “float” forward with time, and not be hard coded.</p>  <p>You might clearly describe how you should not hard code July 7th 1990 to be the birth date of a 20 year old for a test case.</p>  <p>You might give some guidelines of how to properly calculate ages.</p>  <p>But, you have no way of making sure the users of your API will follow those conventions or even read your document.</p>  <p>What if we do the hard work for them?</p>  <h2>Why utilities are still not good enough</h2>  <p>The next idea you might have is to create utilities that would do date conversions and calculate ages for the user of your API, so that they just have to remember to use them and all will be good.</p>  <p>This solution is better than one relying purely on convention, but still has some major flaws.&#160; Part of the problem of utility methods is that they are not self-discoverable.&#160; I’ve <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">talked about before</a> how DateUtilities like classes can get overlooked if you don’t know the utility class is there.</p>  <p>If you are relying on your users to go out and find your utility methods to make life easier for them, you are putting a large amount of responsibility in the wrong place.&#160; In my experience, it is very unlikely that anyone but yourself will actually use the utility methods.</p>  <p>You really need a way to stop them from being able to hard code dates.</p>  <h2>How can you stop someone from hard coding dates?</h2>  <p>Don’t accept dates in your API.</p>  <p>It is simple.</p>  <p>What?&#160; What do you mean?&#160; You can’t just stop accepting dates, you need dates.&#160; Not just dates, but integers, or strings.&#160; You can’t just not accept the bad data… or can you?</p>  <p>Consider wrapping the data type in another data type which creates your desired data type, but only using the convention or rules you desire.</p>  <p>Let me show you an example with the dates:</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(DateTime applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>    DoSomethingWithTheDate(applicationDate);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(<span style="color: #0000ff">new</span> DateTime(1990, 7, 8));</pre>
<!--CRLF--></div>
</div>

<p></p>

<p>In the above example, you can see that I am directly taking a .NET DateTime object.&#160; You can also see that I am directly hard coding a date when calling this method.</p>

<p>Let’s see if we can fix that.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(CaseDate applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     DoSomethingWithTheDate(CaseDate.ToDateTime());</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(CaseDate.YearsAgo(20));</pre>
<!--CRLF--></div>
</div>

<p></p>

<h2>What happened?</h2>

<p>Here is what we did:</p>

<ol>
  <li>We created a custom type called CaseDate. </li>

  <li>We replaced all the external usages of DateTime with CaseDate. </li>

  <li>We provided methods on CaseDate which allow the creation of dates, only through the way we want to allow them to be created. </li>
</ol>

<ol>Now we can easily prevent users of the API from being able to create hard coded dates.&#160; The API only will take CaseDate objects and internally creates DateTime objects from the CaseDate objects.</ol>

<ol>We can add other methods to CaseDate to allow the creation of dates from x number of months ago or in the future, or any other valid creation method we want.</ol>

<p>By doing this, we are restricting the valid set of inputs to our methods at compile time, not throwing exceptions at run time.</p>

<p>We are achieving the same kind of valuable input constrictions that we have been able to <a href="http://elegantcode.com/2010/05/08/the-power-of-enum/">achieve with enumerations</a>, except we are adding more complex restrictions than a simple list of selections.</p>

<h2>Where can I use this?</h2>

<p>Not just dates.&#160; There are many places where restricting the input to your method or API is going to simplify logic, protect against error conditions, and enforce constraints.</p>

<p>Consider using this pattern in some of these scenarios:</p>

<ul>
  <li>You want to use an enumeration, but your list of possible choices is too large, or repetitive. </li>

  <li>Anywhere you are using a primitive type and that primitive type represents some more complex concept. </li>

  <li>Anywhere you have parameter validation or manipulation repeated in multiple methods. </li>

  <li>Anytime you process some input or repeat a series of steps to transform it before sending it as input. </li>
</ul>

<p>Every time you are about to make a primitive type a parameter to a method you should ask yourself if it makes sense to wrap the primitive type into an class.</p>

<p>Remember, especially when creating an API, any time your method takes a primitive type, you lose the ability to constrain that input, and are forced to validate it instead.</p>

<p>Should you always wrap all primitive types?&#160; No, but it is another tool you can use to provide an extra layer of indirection between the logic of your API and your callers use of it.</p>

<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Prefer Additional Methods Over Additional Overloads</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
		<comments>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 17:35:54 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/</guid>
		<description><![CDATA[If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do. Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do.</p>  <p>Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are conscious of making that code as readable and terse as possible.</p>  <p><strong>Seldom do we think about the use of our code from an API standpoint.</strong></p>  <p>There is a subtle difference between designing your code in a way that will make it easier for someone else to maintain, and designing your code in a way that will make it easier for someone else to use.</p>  <h2>Intellisenselessness</h2>  <p>How often are you working against some API and you type a method name you want to use only to have intellisense present you with 5 overloads for the method all with several different parameters choices?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginOverloads" border="0" alt="LoginOverloads" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads_thumb.png" width="600" height="151" /></a> </p>  <p>Which one do you use?&#160; It is hard to be sure, you end up having to read through the long lists of parameters to figure out what method you should call and what parameters you should pass it.</p>  <p>Wouldn’t it be better if you were presented with what the method does in the method name rather than guessing what it does in the parameter list?&#160; Something like this?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginMoreMethods" border="0" alt="LoginMoreMethods" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods_thumb.png" width="596" height="261" /></a> </p>  <h2>Perspective</h2>  <p>From the perspective of the person writing the <em>Login</em> method(s), overloads probably seem like the most efficient and correct way to implement the multiple ways the method can be called.</p>  <p>From the perspective of the person using the <em>Login</em> method(s), additional methods are much preferred, because they are easier to understand and know what you are looking for.</p>  <p><strong>Try to think from the perspective of someone using your code when writing your code.</strong></p>  <h2>Extract boolean parameter to two methods</h2>  <p>I want to take a look at a very specific example that can be of great benefit to the readability and use of your code.</p>  <p>Take a look at this code below.</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login(<span style="color: #0000ff">bool</span> rememberMe)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>
Seems like a fine overload of a <em>Login</em> method.&#160; I have written code just like this, you probably have also.&#160; <br />

<p>&#160;</p>

<p>Unfortunately, by adding this overload, we have added some complexity to our API, because now the user of that code has to see that there is an additional overload that take a bool parameter called <em>rememberMe</em>.</p>

<p>Consider this longer alternative.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginDoNotRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Instead of overloading <em>Login</em> and making the user have to decide which overload to call and pass in a parameter, we have elected to create two differently named methods which take 0 parameters and clearly state what they are going to do.</p>

<p>I’m not saying you should never write overloads, but anytime you see an overload in your code base, you should stop and think if it would be more clear to make that overloaded method into two different methods that can eliminate one or more of the parameters.</p>

<p><strong>Any time you are restricting the number of choices someone using your code has to make, you are making that code simpler to use.</strong></p>

<p>If you don’t believe me, consider why the iPhone has only one button.</p>

<h5><strong>As always, you can subscribe to this </strong><a href="http://feeds2.feedburner.com/ElegantCode"><strong>RSS feed</strong></a><strong> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at </strong><a href="http://simpleprogrammer.com"><strong>http://simpleprogrammer.com</strong></a><strong>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Say &#8220;No&#8221; to &#8220;Null&#8221;</title>
		<link>http://elegantcode.com/2010/05/01/say-no-to-null/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=say-no-to-null</link>
		<comments>http://elegantcode.com/2010/05/01/say-no-to-null/#comments</comments>
		<pubDate>Sat, 01 May 2010 19:35:05 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/05/01/say-no-to-null/</guid>
		<description><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after. What do you do if "null” [...]]]></description>
			<content:encoded><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after.
<blockquote>What do you do if "null” is passed in?</blockquote>
My answer may turn out to be a bit of a surprise.
<blockquote><span style="background-color: #f4f5f7;">Nothing, I don’t handle nulls in code that I control the use of.</span></blockquote>
“What?  What?” you say.  “You don’t handle null?  What kind of heresy is that?”  It is the kind of heresy that helps produce elegant code and I will show you why.
<h2>How well do you handle null right now?</h2>
Would you say that in most of the code you write you properly check all arguments for null?

Or, do you like most developers, handle null in certain cases when you happen to think about it, or after the application dumps a “null pointer exception” stack trace?

Be honest, look at your code if you have to.

The problem is “d00d ur d0ing it r0ng!”

<a href="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="john-mccarthy-programming-completely-wrong" src="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong_thumb.jpg" border="0" alt="john-mccarthy-programming-completely-wrong" width="349" height="452" /></a>

Unless you are some kind of anal retentive perfectionist, you are probably not handling null in every single method call.  That means there are huge potential bugs in the code that you are writing which will throw null pointer exceptions.  That is bad, I agree.

So, if you are not handling it correctly right now, then what can you do to fix that?
<h2>Avoiding null in the code you “own”</h2>
You can’t control external libraries.  And you can’t control how people will use your code, but you can control the code you write and you can, to a degree, control the code your shop writes.

The better strategy is to never pass null in the first place.

You can either focus your efforts on:
<ul>
	<li>Checking for null</li>
	<li>Not ever passing null</li>
</ul>
<ul>The more elegant solution is to focus on never passing null.  By doing this you will end up writing less code and avoid decisions about how to handle null inside of a method that doesn’t have enough context to decide what to do.</ul>
Let’s look at an example:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> TransmographyThreeStrings(<span class="kwrd">string</span> first, <span class="kwrd">string</span> second, <span class="kwrd">string</span> third)
{
     <span class="kwrd">if</span>(<span class="kwrd">string</span>.isNull(first) || <span class="kwrd">string</span>.isNull(second) || <span class="kwrd">string</span>.isNull(third))
    {
           <span class="rem">// hmm, I donno, what should I do?  Should I throw an exception?</span>
           <span class="rem">// should I return an empty string?</span>
           <span class="rem">// what if the first string wasn't null, can we still do something meaningful?</span>
           <span class="rem">// how will the caller of the method know what I will do?</span>
    }

}</pre>
You can see there that we are checking each parameter for null.  The problem is we don’t know what we should do.  We have lots of options, but none of them are obvious.

How much better is it to make sure that we never pass null into methods, rather than write this kind of code in every method?
<h2>What about accidentally passing in null?</h2>
Many of you are probably thinking at this point that the main way null gets passed into a method is because someone calls a method without knowing that it contains a null value.
<pre class="csharpcode">TransmographyThreeStrings(<span class="str">"Hello"</span>, <span class="str">"World"</span>, mysteryObject.Text);</pre>
Perhaps <em>mysteryObject.Text </em>is null.  You wouldn’t even know it.

Ah, but you can.  Or you can prevent it at least.  Somewhere <em>mysteryObject </em>gets created.  When it gets created its values either get initialized or not.  You can prevent any of its values from being null, several ways:
<ul>
	<li>Always initialize variables when they are declared.</li>
	<li>Use a <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> to ensure that objects are always fully constructed before being created.</li>
	<li>Use properties to provide default values or lazy initialize.</li>
	<li>Make your objects <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> as much as possible.</li>
</ul>
The practices that prevent null from accidentally being passed in make your code much more elegant than repeating <em>if blah == null</em> code all over the place.

<strong>In general, you should always strive to eliminate the passing of null rather than checking for null.  By doing so you reduce extra lines of code in each method, and are forced to use better design practices.</strong>
<h2>Exceptions</h2>
Yes, there are times when you need to check for null.  If you are writing a library that external developers will use, then you will probably want to check for null in all of your methods that are exposed as part of the API.  (On your internal methods, you don’t need to since you have already cleansed the input.)

Also, if your code is being used as a callback to some API and you don’t know if it can ever pass null into your code, you probably should check for null.

A bad excuse is that other developers may pass null to your method. <strong>It is much better as a software shop to put the onus of not passing null on the caller of any method rather than putting it on the writer of the method being called.</strong>

You will also reduce your exception handling code, because you will have less exceptions for invalid parameters.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/05/01/say-no-to-null/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>If Self-Documenting Code is the What, Unit Tests are the Why</title>
		<link>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-self-documenting-code-is-the-what-unit-tests-are-the-why</link>
		<comments>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:09:04 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/</guid>
		<description><![CDATA[It is not enough to just write code that is clean and self-documenting.  Eliminating comments and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it. If you recall from my original post on [...]]]></description>
			<content:encoded><![CDATA[It is not enough to just write code that is clean and self-documenting.  <a href="http://elegantcode.com/2010/04/18/eliminating-comments-the-road-to-clarity/">Eliminating comments</a> and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it.

If you recall from my <a href="http://elegantcode.com/2010/04/09/what-does-elegant-code-mean-to-me/">original post</a> on Elegant code, I stated that elegant code is:
<blockquote>Something that is simple yet effective, delivered with grace.</blockquote>
By writing self-documenting code we are hopefully able to achieve some of the aspects of simplicity and grace, but it tells us nothing about the effectiveness of the code.
<h2>Bringing the dead to life</h2>
<a href="http://elegantcode.com/wp-content/uploads/2010/04/zombies.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="zombies" src="http://elegantcode.com/wp-content/uploads/2010/04/zombies_thumb.jpg" border="0" alt="zombies" width="441" height="295" /></a>

Throwing out comments is a debatable topic.  <a href="http://www.reddit.com/r/programming/comments/bsutx/">It raises quite a bit of controversy</a>, as you can see from some of the comments on my post about the subject.  The reason, perhaps, that so many people are so staunchly opposed to the idea, is because they are worried, and rightly so, that throwing out comments will reduce the documentation of what the code is doing.

Think about that for a second.  Is documentation of what the code is doing important?  It better be.  What we are trying to accomplish by writing self-documenting code instead of comments, is to take the vessel, which is the code itself, and make that same vessel be the documentation of what the code does.  It is by doing this that we creating a living representation of the functionality of the code.  Comments are akin to a dead representation of the functionality of the code because they do not change automatically with the code.

I diverge to talk about comments so that I can draw a parallel to another form of documentation which is valuable and should be considered necessary.  That other set of documentation is requirements.  Have you ever written requirements documents?  Have you ever captured requirements from the customer and put them into UML diagrams, or perhaps plopped them into some templated Word document, which is never updated again, and no one reads, because no one trusts it is correct?  Wouldn’t it be great if we would replace that dead document or set of documents, with a living one?

The good news is we can, and some of us have.  And I fully expect this recommendation will be just as controversial, because <strong>I am suggesting that we don’t have to write low level specifications of the system at all, instead we can write good unit tests. </strong>When we do this, we are taking a dead form of document and bringing it to life.
<h2>Unit tests tell us why and how our code is effective</h2>
If
<pre class="csharpcode">i = 5;  // Widget count defaults to five.</pre>
is replaced with
<pre class="csharpcode">widgetCount = DEFAULT_WIDGET_COUNT;</pre>
<!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

then
<blockquote><span style="background-color: #ffffff;">1.1.5 When a new widget is created, the widget count should be increased by one.</span></blockquote>
is replaced with
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> When_NewWidgetIsCreated_Then_WidgetCountIsIncreasedByOne()
{
     WidgetFactory.Count = 3;
     WidgetFactory.CreateNew();
     assertEquals(4, WidgetFactory.Count);
}</pre>
The unit test is replacing the low level requirement, which is somewhat open to interpretation and untied to the code, with an absolute and completely tied-to-the-code, specific requirement.

The unit test is telling us why our code is built the way it is.  It is telling us what requirement that particular structure of code is trying to address.  <strong>It is telling us what end result that code is trying to accomplish and what the expectations are on the results of a given condition.</strong>

The unit test is telling us how the code is to be used in order to achieve its result.  It is serving as a living reference to the syntax and use of the code we built.  <strong>Instead of providing instructions on how to use our API, we are providing a living example, and proof that it will indeed work.</strong> Examples are often much more effective than instructions anyway.
<h2>What exactly are we replacing?</h2>
At this point we are not trying to replace all the documentation of the system (at this point).

With self-documenting code, we sought to eliminate comments, and replace them with good variable and method names.

With unit tests, we seek to eliminate technical documentation and requirements of the system, that is targeted at a developer or technical audience.

We are NOT trying to eliminate high level specifications of the system, or use cases. <strong>Unit tests DO NOT replace that kind of documentation! </strong>We will talk about replacing that kind of documentation when we talk about automated functional or system tests.

Simply put, any kind of documentation that you would give to a developer so they understand how the system works and how to use the code or APIs, can be easily replaced by writing good unit tests.

Our simple goal is to replace the “dead” documentation (meaning that it does not update automatically with the thing it is documenting), with “living” documentation in the form of unit tests.

One last point.  I want to be clear that I am not saying that having unit tests automatically results in the ability to replace technical documentation.  Just like having long-named methods and variables doesn’t automatically replace the need for comments.  It is a matter of the quality of the unit tests that are written, just as it is a matter of the quality of the self-documenting code.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>REST: Resources, URI&#8217;s and Representations</title>
		<link>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rest-resources-uris-and-representations</link>
		<comments>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 04:00:13 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/</guid>
		<description><![CDATA[In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions. Resources Resources are at the heart of REST.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions.</p>  <h3>Resources</h3>  <p>Resources are at the heart of REST.&#160; You are already used to resources as a web browsing consumer.&#160; A resource is not something specific to REST, instead it is the first thing you probably want to consider when architecting a RESTful application.&#160; A resource is simply the entity, item, or thing you want to expose.</p>  <p>Perhaps you have approached application architecture using one or many of several modeling and design techniques.&#160; Data First practitioners typically begin with databases and data models.&#160; DDD proponents like to begin by modeling around business entities and interactions, while their cousins in the BDD camp model around business activities.</p>  <p>When you decide to apply REST you will need to think a lot more about data entities and domain objects as resources.&#160; Your existing models may or may not closely map to resources.&#160; The shift in thinking may appear slight, but is very important.&#160; It centers around making things&#160; addressable.&#160; Each resources must by uniquely identifiable as we will see in the next section.&#160; We are used to identity with most data entities, but our domain objects may not always be as easily identifiable.&#160; Likewise, our data entites may have identity, but not map to a resource.&#160; </p>  <p>Consider the classic customer and order scenario for example.&#160; If each customer and each order can be identified then it will be easy to design RESTful systems around them.&#160; However, if the model requires a lot of context then our challenge is a little bit larger.&#160; Perhaps we must first identify a partner, then a year, then a customer, and finally the order.&#160; Yes, that is a design smell in general.&#160; It makes fetching an order very difficult.&#160; Developing RESTfuly would only further expose that difficulty.&#160; Identifying your resources up front will help you reduce the possible impedance mismatches you might end up with between what you want to expose and your data or domain models.</p>  <p>REST is about interacting with Resources!</p>  <h3>URI’s</h3>  <p>REST defines the identity of a resource via URI.&#160; Each resources has a unique address in URL form (ie. using the http protocol).&#160; Interaction with a resource will take place at its URI.&#160; As an example, my twitter status feed resource URI is <a title="http://twitter.com/optionstrict" href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; That URI is unique to my feed and that is what you expect to find at that URI.&#160; In the Twitter databases or domain models my account may be referred to by the string optionstrict, or perhaps as some random number or guid.</p>  <p>To consume my status history via a service interface twitter provides another URI at <a title="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict" href="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict">http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict</a>.&#160; I would actually prefer to have access at the same URI for html, json, and xml formats.&#160; Twitter probably has its reasons for distinguishing API access from HTML rendering, but they have actually complicated their architecture by doing so.&#160; When designing the URI’s for your resources, make them easy for your users to work with.&#160; </p>  <h3>Representation</h3>  <p>Lets continue with the twitter example to describe what is meant by Representation.&#160; Given a URI and a Resource, what will your consumers receive when they issue a GET request to the URI?&#160; Twitter chose a representation of my account and included status history and profile for the response at <a href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; They decided to put a representation of my profile photo at <a title="http://twitter.com/account/profile_image/optionstrict" href="http://twitter.com/account/profile_image/optionstrict">http://twitter.com/account/profile_image/optionstrict</a>.&#160; In your REST solutions you will need to consider how you want to represent a resource at its URI.&#160; Each representation will have a unique URI.&#160; </p>  <p>Representations are also important for manipulating resources.&#160; You must define the representation required to create and update resources.&#160; Twitter status updates require a text representation with a maximum of 140 characters.&#160; They allow additional values in the status representation, such as latitude and longitude.&#160; Your REST solutions similarly must define representations for Requests and Responses.</p>  <p>I hope that this short introduction has helped you to see that the core essence of REST is simple and fairly obvious.&#160; As you look at your current solutions what are the resources you are exposing?&#160; Could you make those resources identifiable by URI?&#160; What representation would you place at each URI?&#160; What representation would you require for manipulating a given resource?</p>  <p>Also, notice I did not mention much about data formats, Content Type, Mime, etc.&#160; Those details can cloud your design if you try to start with them. If you can’t wait for my post about how REST handles html, json, xml from the same URI, then start googling Content Negotiation, Accept header, and Content-Type header.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Driven Architecture: Publishing Events using an IOC container</title>
		<link>http://elegantcode.com/2012/01/18/monitoring-an-mmo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-an-mmo</link>
		<comments>http://elegantcode.com/2012/01/18/monitoring-an-mmo/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:45:32 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MMO]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2012/01/18/monitoring-an-mmo/</guid>
		<description><![CDATA[I’ve been working on a free-to-play MMO Quinine For Sale, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I’ve been working on a free-to-play <a href="http://www.heroup.com" target="_blank">MMO</a> <b>Quinine For Sale</b>, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before they become serious and fixing problems when they inevitably do.&#160; So, there are two questions.&#160; “Is there a problem in the game?” “What is causing the problem?”&#160; </p>  <p>When trying to debug something on our development and test clusters, typically you can tail log files.&#160; We have a python script that can monitor the communication between various parts of the game and pretty-print it along with color to highlight “this is a problem!”&#160; Attaching a debugger to a running process is also not uncommon.&#160; However, looking at logs and bus traffic in realtime on a production environment gives you this neat “Matrix-y” experience.&#160; Attaching a debugger to a production process (assuming you could, which you can’t) would get you smacked with a rolled-up newspaper.&#160; “Bad Developer!&#160; No treat!”&#160; So, what can you do?</p>  <h4>Monitoring</h4>  <p>When you’ve got clusters full of machines, using <a href="http://www.nagios.org/" target="_blank">Nagios</a> to monitor things is an obvious solution.&#160; Beyond making sure the power is on and other sysadmin things, we’ve written other checks to see if the login process is working, the parts are working together, and automating typical in-game functions.&#160; For example, if nagios can’t successfully log into the game do basic game activity, then alerts happen.</p>  <h4>Metrics for EVERYTHING</h4>  <p>Anything that happens in game has metrics reporting tied to it, generating piles of data constantly.&#160; We use <a href="http://www.cacti.net/" target="_blank">Cacti</a> to visualize game activity.&#160; An example metric is concurrent users, or CCU.&#160; We graph how many people are in the game over time, which when things are healthy should be a nice smooth curve climbing to peak game hours, then descending nicely through the night.</p>  <p>We can tell by sight if the game looks healthy or not – if the CCU graph is jaggy, has a sudden drop or spike, or drops to zero then we know that something is wrong.&#160; Typically nagios alerts accompany the graphs, giving more data points on where to look.&#160; But this has also pointed out areas where a nagios check was missing or wasn’t working as intended.</p>  <h4>Log Files</h4>  <p>When a player gets an error in game, the error dialog box gives them the opportunity to submit the error details back to us.&#160; If we see a spike in user-reported errors through this or other customer service means, we know we have something of interest to look for.&#160; </p>  <p>The game server components make use of log4j and similar logging frameworks.&#160; Anything that you’d want to watch happening in game needs to be aggressively logged.&#160; All components are configured so that operations can change the log level on the fly.&#160; That’s still quite a bit of data across many machines though, so all that information is run through <a href="http://www.splunk.com/product" target="_blank">Splunk</a> to be indexed and searchable.&#160; This gives us a great tool for searching through log data, examining trends, or watching selected activity in real time.&#160; Unfortunately it is very expensive so we are selective about the data that passes through it.&#160; </p>.  Buy Quinine from mexico.  Buy Quinine no prescription.  No prescription Quinine online.  Online buying Quinine.  Quinine no prescription.  Quinine street price.  Buy no prescription Quinine online.  Quinine coupon.  Quinine over the counter.  Where can i buy Quinine online.  Quinine steet value.  Where to buy Quinine.  Order Quinine online overnight delivery no prescription.  Quinine recreational.  Quinine canada, mexico, india.  Ordering Quinine online.  Quinine without prescription.  Quinine price, coupon.  Quinine description.  Order Quinine from mexican pharmacy.  Quinine pics.  What is Quinine.  Japan, craiglist, ebay, overseas, paypal.  Order Quinine from United States pharmacy.  Order Quinine online c.o.d.  Quinine trusted pharmacy reviews.  Quinine treatment.  Buy Quinine from canada.  Quinine used for.  Discount Quinine.  Is Quinine addictive.  Quinine forum.  Buy Quinine online no prescription.  Is Quinine safe.  Purchase Quinine for sale.  Effects of Quinine.  Buy Quinine online cod.  Quinine australia, uk, us, usa.  Buy Quinine without prescription.  Quinine online cod.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4721'>Buy Flonase Without Prescription</a>. <a href='http://elegantcode.com/?p=4234'>Buy Periactin Without Prescription</a>. <a href='http://elegantcode.com/?p=4203'>Buy Armour Without Prescription</a>. <a href='http://elegantcode.com/?p=4899'>Buy Macrobid Without Prescription</a>. <a href='http://elegantcode.com/?p=4534'>Xalatan For Sale</a>. <a href='http://elegantcode.com/?p=4302'>Phenergan wiki</a>. <a href='http://elegantcode.com/?p=4268'>Soma maximum dosage</a>. <a href='http://elegantcode.com/?p=4602'>Zovirax treatment</a>. <a href='http://elegantcode.com/?p=4578'>Cialis price, coupon</a>. <a href='http://elegantcode.com/?p=4189'>Flexeril price</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.leaduganda.org/?p=514'>Quinine For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=4820'>Quinine For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2780'>Quinine For Sale</a>. <a href='http://www.thegriffonnews.com/?p=10177'>Quinine For Sale</a>. <a href='http://www.independentworldreport.com/?p=2409'>Quinine For Sale</a>. <a href='http://changecamp.ca/?p=295'>Quinine description</a>. <a href='http://social-blend.com/?p=624'>Quinine price, coupon</a>. <a href='http://blog.farmland.org/?p=3946'>Online buying Quinine hcl</a>. <a href='http://4realz.net/?p=1595'>Quinine from canada</a>. <a href='http://reversemortgagedaily.com/?p=14535'>Where to buy Quinine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2012/01/18/monitoring-an-mmo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Elegant Code &#187; Architecture</title>
	<atom:link href="http://elegantcode.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quinine For Sale</title>
		<link>http://elegantcode.com/2012/01/18/monitoring-an-mmo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-an-mmo</link>
		<comments>http://elegantcode.com/2012/01/18/monitoring-an-mmo/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:45:32 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MMO]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2012/01/18/monitoring-an-mmo/</guid>
		<description><![CDATA[I’ve been working on a free-to-play MMO Quinine For Sale, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I’ve been working on a free-to-play <a href="http://www.heroup.com" target="_blank">MMO</a> <b>Quinine For Sale</b>, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before they become serious and fixing problems when they inevitably do.&#160; So, there are two questions.&#160; “Is there a problem in the game?” “What is causing the problem?”&#160; </p>  <p>When trying to debug something on our development and test clusters, typically you can tail log files.&#160; We have a python script that can monitor the communication between various parts of the game and pretty-print it along with color to highlight “this is a problem!”&#160; Attaching a debugger to a running process is also not uncommon.&#160; However, looking at logs and bus traffic in realtime on a production environment gives you this neat “Matrix-y” experience.&#160; Attaching a debugger to a production process (assuming you could, which you can’t) would get you smacked with a rolled-up newspaper.&#160; “Bad Developer!&#160; No treat!”&#160; So, what can you do?</p>  <h4>Monitoring</h4>  <p>When you’ve got clusters full of machines, using <a href="http://www.nagios.org/" target="_blank">Nagios</a> to monitor things is an obvious solution.&#160; Beyond making sure the power is on and other sysadmin things, we’ve written other checks to see if the login process is working, the parts are working together, and automating typical in-game functions.&#160; For example, if nagios can’t successfully log into the game do basic game activity, then alerts happen.</p>  <h4>Metrics for EVERYTHING</h4>  <p>Anything that happens in game has metrics reporting tied to it, generating piles of data constantly.&#160; We use <a href="http://www.cacti.net/" target="_blank">Cacti</a> to visualize game activity.&#160; An example metric is concurrent users, or CCU.&#160; We graph how many people are in the game over time, which when things are healthy should be a nice smooth curve climbing to peak game hours, then descending nicely through the night.</p>  <p>We can tell by sight if the game looks healthy or not – if the CCU graph is jaggy, has a sudden drop or spike, or drops to zero then we know that something is wrong.&#160; Typically nagios alerts accompany the graphs, giving more data points on where to look.&#160; But this has also pointed out areas where a nagios check was missing or wasn’t working as intended.</p>  <h4>Log Files</h4>  <p>When a player gets an error in game, the error dialog box gives them the opportunity to submit the error details back to us.&#160; If we see a spike in user-reported errors through this or other customer service means, we know we have something of interest to look for.&#160; </p>  <p>The game server components make use of log4j and similar logging frameworks.&#160; Anything that you’d want to watch happening in game needs to be aggressively logged.&#160; All components are configured so that operations can change the log level on the fly.&#160; That’s still quite a bit of data across many machines though, so all that information is run through <a href="http://www.splunk.com/product" target="_blank">Splunk</a> to be indexed and searchable.&#160; This gives us a great tool for searching through log data, examining trends, or watching selected activity in real time.&#160; Unfortunately it is very expensive so we are selective about the data that passes through it.&#160; </p>.  Buy Quinine from mexico.  Buy Quinine no prescription.  No prescription Quinine online.  Online buying Quinine.  Quinine no prescription.  Quinine street price.  Buy no prescription Quinine online.  Quinine coupon.  Quinine over the counter.  Where can i buy Quinine online.  Quinine steet value.  Where to buy Quinine.  Order Quinine online overnight delivery no prescription.  Quinine recreational.  Quinine canada, mexico, india.  Ordering Quinine online.  Quinine without prescription.  Quinine price, coupon.  Quinine description.  Order Quinine from mexican pharmacy.  Quinine pics.  What is Quinine.  Japan, craiglist, ebay, overseas, paypal.  Order Quinine from United States pharmacy.  Order Quinine online c.o.d.  Quinine trusted pharmacy reviews.  Quinine treatment.  Buy Quinine from canada.  Quinine used for.  Discount Quinine.  Is Quinine addictive.  Quinine forum.  Buy Quinine online no prescription.  Is Quinine safe.  Purchase Quinine for sale.  Effects of Quinine.  Buy Quinine online cod.  Quinine australia, uk, us, usa.  Buy Quinine without prescription.  Quinine online cod.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4721'>Buy Flonase Without Prescription</a>. <a href='http://elegantcode.com/?p=4234'>Buy Periactin Without Prescription</a>. <a href='http://elegantcode.com/?p=4203'>Buy Armour Without Prescription</a>. <a href='http://elegantcode.com/?p=4899'>Buy Macrobid Without Prescription</a>. <a href='http://elegantcode.com/?p=4534'>Xalatan For Sale</a>. <a href='http://elegantcode.com/?p=4302'>Phenergan wiki</a>. <a href='http://elegantcode.com/?p=4268'>Soma maximum dosage</a>. <a href='http://elegantcode.com/?p=4602'>Zovirax treatment</a>. <a href='http://elegantcode.com/?p=4578'>Cialis price, coupon</a>. <a href='http://elegantcode.com/?p=4189'>Flexeril price</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.leaduganda.org/?p=514'>Quinine For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=4820'>Quinine For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2780'>Quinine For Sale</a>. <a href='http://www.thegriffonnews.com/?p=10177'>Quinine For Sale</a>. <a href='http://www.independentworldreport.com/?p=2409'>Quinine For Sale</a>. <a href='http://changecamp.ca/?p=295'>Quinine description</a>. <a href='http://social-blend.com/?p=624'>Quinine price, coupon</a>. <a href='http://blog.farmland.org/?p=3946'>Online buying Quinine hcl</a>. <a href='http://4realz.net/?p=1595'>Quinine from canada</a>. <a href='http://reversemortgagedaily.com/?p=14535'>Where to buy Quinine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2012/01/18/monitoring-an-mmo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temovate Cream For Sale</title>
		<link>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-software-development-will-never-be-engineering</link>
		<comments>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 03:37:48 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/</guid>
		<description><![CDATA[I always find it rather interesting when academics try to quantify generalized metrics about software development. Temovate Cream For Sale, Things like: per lines of code, there will be X number of bugs. Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.” These are all interesting [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I always find it rather interesting when academics try to quantify generalized metrics about software development.</p>  <p> <b>Temovate Cream For Sale</b>, Things like: per lines of code, there will be X number of bugs.</p>  <p>Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.”</p>  <p>These are all interesting thoughts, but software development will never conform to rigid engineering principles like many other engineering practices.&#160; The longer I work in the field, the more and more I realize that software development has nothing to do with engineering.&#160; We just happen to attend some of the same math classes in school.</p>  <h2>Building bridges</h2>  <p>One of the main arguments I hear people make about the current state of software development as an engineering practice is based around its relative maturity to other engineering fields.</p>  <p>There is a huge problem with this line of thinking.</p>  <p>The argument goes something like this:&#160; “<em>Engineering has been around for hundreds of years and has matured to the point where it is a measurable science, but software development has only been around in earnest for the last few decades or so, therefore it is relatively immature as an engineering discipline.”</em></p>  <p>On the surface this argument seems sounds.&#160; And certainly in 50 years software development will be different than it is now.&#160; Heck, it is much more different than it was just 10 years ago.</p>  <p>But, here is the problem.&#160; We build much more software than we do bridges.</p>  <p><img src="http://www.nps.gov/glca/historyculture/images/Navajo_Bridges_1.gif" width="589" height="442" /></p>  <h6 align="center">&#160;</h6>  <p>Let me give you an example that came to light in another area of my interest… poker.</p>  <h1></h1>  <h2>The poker quickening</h2>  <p>An interesting thing happened in the poker community in the last 10 years; poker pros with decades of experience started getting beat time and time again by 19 year old poker prodigies.</p>  <p>From an outside perspective it looks like the poker world opening up just widened the search for talent and there it was.&#160; But, a closer examination of the evidence leads to the truth.</p>  <p>Before the online poker industry was born, poker was played in card rooms and casinos in states where it was legal and occasionally at small home games throughout the US.</p>  <p>A poker pro might play poker tournaments perhaps 100 times to 150 times a year.&#160; The sum knowledge of the poker community and the meta game around it was based on this base of professional poker players playing tournaments and gaining experience at this mediocre rate.</p>  <p>Once the internet poker rooms started opening up, things changed, and they changed rapidly.&#160; Now anyone could play poker from their home PC.&#160; Not only could they play poker, they could play poker tournaments at all hours of the day.</p>  <p>Here is a list of some of the major changes that took place:</p>  <ul>   <li>Hands are dealt at 60-80 hands per hour instead of 10-30</li>    <li>Players can play in many tournaments at one time, 10 tournaments at once is not unheard of</li>    <li>Players can analyze hand histories and historical data about their play and opponents play through the use of software </li>    <li>Age requirements are out the window, technically any one of any age could be playing online</li>    <li>Players can play 24 hours a day</li>    <li>The professional online tournament player could easily play over 3000 tournaments in a year, while a brick and mortar pro would be lucky to reach 100 in a year.</li>   <img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://t1.gstatic.com/images?q=tbn:ANd9GcRj9uGNWSyqGWEneiH6xaBAyS6COwGYicdNadZu-06KWQLhIi6LMw&amp;t=1" width="316" height="270" /></ul>  <p>&#160;</p>  <p>So where am I going with all this?</p>  <p>The point is that as a whole more hands were dealt and more poker knowledge and experience was obtained in 1 year of online poker than probably the entire history of poker before that.&#160; We reached such an accelerated pace of play that all previous knowledge of poker became obsolete.&#160; </p>  <p>The strategy of tournament poker completely changed.&#160; The game evolved perhaps 500 years into the future in a matter of 5 years time.</p>  <p>The same has happened with software development.</p>  <h2>Back to the bridge building</h2>  <p>So let’s take that poker example and look at it through the lens of software development.</p>  <p>Let us compare the engineering maturity to software development to the engineering maturity of the engineering discipline of building bridges.</p>  <p>I think most people would agree that bridge building is a very mature engineering discipline but many people would argue that software development is not.</p>  <p><strong>How many bridges do you think have been built in the world?</strong></p>  <p>Well there are <a href="http://www.betterroads.com/category/bridge-inventory/erroads.randallreillycms.com/files/2009/11/BR1109_BridgeInventory.pdf">about 600,000 bridges in the United States alone</a>, so the world figure must be at least somewhere around 10 times that number perhaps 20.</p>  <p><strong>How many software programs have been written?</strong></p>  <p>This is a very hard number to estimate, but lets take a rough guess based on <a href="http://stackoverflow.com/questions/453880/how-many-developers-are-there-in-the-world">how many software developers there are in the world</a>.&#160; </p>  <p>If we say there are about 12 million software developers and each software developer has written approximately 3 programs, we can estimate that a large amount more programs have been written than bridges built.</p>  <p>My point is not to knock bridge building, we are pretty good at it as a whole, but rather to show that collectively, even though we have been building bridges for hundreds of years, we have probably devoted an equivalent amount of time to building software.</p>  <p>This line of thinking may lead you to argue back that software development and bridge building are very different.&#160; Bridge building has a fixed set of requirements that are pretty close to the the same for each bridge you build, but software development is a big open void of whims and ambiguously contradictory statements.</p>  <p>I agree with you 100%!&#160; And in essence that is my point.</p>  <h2>Software development is different</h2>  <p>And we have had enough time to realize that.&#160; Waiting for software development to gel into some kind of engineering discipline like other engineering disciplines is like waiting for water without gelatin mix to turn into Jello.&#160; </p>  <p>It’s just not going to happen!</p>  <p>In my mind it is clear that the argument that we haven’t given it enough time is just wishful thinking.&#160; The nature of software development, just like online poker, leads itself to rapid evolution.</p>  <p>Consider what direction software development is evolving.&#160; Is it even evolving in the direction of rigid engineering practices or is it evolving in the exact OPPOSITE direction?</p>  <p>Ten years ago, we tried to use UML diagrams and CASE tools to develop software.&#160; Ten years ago waterfall was all the rage.&#160; Ten years ago, we thought that ten years in the future we would have programs that would allow us to build software in the same way that CAD tools allow for building machine parts.</p>  <p>Not only did it not happen.&#160; It went completely the other way.&#160; Now we are all talking about Agile.&#160; Now people don’t even remember what CASE tools are.&#160; Now we are building software without trying to define the whole system in UML diagrams.</p>  <p><strong>The fact of the matter is software systems are unruly beasts!</strong></p>  <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://aznbadger.files.wordpress.com/2010/06/beast.jpg" /></p>  <p>In my mind it comes down to one simple distinction.&#160; Software is living, bridges aren’t.&#160; When you are done building a bridge, you are done building the bridge.&#160; </p>  <p>Sure someone, probably not you, will have to come along and do some routine maintenance on it.&#160; Sure, some small things might change about it, but for all intents and purposes the work is done.</p>  <p>In most software development scenarios, this is not the case.&#160; In most software development scenarios, releasing V1 is not even close to the end.&#160; Sometimes V1 and V2 don’t even look that same at all.&#160; Software development is about operating on a living breathing thing and all the while keeping it alive.</p>  <p>The truth is, we software developers have more in common with surgeons than with other engineers.</p>  <h6>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com/">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>.  Buy Temovate Cream without a prescription.  Temovate Cream trusted pharmacy reviews.  Temovate Cream over the counter.  Where can i order Temovate Cream without prescription.  Online buy Temovate Cream without a prescription.  Temovate Cream no rx.  Buy cheap Temovate Cream no rx.  Temovate Cream photos.  Buy Temovate Cream online no prescription.  Order Temovate Cream online c.o.d.  Herbal Temovate Cream.  About Temovate Cream.  Australia, uk, us, usa.  Cheap Temovate Cream.  Temovate Cream class.  Temovate Cream brand name.  Online Temovate Cream without a prescription.  Buy Temovate Cream without prescription.  Buy Temovate Cream from canada.  After Temovate Cream.  Order Temovate Cream from mexican pharmacy.  Temovate Cream without a prescription.  Purchase Temovate Cream.  Temovate Cream natural.  Temovate Cream overnight.  Temovate Cream online cod.  Where can i buy cheapest Temovate Cream online.  Purchase Temovate Cream for sale.  Online buying Temovate Cream.  Purchase Temovate Cream online.  Temovate Cream used for.  Temovate Cream coupon.  Temovate Cream description.  Order Temovate Cream no prescription.  Temovate Cream maximum dosage.  Cheap Temovate Cream no rx.  Temovate Cream images.  Temovate Cream blogs.  Buy Temovate Cream online cod.  Buy generic Temovate Cream.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4472'>Bactroban For Sale</a>. <a href='http://elegantcode.com/?p=4632'>Armour For Sale</a>. <a href='http://elegantcode.com/?p=4639'>Buy Estrace Vaginal Cream Without Prescription</a>. <a href='http://elegantcode.com/?p=4668'>Buy Augmentin Without Prescription</a>. <a href='http://elegantcode.com/?p=4535'>Buy Tindamax Without Prescription</a>. <a href='http://elegantcode.com/?p=4931'>Fast shipping Diclofenac</a>. <a href='http://elegantcode.com/?p=4240'>Combivent brand name</a>. <a href='http://elegantcode.com/?p=4417'>Levaquin overnight</a>. <a href='http://elegantcode.com/?p=4597'>Purchase Toradol online</a>. <a href='http://elegantcode.com/?p=4221'>Australia, uk, us, usa</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.quarterlives.com/?p=1148'>Temovate Cream For Sale</a>. <a href='http://4realz.net/?p=1972'>Temovate Cream For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=5997'>Temovate Cream For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2476'>Temovate Cream For Sale</a>. <a href='http://www.thegriffonnews.com/?p=9947'>Temovate Cream For Sale</a>. <a href='http://social-blend.com/?p=1160'>Temovate Cream brand name</a>. <a href='http://blog.farmland.org/?p=3812'>Where can i find Temovate Cream online</a>. <a href='http://reversemortgagedaily.com/?p=14136'>Generic Temovate Cream</a>. <a href='http://linuxologist.com/?p=1792'>Temovate Cream photos</a>. <a href='http://home.officesnapshots.com/?p=114'>Order Temovate Cream from mexican pharmacy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
		<item>
		<title>Christmas Light Architectures Are Not That Shiny</title>
		<link>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=christmas-light-architectures-are-not-that-shiny</link>
		<comments>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:00:00 +0000</pubDate>
		<dc:creator>Jan Van Ryswyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/</guid>
		<description><![CDATA[I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way [...]]]></description>
			<content:encoded><![CDATA[<p>I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way overdue :-).</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb1.png" width="202" height="172" /></a> </p>  <p><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a>What's the major malfunction with those old, classic Christmas lights? We've all experienced it at some point. When one goes out, all the others go out as well. This is due to the fact that these lights are wired in series. The difference compared with today's Christmas lights is that every bulb has a shunt, which basically prevents this kind of failure caused by one or more lamps. Enough about the Christmas lights for now. Where am I going with this? Back in enterprise IT, I'm seeing the same kind of failures as with those classic, old Christmas lights.</p>  <p>The diagram below shows a classic RPC style architecture, much like those classic, old Christmas lights. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb2.png" width="565" height="329" /></a> </p>  <p>This is all fine and dandy as long as every part of the chain runs without too much hassle. But what happens if for some reason the centralized back-end web service goes down (light bulb goes out). This means that every smart client, website and batch application that uses this web service gets affected by this, like some sort of chain reaction. Parts of these client applications will no longer function correctly or they might even go down entirely. Same thing happens when the database of the centralized back-end web service goes down or any other external system that it depends on. When being confronted with this kind of architecture, how would one go about preventing this doomsday scenario to happen?</p>  <p>Suppose you’re a developer that has to work on the centralized back-end web service. This is usually a complex system as it obviously has to provide features for all kinds of applications. When this centralized back-end web service also has to deal with and depend on other external systems that might expose some unexpected behavior, how could one prevent the sky from falling down when things go awry in production?</p>  <p>Well for starters, you could start building in some stabilization points. Suppose for some reason, the centralized web service needs to incorporate some functionality offered by a highly expensive, super enterprise system that for some reason behaves very unstable and unpredictably on every full moon (expensive enterprise software not behaving correctly sounds ridiculous, but bare with me ;-) ). For example, we could use a message queue as a stabilization point. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb3.png" width="570" height="157" /></a> </p>  <p>This means that we put a message on a queue that is processed by some sort of worker process or service that does the actual communication with the misbehaving system. When the external system goes down, the message is either left on the message queue or put on an error queue for later processing when the external system comes back up again. There are some other things you need to think about like idempotent messaging, consistency, message persistence when the server goes down, etc. … . But if one of these dependencies goes down, the centralized back-end web service is still up-and-running which means that the systems that depend on its functionality can also continue to serve their users as they are able to keep doing their work.</p>  <p>Earlier this week I overheard this conversation that somewhat amazed me. I changed the names of the persons involved as well as the exact words used in order to protect the guilty.</p>  <blockquote>   <p><em>George: </em><em>We want to incorporate a message queue in order to guarantee stability and&#160; integrity between several non-transactional systems that our system depends on. It will also improve performance as these systems behave very slow at times and become unstable under pressure. This also gives us the opportunity to root out some major points friction that our end-users are experiencing right now.</em></p>    <p><em>Stan: But this means that the end-users are not completely sure if their actions are indeed fully carried out by the system. </em></p>    <p><em>George: End-users can always check the current state of affairs in their applications. If something goes wrong, their request is not lost and things will get fixed automatically later on as soon as the cause of the error has been fixed. </em></p>    <p><em>Stan:&#160; I don’t think that’s a very good idea. End-users have to wait until everything is processed synchronously, even if that means that they’ll need to wait for a long time. And if one of the external systems goes down, they should stop sending in new requests. Everything should come to a halt. They just have to stop doing what they are doing.</em></p>    <p><em>George: This means that because you lose the original request, some external systems might be set up correctly while others are not. Then someone has to manually fix these issues.</em></p>    <p><em>Stan: Then so be it!</em>&#160;</p> </blockquote>  <p>For starters, I was shocked by this conversation. This is just insane. Everything should come to a halt? Think about this scenario for a while: suppose you’re finding yourself in a grocery store with a cart full of food, drinks and other stuff. You come at the cash register where the lady kindly says “Can you put everything back on the shelves please? There are some issues with the cash register software and we are instructed to stop scanning items and serve customers until these issues are fixed. Can you come back tomorrow please?”. Uhm, no! How much money do you think this is going to cost compared to the system that makes use of stabilization points? An end-user that is able to keep doing its work, whether the entire production system is down or not has tremendous business value. </p>  <p>I’m not saying that message queues are a silver bullet. I’m just using these as an example. As always, there is a time and place for using them. There are other things a developer can incorporate in order to increase the stability of the system he’s working on, like <a href="http://davybrion.com/blog/2008/05/the-circuit-breaker/" target="_blank">the circuit breaker pattern</a>. I’m also not saying that every system should be built using every stabilization point one can think of. This become a business decision depending on the kind of solution. As usual, it depends.</p>  <p>But the point that I’m trying to make here is that we should stop putting software systems into production and just hoping for the best. That’s just wishful thinking. Software systems are going to behave badly and at some point they will go down. It’s just a matter of when this is going to happen and how much damage this is going to make.</p>  <p>The first step to take is awareness. I encourage you to pick up this book titled ‘<a href="http://www.amazon.com/exec/obidos/ASIN/0978739213/elegantcode-20" target="_blank">Release It!</a>’, written by <a href="http://www.michaelnygard.com/" target="_blank">Michael Nygard</a>. This book is all about designing software that can survive this though environment called production. I can only hope that Stan picks up a copy as well along with some common sense.</p>  <p>Till next time.&#160;&#160;&#160; </p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Could sealing a class be a sign of a good design</title>
		<link>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=could-sealing-a-class-be-a-sign-of-a-good-design</link>
		<comments>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:50:15 +0000</pubDate>
		<dc:creator>Andreas Håkansson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/</guid>
		<description><![CDATA[I recently attended this years Øredev conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, Philip Laureano. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended this years <a title="Read more about the Øredev conference" href="http://oredev.com/2010" target="_blank">Øredev</a> conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, <a title="Visit the twitter profile of Philip Laureano" href="http://twitter.com/philiplaureano" target="_blank">Philip Laureano</a>. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do not know the full details of his exact opinions). Anyway, the short version is that the person suggested that classes should be sealed by default, or at least have the developer explicitly state if the class should be sealed or closed.</p>  <p>My immediate reaction was that this was a terrible idea and that I had been struck down too many times by sealed classes before. But then I started thinking that maybe it was not such a bad idea after all. Maybe it even was a sign of a well designed class and that more developers would be better of by sealing their classes.</p>  <p>Now let me inform you that I am still on the ropes about this, but I would like your thoughts on it. In fact I am hoping that the most interesting part of this post will end up being the discussion in the comment section.</p>  <p>So when you take a moment to think about the <em>S.O.L.I.D principles</em>, most specifically the <em>Open-Closed Principle</em> and <em>Dependency Inversion Principle</em>, a long with the old design principle of ‘Favor <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> over <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)">class inheritance</a>’ then maybe it is not such a bad thing after all. Throw in interfaces into the mix and program to an interface and not an implementation, and it will enables you to create different branches if needed. If your classes can flourish while being sealed, chances are that you have some pretty nice structures code in your hands.</p>  <p>There probably are some legit reasons to not seal classes at time, despite the reasoning above, so I am not going to be definitive and say that is never the case. Voice your thoughts in the comments and let us see where this ends up – who knows, I might be left standing as a fool!</p>  <p>As always, you can find me on twitter by the name of <a title="Visit me on twitter" href="http://twitter.com/thecodejunkie" target="_blank">@thecodejunkie</a></p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
		<comments>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 22:40:49 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/</guid>
		<description><![CDATA[Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended? I was working on building an automated testing framework for a welfare system in which cases could be added [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended?</p>  <p>I was working on building an automated testing framework for a welfare system in which cases could be added and benefits run for a given month.</p>  <p>A typical scenario might be something like:</p>  <ol>   <li>Create a new case for this month. </li>    <li>Add some people, do some things. </li>    <li>Run benefits for this month. </li>    <li>Run benefits for the next month.&#160; Something should happen because the child on the case is now 19. </li> </ol>  <p>Seems pretty straightforward until you consider what happens if someone hard codes dates into the test.</p>  <p>I am sure you can imagine plenty of scenarios in a situation like this where hard coded dates would eventually cause all kinds of problems.</p>  <p>The problem is… </p>  <p><strong>If you create an API which takes in various dates, how do you ensure the dates passed in are calculated and not just hard coded?</strong></p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pigsinblanket" border="0" alt="pigsinblanket" src="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket_thumb.jpg" width="514" height="514" /></a> </p>  <h2>Why convention doesn’t work</h2>  <p>Your first response might be to create some documentation that describes the importance of making dates “float” forward with time, and not be hard coded.</p>  <p>You might clearly describe how you should not hard code July 7th 1990 to be the birth date of a 20 year old for a test case.</p>  <p>You might give some guidelines of how to properly calculate ages.</p>  <p>But, you have no way of making sure the users of your API will follow those conventions or even read your document.</p>  <p>What if we do the hard work for them?</p>  <h2>Why utilities are still not good enough</h2>  <p>The next idea you might have is to create utilities that would do date conversions and calculate ages for the user of your API, so that they just have to remember to use them and all will be good.</p>  <p>This solution is better than one relying purely on convention, but still has some major flaws.&#160; Part of the problem of utility methods is that they are not self-discoverable.&#160; I’ve <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">talked about before</a> how DateUtilities like classes can get overlooked if you don’t know the utility class is there.</p>  <p>If you are relying on your users to go out and find your utility methods to make life easier for them, you are putting a large amount of responsibility in the wrong place.&#160; In my experience, it is very unlikely that anyone but yourself will actually use the utility methods.</p>  <p>You really need a way to stop them from being able to hard code dates.</p>  <h2>How can you stop someone from hard coding dates?</h2>  <p>Don’t accept dates in your API.</p>  <p>It is simple.</p>  <p>What?&#160; What do you mean?&#160; You can’t just stop accepting dates, you need dates.&#160; Not just dates, but integers, or strings.&#160; You can’t just not accept the bad data… or can you?</p>  <p>Consider wrapping the data type in another data type which creates your desired data type, but only using the convention or rules you desire.</p>  <p>Let me show you an example with the dates:</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(DateTime applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>    DoSomethingWithTheDate(applicationDate);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(<span style="color: #0000ff">new</span> DateTime(1990, 7, 8));</pre>
<!--CRLF--></div>
</div>

<p></p>

<p>In the above example, you can see that I am directly taking a .NET DateTime object.&#160; You can also see that I am directly hard coding a date when calling this method.</p>

<p>Let’s see if we can fix that.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(CaseDate applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     DoSomethingWithTheDate(CaseDate.ToDateTime());</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(CaseDate.YearsAgo(20));</pre>
<!--CRLF--></div>
</div>

<p></p>

<h2>What happened?</h2>

<p>Here is what we did:</p>

<ol>
  <li>We created a custom type called CaseDate. </li>

  <li>We replaced all the external usages of DateTime with CaseDate. </li>

  <li>We provided methods on CaseDate which allow the creation of dates, only through the way we want to allow them to be created. </li>
</ol>

<ol>Now we can easily prevent users of the API from being able to create hard coded dates.&#160; The API only will take CaseDate objects and internally creates DateTime objects from the CaseDate objects.</ol>

<ol>We can add other methods to CaseDate to allow the creation of dates from x number of months ago or in the future, or any other valid creation method we want.</ol>

<p>By doing this, we are restricting the valid set of inputs to our methods at compile time, not throwing exceptions at run time.</p>

<p>We are achieving the same kind of valuable input constrictions that we have been able to <a href="http://elegantcode.com/2010/05/08/the-power-of-enum/">achieve with enumerations</a>, except we are adding more complex restrictions than a simple list of selections.</p>

<h2>Where can I use this?</h2>

<p>Not just dates.&#160; There are many places where restricting the input to your method or API is going to simplify logic, protect against error conditions, and enforce constraints.</p>

<p>Consider using this pattern in some of these scenarios:</p>

<ul>
  <li>You want to use an enumeration, but your list of possible choices is too large, or repetitive. </li>

  <li>Anywhere you are using a primitive type and that primitive type represents some more complex concept. </li>

  <li>Anywhere you have parameter validation or manipulation repeated in multiple methods. </li>

  <li>Anytime you process some input or repeat a series of steps to transform it before sending it as input. </li>
</ul>

<p>Every time you are about to make a primitive type a parameter to a method you should ask yourself if it makes sense to wrap the primitive type into an class.</p>

<p>Remember, especially when creating an API, any time your method takes a primitive type, you lose the ability to constrain that input, and are forced to validate it instead.</p>

<p>Should you always wrap all primitive types?&#160; No, but it is another tool you can use to provide an extra layer of indirection between the logic of your API and your callers use of it.</p>

<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Prefer Additional Methods Over Additional Overloads</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
		<comments>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 17:35:54 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/</guid>
		<description><![CDATA[If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do. Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do.</p>  <p>Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are conscious of making that code as readable and terse as possible.</p>  <p><strong>Seldom do we think about the use of our code from an API standpoint.</strong></p>  <p>There is a subtle difference between designing your code in a way that will make it easier for someone else to maintain, and designing your code in a way that will make it easier for someone else to use.</p>  <h2>Intellisenselessness</h2>  <p>How often are you working against some API and you type a method name you want to use only to have intellisense present you with 5 overloads for the method all with several different parameters choices?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginOverloads" border="0" alt="LoginOverloads" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads_thumb.png" width="600" height="151" /></a> </p>  <p>Which one do you use?&#160; It is hard to be sure, you end up having to read through the long lists of parameters to figure out what method you should call and what parameters you should pass it.</p>  <p>Wouldn’t it be better if you were presented with what the method does in the method name rather than guessing what it does in the parameter list?&#160; Something like this?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginMoreMethods" border="0" alt="LoginMoreMethods" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods_thumb.png" width="596" height="261" /></a> </p>  <h2>Perspective</h2>  <p>From the perspective of the person writing the <em>Login</em> method(s), overloads probably seem like the most efficient and correct way to implement the multiple ways the method can be called.</p>  <p>From the perspective of the person using the <em>Login</em> method(s), additional methods are much preferred, because they are easier to understand and know what you are looking for.</p>  <p><strong>Try to think from the perspective of someone using your code when writing your code.</strong></p>  <h2>Extract boolean parameter to two methods</h2>  <p>I want to take a look at a very specific example that can be of great benefit to the readability and use of your code.</p>  <p>Take a look at this code below.</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login(<span style="color: #0000ff">bool</span> rememberMe)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>
Seems like a fine overload of a <em>Login</em> method.&#160; I have written code just like this, you probably have also.&#160; <br />

<p>&#160;</p>

<p>Unfortunately, by adding this overload, we have added some complexity to our API, because now the user of that code has to see that there is an additional overload that take a bool parameter called <em>rememberMe</em>.</p>

<p>Consider this longer alternative.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginDoNotRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Instead of overloading <em>Login</em> and making the user have to decide which overload to call and pass in a parameter, we have elected to create two differently named methods which take 0 parameters and clearly state what they are going to do.</p>

<p>I’m not saying you should never write overloads, but anytime you see an overload in your code base, you should stop and think if it would be more clear to make that overloaded method into two different methods that can eliminate one or more of the parameters.</p>

<p><strong>Any time you are restricting the number of choices someone using your code has to make, you are making that code simpler to use.</strong></p>

<p>If you don’t believe me, consider why the iPhone has only one button.</p>

<h5><strong>As always, you can subscribe to this </strong><a href="http://feeds2.feedburner.com/ElegantCode"><strong>RSS feed</strong></a><strong> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at </strong><a href="http://simpleprogrammer.com"><strong>http://simpleprogrammer.com</strong></a><strong>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Say &#8220;No&#8221; to &#8220;Null&#8221;</title>
		<link>http://elegantcode.com/2010/05/01/say-no-to-null/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=say-no-to-null</link>
		<comments>http://elegantcode.com/2010/05/01/say-no-to-null/#comments</comments>
		<pubDate>Sat, 01 May 2010 19:35:05 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/05/01/say-no-to-null/</guid>
		<description><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after. What do you do if "null” [...]]]></description>
			<content:encoded><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after.
<blockquote>What do you do if "null” is passed in?</blockquote>
My answer may turn out to be a bit of a surprise.
<blockquote><span style="background-color: #f4f5f7;">Nothing, I don’t handle nulls in code that I control the use of.</span></blockquote>
“What?  What?” you say.  “You don’t handle null?  What kind of heresy is that?”  It is the kind of heresy that helps produce elegant code and I will show you why.
<h2>How well do you handle null right now?</h2>
Would you say that in most of the code you write you properly check all arguments for null?

Or, do you like most developers, handle null in certain cases when you happen to think about it, or after the application dumps a “null pointer exception” stack trace?

Be honest, look at your code if you have to.

The problem is “d00d ur d0ing it r0ng!”

<a href="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="john-mccarthy-programming-completely-wrong" src="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong_thumb.jpg" border="0" alt="john-mccarthy-programming-completely-wrong" width="349" height="452" /></a>

Unless you are some kind of anal retentive perfectionist, you are probably not handling null in every single method call.  That means there are huge potential bugs in the code that you are writing which will throw null pointer exceptions.  That is bad, I agree.

So, if you are not handling it correctly right now, then what can you do to fix that?
<h2>Avoiding null in the code you “own”</h2>
You can’t control external libraries.  And you can’t control how people will use your code, but you can control the code you write and you can, to a degree, control the code your shop writes.

The better strategy is to never pass null in the first place.

You can either focus your efforts on:
<ul>
	<li>Checking for null</li>
	<li>Not ever passing null</li>
</ul>
<ul>The more elegant solution is to focus on never passing null.  By doing this you will end up writing less code and avoid decisions about how to handle null inside of a method that doesn’t have enough context to decide what to do.</ul>
Let’s look at an example:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> TransmographyThreeStrings(<span class="kwrd">string</span> first, <span class="kwrd">string</span> second, <span class="kwrd">string</span> third)
{
     <span class="kwrd">if</span>(<span class="kwrd">string</span>.isNull(first) || <span class="kwrd">string</span>.isNull(second) || <span class="kwrd">string</span>.isNull(third))
    {
           <span class="rem">// hmm, I donno, what should I do?  Should I throw an exception?</span>
           <span class="rem">// should I return an empty string?</span>
           <span class="rem">// what if the first string wasn't null, can we still do something meaningful?</span>
           <span class="rem">// how will the caller of the method know what I will do?</span>
    }

}</pre>
You can see there that we are checking each parameter for null.  The problem is we don’t know what we should do.  We have lots of options, but none of them are obvious.

How much better is it to make sure that we never pass null into methods, rather than write this kind of code in every method?
<h2>What about accidentally passing in null?</h2>
Many of you are probably thinking at this point that the main way null gets passed into a method is because someone calls a method without knowing that it contains a null value.
<pre class="csharpcode">TransmographyThreeStrings(<span class="str">"Hello"</span>, <span class="str">"World"</span>, mysteryObject.Text);</pre>
Perhaps <em>mysteryObject.Text </em>is null.  You wouldn’t even know it.

Ah, but you can.  Or you can prevent it at least.  Somewhere <em>mysteryObject </em>gets created.  When it gets created its values either get initialized or not.  You can prevent any of its values from being null, several ways:
<ul>
	<li>Always initialize variables when they are declared.</li>
	<li>Use a <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> to ensure that objects are always fully constructed before being created.</li>
	<li>Use properties to provide default values or lazy initialize.</li>
	<li>Make your objects <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> as much as possible.</li>
</ul>
The practices that prevent null from accidentally being passed in make your code much more elegant than repeating <em>if blah == null</em> code all over the place.

<strong>In general, you should always strive to eliminate the passing of null rather than checking for null.  By doing so you reduce extra lines of code in each method, and are forced to use better design practices.</strong>
<h2>Exceptions</h2>
Yes, there are times when you need to check for null.  If you are writing a library that external developers will use, then you will probably want to check for null in all of your methods that are exposed as part of the API.  (On your internal methods, you don’t need to since you have already cleansed the input.)

Also, if your code is being used as a callback to some API and you don’t know if it can ever pass null into your code, you probably should check for null.

A bad excuse is that other developers may pass null to your method. <strong>It is much better as a software shop to put the onus of not passing null on the caller of any method rather than putting it on the writer of the method being called.</strong>

You will also reduce your exception handling code, because you will have less exceptions for invalid parameters.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/05/01/say-no-to-null/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>If Self-Documenting Code is the What, Unit Tests are the Why</title>
		<link>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-self-documenting-code-is-the-what-unit-tests-are-the-why</link>
		<comments>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:09:04 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/</guid>
		<description><![CDATA[It is not enough to just write code that is clean and self-documenting.  Eliminating comments and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it. If you recall from my original post on [...]]]></description>
			<content:encoded><![CDATA[It is not enough to just write code that is clean and self-documenting.  <a href="http://elegantcode.com/2010/04/18/eliminating-comments-the-road-to-clarity/">Eliminating comments</a> and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it.

If you recall from my <a href="http://elegantcode.com/2010/04/09/what-does-elegant-code-mean-to-me/">original post</a> on Elegant code, I stated that elegant code is:
<blockquote>Something that is simple yet effective, delivered with grace.</blockquote>
By writing self-documenting code we are hopefully able to achieve some of the aspects of simplicity and grace, but it tells us nothing about the effectiveness of the code.
<h2>Bringing the dead to life</h2>
<a href="http://elegantcode.com/wp-content/uploads/2010/04/zombies.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="zombies" src="http://elegantcode.com/wp-content/uploads/2010/04/zombies_thumb.jpg" border="0" alt="zombies" width="441" height="295" /></a>

Throwing out comments is a debatable topic.  <a href="http://www.reddit.com/r/programming/comments/bsutx/">It raises quite a bit of controversy</a>, as you can see from some of the comments on my post about the subject.  The reason, perhaps, that so many people are so staunchly opposed to the idea, is because they are worried, and rightly so, that throwing out comments will reduce the documentation of what the code is doing.

Think about that for a second.  Is documentation of what the code is doing important?  It better be.  What we are trying to accomplish by writing self-documenting code instead of comments, is to take the vessel, which is the code itself, and make that same vessel be the documentation of what the code does.  It is by doing this that we creating a living representation of the functionality of the code.  Comments are akin to a dead representation of the functionality of the code because they do not change automatically with the code.

I diverge to talk about comments so that I can draw a parallel to another form of documentation which is valuable and should be considered necessary.  That other set of documentation is requirements.  Have you ever written requirements documents?  Have you ever captured requirements from the customer and put them into UML diagrams, or perhaps plopped them into some templated Word document, which is never updated again, and no one reads, because no one trusts it is correct?  Wouldn’t it be great if we would replace that dead document or set of documents, with a living one?

The good news is we can, and some of us have.  And I fully expect this recommendation will be just as controversial, because <strong>I am suggesting that we don’t have to write low level specifications of the system at all, instead we can write good unit tests. </strong>When we do this, we are taking a dead form of document and bringing it to life.
<h2>Unit tests tell us why and how our code is effective</h2>
If
<pre class="csharpcode">i = 5;  // Widget count defaults to five.</pre>
is replaced with
<pre class="csharpcode">widgetCount = DEFAULT_WIDGET_COUNT;</pre>
<!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

then
<blockquote><span style="background-color: #ffffff;">1.1.5 When a new widget is created, the widget count should be increased by one.</span></blockquote>
is replaced with
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> When_NewWidgetIsCreated_Then_WidgetCountIsIncreasedByOne()
{
     WidgetFactory.Count = 3;
     WidgetFactory.CreateNew();
     assertEquals(4, WidgetFactory.Count);
}</pre>
The unit test is replacing the low level requirement, which is somewhat open to interpretation and untied to the code, with an absolute and completely tied-to-the-code, specific requirement.

The unit test is telling us why our code is built the way it is.  It is telling us what requirement that particular structure of code is trying to address.  <strong>It is telling us what end result that code is trying to accomplish and what the expectations are on the results of a given condition.</strong>

The unit test is telling us how the code is to be used in order to achieve its result.  It is serving as a living reference to the syntax and use of the code we built.  <strong>Instead of providing instructions on how to use our API, we are providing a living example, and proof that it will indeed work.</strong> Examples are often much more effective than instructions anyway.
<h2>What exactly are we replacing?</h2>
At this point we are not trying to replace all the documentation of the system (at this point).

With self-documenting code, we sought to eliminate comments, and replace them with good variable and method names.

With unit tests, we seek to eliminate technical documentation and requirements of the system, that is targeted at a developer or technical audience.

We are NOT trying to eliminate high level specifications of the system, or use cases. <strong>Unit tests DO NOT replace that kind of documentation! </strong>We will talk about replacing that kind of documentation when we talk about automated functional or system tests.

Simply put, any kind of documentation that you would give to a developer so they understand how the system works and how to use the code or APIs, can be easily replaced by writing good unit tests.

Our simple goal is to replace the “dead” documentation (meaning that it does not update automatically with the thing it is documenting), with “living” documentation in the form of unit tests.

One last point.  I want to be clear that I am not saying that having unit tests automatically results in the ability to replace technical documentation.  Just like having long-named methods and variables doesn’t automatically replace the need for comments.  It is a matter of the quality of the unit tests that are written, just as it is a matter of the quality of the self-documenting code.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>REST: Resources, URI&#8217;s and Representations</title>
		<link>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rest-resources-uris-and-representations</link>
		<comments>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 04:00:13 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/</guid>
		<description><![CDATA[In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions. Resources Resources are at the heart of REST.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions.</p>  <h3>Resources</h3>  <p>Resources are at the heart of REST.&#160; You are already used to resources as a web browsing consumer.&#160; A resource is not something specific to REST, instead it is the first thing you probably want to consider when architecting a RESTful application.&#160; A resource is simply the entity, item, or thing you want to expose.</p>  <p>Perhaps you have approached application architecture using one or many of several modeling and design techniques.&#160; Data First practitioners typically begin with databases and data models.&#160; DDD proponents like to begin by modeling around business entities and interactions, while their cousins in the BDD camp model around business activities.</p>  <p>When you decide to apply REST you will need to think a lot more about data entities and domain objects as resources.&#160; Your existing models may or may not closely map to resources.&#160; The shift in thinking may appear slight, but is very important.&#160; It centers around making things&#160; addressable.&#160; Each resources must by uniquely identifiable as we will see in the next section.&#160; We are used to identity with most data entities, but our domain objects may not always be as easily identifiable.&#160; Likewise, our data entites may have identity, but not map to a resource.&#160; </p>  <p>Consider the classic customer and order scenario for example.&#160; If each customer and each order can be identified then it will be easy to design RESTful systems around them.&#160; However, if the model requires a lot of context then our challenge is a little bit larger.&#160; Perhaps we must first identify a partner, then a year, then a customer, and finally the order.&#160; Yes, that is a design smell in general.&#160; It makes fetching an order very difficult.&#160; Developing RESTfuly would only further expose that difficulty.&#160; Identifying your resources up front will help you reduce the possible impedance mismatches you might end up with between what you want to expose and your data or domain models.</p>  <p>REST is about interacting with Resources!</p>  <h3>URI’s</h3>  <p>REST defines the identity of a resource via URI.&#160; Each resources has a unique address in URL form (ie. using the http protocol).&#160; Interaction with a resource will take place at its URI.&#160; As an example, my twitter status feed resource URI is <a title="http://twitter.com/optionstrict" href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; That URI is unique to my feed and that is what you expect to find at that URI.&#160; In the Twitter databases or domain models my account may be referred to by the string optionstrict, or perhaps as some random number or guid.</p>  <p>To consume my status history via a service interface twitter provides another URI at <a title="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict" href="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict">http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict</a>.&#160; I would actually prefer to have access at the same URI for html, json, and xml formats.&#160; Twitter probably has its reasons for distinguishing API access from HTML rendering, but they have actually complicated their architecture by doing so.&#160; When designing the URI’s for your resources, make them easy for your users to work with.&#160; </p>  <h3>Representation</h3>  <p>Lets continue with the twitter example to describe what is meant by Representation.&#160; Given a URI and a Resource, what will your consumers receive when they issue a GET request to the URI?&#160; Twitter chose a representation of my account and included status history and profile for the response at <a href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; They decided to put a representation of my profile photo at <a title="http://twitter.com/account/profile_image/optionstrict" href="http://twitter.com/account/profile_image/optionstrict">http://twitter.com/account/profile_image/optionstrict</a>.&#160; In your REST solutions you will need to consider how you want to represent a resource at its URI.&#160; Each representation will have a unique URI.&#160; </p>  <p>Representations are also important for manipulating resources.&#160; You must define the representation required to create and update resources.&#160; Twitter status updates require a text representation with a maximum of 140 characters.&#160; They allow additional values in the status representation, such as latitude and longitude.&#160; Your REST solutions similarly must define representations for Requests and Responses.</p>  <p>I hope that this short introduction has helped you to see that the core essence of REST is simple and fairly obvious.&#160; As you look at your current solutions what are the resources you are exposing?&#160; Could you make those resources identifiable by URI?&#160; What representation would you place at each URI?&#160; What representation would you require for manipulating a given resource?</p>  <p>Also, notice I did not mention much about data formats, Content Type, Mime, etc.&#160; Those details can cloud your design if you try to start with them. If you can’t wait for my post about how REST handles html, json, xml from the same URI, then start googling Content Negotiation, Accept header, and Content-Type header.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Driven Architecture: Publishing Events using an IOC container</title>
		<link>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-software-development-will-never-be-engineering</link>
		<comments>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 03:37:48 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/</guid>
		<description><![CDATA[I always find it rather interesting when academics try to quantify generalized metrics about software development. Temovate Cream For Sale, Things like: per lines of code, there will be X number of bugs. Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.” These are all interesting [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I always find it rather interesting when academics try to quantify generalized metrics about software development.</p>  <p> <b>Temovate Cream For Sale</b>, Things like: per lines of code, there will be X number of bugs.</p>  <p>Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.”</p>  <p>These are all interesting thoughts, but software development will never conform to rigid engineering principles like many other engineering practices.&#160; The longer I work in the field, the more and more I realize that software development has nothing to do with engineering.&#160; We just happen to attend some of the same math classes in school.</p>  <h2>Building bridges</h2>  <p>One of the main arguments I hear people make about the current state of software development as an engineering practice is based around its relative maturity to other engineering fields.</p>  <p>There is a huge problem with this line of thinking.</p>  <p>The argument goes something like this:&#160; “<em>Engineering has been around for hundreds of years and has matured to the point where it is a measurable science, but software development has only been around in earnest for the last few decades or so, therefore it is relatively immature as an engineering discipline.”</em></p>  <p>On the surface this argument seems sounds.&#160; And certainly in 50 years software development will be different than it is now.&#160; Heck, it is much more different than it was just 10 years ago.</p>  <p>But, here is the problem.&#160; We build much more software than we do bridges.</p>  <p><img src="http://www.nps.gov/glca/historyculture/images/Navajo_Bridges_1.gif" width="589" height="442" /></p>  <h6 align="center">&#160;</h6>  <p>Let me give you an example that came to light in another area of my interest… poker.</p>  <h1></h1>  <h2>The poker quickening</h2>  <p>An interesting thing happened in the poker community in the last 10 years; poker pros with decades of experience started getting beat time and time again by 19 year old poker prodigies.</p>  <p>From an outside perspective it looks like the poker world opening up just widened the search for talent and there it was.&#160; But, a closer examination of the evidence leads to the truth.</p>  <p>Before the online poker industry was born, poker was played in card rooms and casinos in states where it was legal and occasionally at small home games throughout the US.</p>  <p>A poker pro might play poker tournaments perhaps 100 times to 150 times a year.&#160; The sum knowledge of the poker community and the meta game around it was based on this base of professional poker players playing tournaments and gaining experience at this mediocre rate.</p>  <p>Once the internet poker rooms started opening up, things changed, and they changed rapidly.&#160; Now anyone could play poker from their home PC.&#160; Not only could they play poker, they could play poker tournaments at all hours of the day.</p>  <p>Here is a list of some of the major changes that took place:</p>  <ul>   <li>Hands are dealt at 60-80 hands per hour instead of 10-30</li>    <li>Players can play in many tournaments at one time, 10 tournaments at once is not unheard of</li>    <li>Players can analyze hand histories and historical data about their play and opponents play through the use of software </li>    <li>Age requirements are out the window, technically any one of any age could be playing online</li>    <li>Players can play 24 hours a day</li>    <li>The professional online tournament player could easily play over 3000 tournaments in a year, while a brick and mortar pro would be lucky to reach 100 in a year.</li>   <img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://t1.gstatic.com/images?q=tbn:ANd9GcRj9uGNWSyqGWEneiH6xaBAyS6COwGYicdNadZu-06KWQLhIi6LMw&amp;t=1" width="316" height="270" /></ul>  <p>&#160;</p>  <p>So where am I going with all this?</p>  <p>The point is that as a whole more hands were dealt and more poker knowledge and experience was obtained in 1 year of online poker than probably the entire history of poker before that.&#160; We reached such an accelerated pace of play that all previous knowledge of poker became obsolete.&#160; </p>  <p>The strategy of tournament poker completely changed.&#160; The game evolved perhaps 500 years into the future in a matter of 5 years time.</p>  <p>The same has happened with software development.</p>  <h2>Back to the bridge building</h2>  <p>So let’s take that poker example and look at it through the lens of software development.</p>  <p>Let us compare the engineering maturity to software development to the engineering maturity of the engineering discipline of building bridges.</p>  <p>I think most people would agree that bridge building is a very mature engineering discipline but many people would argue that software development is not.</p>  <p><strong>How many bridges do you think have been built in the world?</strong></p>  <p>Well there are <a href="http://www.betterroads.com/category/bridge-inventory/erroads.randallreillycms.com/files/2009/11/BR1109_BridgeInventory.pdf">about 600,000 bridges in the United States alone</a>, so the world figure must be at least somewhere around 10 times that number perhaps 20.</p>  <p><strong>How many software programs have been written?</strong></p>  <p>This is a very hard number to estimate, but lets take a rough guess based on <a href="http://stackoverflow.com/questions/453880/how-many-developers-are-there-in-the-world">how many software developers there are in the world</a>.&#160; </p>  <p>If we say there are about 12 million software developers and each software developer has written approximately 3 programs, we can estimate that a large amount more programs have been written than bridges built.</p>  <p>My point is not to knock bridge building, we are pretty good at it as a whole, but rather to show that collectively, even though we have been building bridges for hundreds of years, we have probably devoted an equivalent amount of time to building software.</p>  <p>This line of thinking may lead you to argue back that software development and bridge building are very different.&#160; Bridge building has a fixed set of requirements that are pretty close to the the same for each bridge you build, but software development is a big open void of whims and ambiguously contradictory statements.</p>  <p>I agree with you 100%!&#160; And in essence that is my point.</p>  <h2>Software development is different</h2>  <p>And we have had enough time to realize that.&#160; Waiting for software development to gel into some kind of engineering discipline like other engineering disciplines is like waiting for water without gelatin mix to turn into Jello.&#160; </p>  <p>It’s just not going to happen!</p>  <p>In my mind it is clear that the argument that we haven’t given it enough time is just wishful thinking.&#160; The nature of software development, just like online poker, leads itself to rapid evolution.</p>  <p>Consider what direction software development is evolving.&#160; Is it even evolving in the direction of rigid engineering practices or is it evolving in the exact OPPOSITE direction?</p>  <p>Ten years ago, we tried to use UML diagrams and CASE tools to develop software.&#160; Ten years ago waterfall was all the rage.&#160; Ten years ago, we thought that ten years in the future we would have programs that would allow us to build software in the same way that CAD tools allow for building machine parts.</p>  <p>Not only did it not happen.&#160; It went completely the other way.&#160; Now we are all talking about Agile.&#160; Now people don’t even remember what CASE tools are.&#160; Now we are building software without trying to define the whole system in UML diagrams.</p>  <p><strong>The fact of the matter is software systems are unruly beasts!</strong></p>  <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://aznbadger.files.wordpress.com/2010/06/beast.jpg" /></p>  <p>In my mind it comes down to one simple distinction.&#160; Software is living, bridges aren’t.&#160; When you are done building a bridge, you are done building the bridge.&#160; </p>  <p>Sure someone, probably not you, will have to come along and do some routine maintenance on it.&#160; Sure, some small things might change about it, but for all intents and purposes the work is done.</p>  <p>In most software development scenarios, this is not the case.&#160; In most software development scenarios, releasing V1 is not even close to the end.&#160; Sometimes V1 and V2 don’t even look that same at all.&#160; Software development is about operating on a living breathing thing and all the while keeping it alive.</p>  <p>The truth is, we software developers have more in common with surgeons than with other engineers.</p>  <h6>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com/">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>.  Buy Temovate Cream without a prescription.  Temovate Cream trusted pharmacy reviews.  Temovate Cream over the counter.  Where can i order Temovate Cream without prescription.  Online buy Temovate Cream without a prescription.  Temovate Cream no rx.  Buy cheap Temovate Cream no rx.  Temovate Cream photos.  Buy Temovate Cream online no prescription.  Order Temovate Cream online c.o.d.  Herbal Temovate Cream.  About Temovate Cream.  Australia, uk, us, usa.  Cheap Temovate Cream.  Temovate Cream class.  Temovate Cream brand name.  Online Temovate Cream without a prescription.  Buy Temovate Cream without prescription.  Buy Temovate Cream from canada.  After Temovate Cream.  Order Temovate Cream from mexican pharmacy.  Temovate Cream without a prescription.  Purchase Temovate Cream.  Temovate Cream natural.  Temovate Cream overnight.  Temovate Cream online cod.  Where can i buy cheapest Temovate Cream online.  Purchase Temovate Cream for sale.  Online buying Temovate Cream.  Purchase Temovate Cream online.  Temovate Cream used for.  Temovate Cream coupon.  Temovate Cream description.  Order Temovate Cream no prescription.  Temovate Cream maximum dosage.  Cheap Temovate Cream no rx.  Temovate Cream images.  Temovate Cream blogs.  Buy Temovate Cream online cod.  Buy generic Temovate Cream.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4472'>Bactroban For Sale</a>. <a href='http://elegantcode.com/?p=4632'>Armour For Sale</a>. <a href='http://elegantcode.com/?p=4639'>Buy Estrace Vaginal Cream Without Prescription</a>. <a href='http://elegantcode.com/?p=4668'>Buy Augmentin Without Prescription</a>. <a href='http://elegantcode.com/?p=4535'>Buy Tindamax Without Prescription</a>. <a href='http://elegantcode.com/?p=4931'>Fast shipping Diclofenac</a>. <a href='http://elegantcode.com/?p=4240'>Combivent brand name</a>. <a href='http://elegantcode.com/?p=4417'>Levaquin overnight</a>. <a href='http://elegantcode.com/?p=4597'>Purchase Toradol online</a>. <a href='http://elegantcode.com/?p=4221'>Australia, uk, us, usa</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.quarterlives.com/?p=1148'>Temovate Cream For Sale</a>. <a href='http://4realz.net/?p=1972'>Temovate Cream For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=5997'>Temovate Cream For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2476'>Temovate Cream For Sale</a>. <a href='http://www.thegriffonnews.com/?p=9947'>Temovate Cream For Sale</a>. <a href='http://social-blend.com/?p=1160'>Temovate Cream brand name</a>. <a href='http://blog.farmland.org/?p=3812'>Where can i find Temovate Cream online</a>. <a href='http://reversemortgagedaily.com/?p=14136'>Generic Temovate Cream</a>. <a href='http://linuxologist.com/?p=1792'>Temovate Cream photos</a>. <a href='http://home.officesnapshots.com/?p=114'>Order Temovate Cream from mexican pharmacy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
		<item>
		<title>Elegant Code &#187; Architecture</title>
	<atom:link href="http://elegantcode.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quinine For Sale</title>
		<link>http://elegantcode.com/2012/01/18/monitoring-an-mmo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-an-mmo</link>
		<comments>http://elegantcode.com/2012/01/18/monitoring-an-mmo/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:45:32 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MMO]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2012/01/18/monitoring-an-mmo/</guid>
		<description><![CDATA[I’ve been working on a free-to-play MMO Quinine For Sale, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I’ve been working on a free-to-play <a href="http://www.heroup.com" target="_blank">MMO</a> <b>Quinine For Sale</b>, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before they become serious and fixing problems when they inevitably do.&#160; So, there are two questions.&#160; “Is there a problem in the game?” “What is causing the problem?”&#160; </p>  <p>When trying to debug something on our development and test clusters, typically you can tail log files.&#160; We have a python script that can monitor the communication between various parts of the game and pretty-print it along with color to highlight “this is a problem!”&#160; Attaching a debugger to a running process is also not uncommon.&#160; However, looking at logs and bus traffic in realtime on a production environment gives you this neat “Matrix-y” experience.&#160; Attaching a debugger to a production process (assuming you could, which you can’t) would get you smacked with a rolled-up newspaper.&#160; “Bad Developer!&#160; No treat!”&#160; So, what can you do?</p>  <h4>Monitoring</h4>  <p>When you’ve got clusters full of machines, using <a href="http://www.nagios.org/" target="_blank">Nagios</a> to monitor things is an obvious solution.&#160; Beyond making sure the power is on and other sysadmin things, we’ve written other checks to see if the login process is working, the parts are working together, and automating typical in-game functions.&#160; For example, if nagios can’t successfully log into the game do basic game activity, then alerts happen.</p>  <h4>Metrics for EVERYTHING</h4>  <p>Anything that happens in game has metrics reporting tied to it, generating piles of data constantly.&#160; We use <a href="http://www.cacti.net/" target="_blank">Cacti</a> to visualize game activity.&#160; An example metric is concurrent users, or CCU.&#160; We graph how many people are in the game over time, which when things are healthy should be a nice smooth curve climbing to peak game hours, then descending nicely through the night.</p>  <p>We can tell by sight if the game looks healthy or not – if the CCU graph is jaggy, has a sudden drop or spike, or drops to zero then we know that something is wrong.&#160; Typically nagios alerts accompany the graphs, giving more data points on where to look.&#160; But this has also pointed out areas where a nagios check was missing or wasn’t working as intended.</p>  <h4>Log Files</h4>  <p>When a player gets an error in game, the error dialog box gives them the opportunity to submit the error details back to us.&#160; If we see a spike in user-reported errors through this or other customer service means, we know we have something of interest to look for.&#160; </p>  <p>The game server components make use of log4j and similar logging frameworks.&#160; Anything that you’d want to watch happening in game needs to be aggressively logged.&#160; All components are configured so that operations can change the log level on the fly.&#160; That’s still quite a bit of data across many machines though, so all that information is run through <a href="http://www.splunk.com/product" target="_blank">Splunk</a> to be indexed and searchable.&#160; This gives us a great tool for searching through log data, examining trends, or watching selected activity in real time.&#160; Unfortunately it is very expensive so we are selective about the data that passes through it.&#160; </p>.  Buy Quinine from mexico.  Buy Quinine no prescription.  No prescription Quinine online.  Online buying Quinine.  Quinine no prescription.  Quinine street price.  Buy no prescription Quinine online.  Quinine coupon.  Quinine over the counter.  Where can i buy Quinine online.  Quinine steet value.  Where to buy Quinine.  Order Quinine online overnight delivery no prescription.  Quinine recreational.  Quinine canada, mexico, india.  Ordering Quinine online.  Quinine without prescription.  Quinine price, coupon.  Quinine description.  Order Quinine from mexican pharmacy.  Quinine pics.  What is Quinine.  Japan, craiglist, ebay, overseas, paypal.  Order Quinine from United States pharmacy.  Order Quinine online c.o.d.  Quinine trusted pharmacy reviews.  Quinine treatment.  Buy Quinine from canada.  Quinine used for.  Discount Quinine.  Is Quinine addictive.  Quinine forum.  Buy Quinine online no prescription.  Is Quinine safe.  Purchase Quinine for sale.  Effects of Quinine.  Buy Quinine online cod.  Quinine australia, uk, us, usa.  Buy Quinine without prescription.  Quinine online cod.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4721'>Buy Flonase Without Prescription</a>. <a href='http://elegantcode.com/?p=4234'>Buy Periactin Without Prescription</a>. <a href='http://elegantcode.com/?p=4203'>Buy Armour Without Prescription</a>. <a href='http://elegantcode.com/?p=4899'>Buy Macrobid Without Prescription</a>. <a href='http://elegantcode.com/?p=4534'>Xalatan For Sale</a>. <a href='http://elegantcode.com/?p=4302'>Phenergan wiki</a>. <a href='http://elegantcode.com/?p=4268'>Soma maximum dosage</a>. <a href='http://elegantcode.com/?p=4602'>Zovirax treatment</a>. <a href='http://elegantcode.com/?p=4578'>Cialis price, coupon</a>. <a href='http://elegantcode.com/?p=4189'>Flexeril price</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.leaduganda.org/?p=514'>Quinine For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=4820'>Quinine For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2780'>Quinine For Sale</a>. <a href='http://www.thegriffonnews.com/?p=10177'>Quinine For Sale</a>. <a href='http://www.independentworldreport.com/?p=2409'>Quinine For Sale</a>. <a href='http://changecamp.ca/?p=295'>Quinine description</a>. <a href='http://social-blend.com/?p=624'>Quinine price, coupon</a>. <a href='http://blog.farmland.org/?p=3946'>Online buying Quinine hcl</a>. <a href='http://4realz.net/?p=1595'>Quinine from canada</a>. <a href='http://reversemortgagedaily.com/?p=14535'>Where to buy Quinine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2012/01/18/monitoring-an-mmo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temovate Cream For Sale</title>
		<link>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-software-development-will-never-be-engineering</link>
		<comments>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 03:37:48 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/</guid>
		<description><![CDATA[I always find it rather interesting when academics try to quantify generalized metrics about software development. Temovate Cream For Sale, Things like: per lines of code, there will be X number of bugs. Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.” These are all interesting [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I always find it rather interesting when academics try to quantify generalized metrics about software development.</p>  <p> <b>Temovate Cream For Sale</b>, Things like: per lines of code, there will be X number of bugs.</p>  <p>Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.”</p>  <p>These are all interesting thoughts, but software development will never conform to rigid engineering principles like many other engineering practices.&#160; The longer I work in the field, the more and more I realize that software development has nothing to do with engineering.&#160; We just happen to attend some of the same math classes in school.</p>  <h2>Building bridges</h2>  <p>One of the main arguments I hear people make about the current state of software development as an engineering practice is based around its relative maturity to other engineering fields.</p>  <p>There is a huge problem with this line of thinking.</p>  <p>The argument goes something like this:&#160; “<em>Engineering has been around for hundreds of years and has matured to the point where it is a measurable science, but software development has only been around in earnest for the last few decades or so, therefore it is relatively immature as an engineering discipline.”</em></p>  <p>On the surface this argument seems sounds.&#160; And certainly in 50 years software development will be different than it is now.&#160; Heck, it is much more different than it was just 10 years ago.</p>  <p>But, here is the problem.&#160; We build much more software than we do bridges.</p>  <p><img src="http://www.nps.gov/glca/historyculture/images/Navajo_Bridges_1.gif" width="589" height="442" /></p>  <h6 align="center">&#160;</h6>  <p>Let me give you an example that came to light in another area of my interest… poker.</p>  <h1></h1>  <h2>The poker quickening</h2>  <p>An interesting thing happened in the poker community in the last 10 years; poker pros with decades of experience started getting beat time and time again by 19 year old poker prodigies.</p>  <p>From an outside perspective it looks like the poker world opening up just widened the search for talent and there it was.&#160; But, a closer examination of the evidence leads to the truth.</p>  <p>Before the online poker industry was born, poker was played in card rooms and casinos in states where it was legal and occasionally at small home games throughout the US.</p>  <p>A poker pro might play poker tournaments perhaps 100 times to 150 times a year.&#160; The sum knowledge of the poker community and the meta game around it was based on this base of professional poker players playing tournaments and gaining experience at this mediocre rate.</p>  <p>Once the internet poker rooms started opening up, things changed, and they changed rapidly.&#160; Now anyone could play poker from their home PC.&#160; Not only could they play poker, they could play poker tournaments at all hours of the day.</p>  <p>Here is a list of some of the major changes that took place:</p>  <ul>   <li>Hands are dealt at 60-80 hands per hour instead of 10-30</li>    <li>Players can play in many tournaments at one time, 10 tournaments at once is not unheard of</li>    <li>Players can analyze hand histories and historical data about their play and opponents play through the use of software </li>    <li>Age requirements are out the window, technically any one of any age could be playing online</li>    <li>Players can play 24 hours a day</li>    <li>The professional online tournament player could easily play over 3000 tournaments in a year, while a brick and mortar pro would be lucky to reach 100 in a year.</li>   <img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://t1.gstatic.com/images?q=tbn:ANd9GcRj9uGNWSyqGWEneiH6xaBAyS6COwGYicdNadZu-06KWQLhIi6LMw&amp;t=1" width="316" height="270" /></ul>  <p>&#160;</p>  <p>So where am I going with all this?</p>  <p>The point is that as a whole more hands were dealt and more poker knowledge and experience was obtained in 1 year of online poker than probably the entire history of poker before that.&#160; We reached such an accelerated pace of play that all previous knowledge of poker became obsolete.&#160; </p>  <p>The strategy of tournament poker completely changed.&#160; The game evolved perhaps 500 years into the future in a matter of 5 years time.</p>  <p>The same has happened with software development.</p>  <h2>Back to the bridge building</h2>  <p>So let’s take that poker example and look at it through the lens of software development.</p>  <p>Let us compare the engineering maturity to software development to the engineering maturity of the engineering discipline of building bridges.</p>  <p>I think most people would agree that bridge building is a very mature engineering discipline but many people would argue that software development is not.</p>  <p><strong>How many bridges do you think have been built in the world?</strong></p>  <p>Well there are <a href="http://www.betterroads.com/category/bridge-inventory/erroads.randallreillycms.com/files/2009/11/BR1109_BridgeInventory.pdf">about 600,000 bridges in the United States alone</a>, so the world figure must be at least somewhere around 10 times that number perhaps 20.</p>  <p><strong>How many software programs have been written?</strong></p>  <p>This is a very hard number to estimate, but lets take a rough guess based on <a href="http://stackoverflow.com/questions/453880/how-many-developers-are-there-in-the-world">how many software developers there are in the world</a>.&#160; </p>  <p>If we say there are about 12 million software developers and each software developer has written approximately 3 programs, we can estimate that a large amount more programs have been written than bridges built.</p>  <p>My point is not to knock bridge building, we are pretty good at it as a whole, but rather to show that collectively, even though we have been building bridges for hundreds of years, we have probably devoted an equivalent amount of time to building software.</p>  <p>This line of thinking may lead you to argue back that software development and bridge building are very different.&#160; Bridge building has a fixed set of requirements that are pretty close to the the same for each bridge you build, but software development is a big open void of whims and ambiguously contradictory statements.</p>  <p>I agree with you 100%!&#160; And in essence that is my point.</p>  <h2>Software development is different</h2>  <p>And we have had enough time to realize that.&#160; Waiting for software development to gel into some kind of engineering discipline like other engineering disciplines is like waiting for water without gelatin mix to turn into Jello.&#160; </p>  <p>It’s just not going to happen!</p>  <p>In my mind it is clear that the argument that we haven’t given it enough time is just wishful thinking.&#160; The nature of software development, just like online poker, leads itself to rapid evolution.</p>  <p>Consider what direction software development is evolving.&#160; Is it even evolving in the direction of rigid engineering practices or is it evolving in the exact OPPOSITE direction?</p>  <p>Ten years ago, we tried to use UML diagrams and CASE tools to develop software.&#160; Ten years ago waterfall was all the rage.&#160; Ten years ago, we thought that ten years in the future we would have programs that would allow us to build software in the same way that CAD tools allow for building machine parts.</p>  <p>Not only did it not happen.&#160; It went completely the other way.&#160; Now we are all talking about Agile.&#160; Now people don’t even remember what CASE tools are.&#160; Now we are building software without trying to define the whole system in UML diagrams.</p>  <p><strong>The fact of the matter is software systems are unruly beasts!</strong></p>  <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://aznbadger.files.wordpress.com/2010/06/beast.jpg" /></p>  <p>In my mind it comes down to one simple distinction.&#160; Software is living, bridges aren’t.&#160; When you are done building a bridge, you are done building the bridge.&#160; </p>  <p>Sure someone, probably not you, will have to come along and do some routine maintenance on it.&#160; Sure, some small things might change about it, but for all intents and purposes the work is done.</p>  <p>In most software development scenarios, this is not the case.&#160; In most software development scenarios, releasing V1 is not even close to the end.&#160; Sometimes V1 and V2 don’t even look that same at all.&#160; Software development is about operating on a living breathing thing and all the while keeping it alive.</p>  <p>The truth is, we software developers have more in common with surgeons than with other engineers.</p>  <h6>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com/">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>.  Buy Temovate Cream without a prescription.  Temovate Cream trusted pharmacy reviews.  Temovate Cream over the counter.  Where can i order Temovate Cream without prescription.  Online buy Temovate Cream without a prescription.  Temovate Cream no rx.  Buy cheap Temovate Cream no rx.  Temovate Cream photos.  Buy Temovate Cream online no prescription.  Order Temovate Cream online c.o.d.  Herbal Temovate Cream.  About Temovate Cream.  Australia, uk, us, usa.  Cheap Temovate Cream.  Temovate Cream class.  Temovate Cream brand name.  Online Temovate Cream without a prescription.  Buy Temovate Cream without prescription.  Buy Temovate Cream from canada.  After Temovate Cream.  Order Temovate Cream from mexican pharmacy.  Temovate Cream without a prescription.  Purchase Temovate Cream.  Temovate Cream natural.  Temovate Cream overnight.  Temovate Cream online cod.  Where can i buy cheapest Temovate Cream online.  Purchase Temovate Cream for sale.  Online buying Temovate Cream.  Purchase Temovate Cream online.  Temovate Cream used for.  Temovate Cream coupon.  Temovate Cream description.  Order Temovate Cream no prescription.  Temovate Cream maximum dosage.  Cheap Temovate Cream no rx.  Temovate Cream images.  Temovate Cream blogs.  Buy Temovate Cream online cod.  Buy generic Temovate Cream.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4472'>Bactroban For Sale</a>. <a href='http://elegantcode.com/?p=4632'>Armour For Sale</a>. <a href='http://elegantcode.com/?p=4639'>Buy Estrace Vaginal Cream Without Prescription</a>. <a href='http://elegantcode.com/?p=4668'>Buy Augmentin Without Prescription</a>. <a href='http://elegantcode.com/?p=4535'>Buy Tindamax Without Prescription</a>. <a href='http://elegantcode.com/?p=4931'>Fast shipping Diclofenac</a>. <a href='http://elegantcode.com/?p=4240'>Combivent brand name</a>. <a href='http://elegantcode.com/?p=4417'>Levaquin overnight</a>. <a href='http://elegantcode.com/?p=4597'>Purchase Toradol online</a>. <a href='http://elegantcode.com/?p=4221'>Australia, uk, us, usa</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.quarterlives.com/?p=1148'>Temovate Cream For Sale</a>. <a href='http://4realz.net/?p=1972'>Temovate Cream For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=5997'>Temovate Cream For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2476'>Temovate Cream For Sale</a>. <a href='http://www.thegriffonnews.com/?p=9947'>Temovate Cream For Sale</a>. <a href='http://social-blend.com/?p=1160'>Temovate Cream brand name</a>. <a href='http://blog.farmland.org/?p=3812'>Where can i find Temovate Cream online</a>. <a href='http://reversemortgagedaily.com/?p=14136'>Generic Temovate Cream</a>. <a href='http://linuxologist.com/?p=1792'>Temovate Cream photos</a>. <a href='http://home.officesnapshots.com/?p=114'>Order Temovate Cream from mexican pharmacy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
		<item>
		<title>Christmas Light Architectures Are Not That Shiny</title>
		<link>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=christmas-light-architectures-are-not-that-shiny</link>
		<comments>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:00:00 +0000</pubDate>
		<dc:creator>Jan Van Ryswyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/</guid>
		<description><![CDATA[I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way [...]]]></description>
			<content:encoded><![CDATA[<p>I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way overdue :-).</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb1.png" width="202" height="172" /></a> </p>  <p><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a>What's the major malfunction with those old, classic Christmas lights? We've all experienced it at some point. When one goes out, all the others go out as well. This is due to the fact that these lights are wired in series. The difference compared with today's Christmas lights is that every bulb has a shunt, which basically prevents this kind of failure caused by one or more lamps. Enough about the Christmas lights for now. Where am I going with this? Back in enterprise IT, I'm seeing the same kind of failures as with those classic, old Christmas lights.</p>  <p>The diagram below shows a classic RPC style architecture, much like those classic, old Christmas lights. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb2.png" width="565" height="329" /></a> </p>  <p>This is all fine and dandy as long as every part of the chain runs without too much hassle. But what happens if for some reason the centralized back-end web service goes down (light bulb goes out). This means that every smart client, website and batch application that uses this web service gets affected by this, like some sort of chain reaction. Parts of these client applications will no longer function correctly or they might even go down entirely. Same thing happens when the database of the centralized back-end web service goes down or any other external system that it depends on. When being confronted with this kind of architecture, how would one go about preventing this doomsday scenario to happen?</p>  <p>Suppose you’re a developer that has to work on the centralized back-end web service. This is usually a complex system as it obviously has to provide features for all kinds of applications. When this centralized back-end web service also has to deal with and depend on other external systems that might expose some unexpected behavior, how could one prevent the sky from falling down when things go awry in production?</p>  <p>Well for starters, you could start building in some stabilization points. Suppose for some reason, the centralized web service needs to incorporate some functionality offered by a highly expensive, super enterprise system that for some reason behaves very unstable and unpredictably on every full moon (expensive enterprise software not behaving correctly sounds ridiculous, but bare with me ;-) ). For example, we could use a message queue as a stabilization point. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb3.png" width="570" height="157" /></a> </p>  <p>This means that we put a message on a queue that is processed by some sort of worker process or service that does the actual communication with the misbehaving system. When the external system goes down, the message is either left on the message queue or put on an error queue for later processing when the external system comes back up again. There are some other things you need to think about like idempotent messaging, consistency, message persistence when the server goes down, etc. … . But if one of these dependencies goes down, the centralized back-end web service is still up-and-running which means that the systems that depend on its functionality can also continue to serve their users as they are able to keep doing their work.</p>  <p>Earlier this week I overheard this conversation that somewhat amazed me. I changed the names of the persons involved as well as the exact words used in order to protect the guilty.</p>  <blockquote>   <p><em>George: </em><em>We want to incorporate a message queue in order to guarantee stability and&#160; integrity between several non-transactional systems that our system depends on. It will also improve performance as these systems behave very slow at times and become unstable under pressure. This also gives us the opportunity to root out some major points friction that our end-users are experiencing right now.</em></p>    <p><em>Stan: But this means that the end-users are not completely sure if their actions are indeed fully carried out by the system. </em></p>    <p><em>George: End-users can always check the current state of affairs in their applications. If something goes wrong, their request is not lost and things will get fixed automatically later on as soon as the cause of the error has been fixed. </em></p>    <p><em>Stan:&#160; I don’t think that’s a very good idea. End-users have to wait until everything is processed synchronously, even if that means that they’ll need to wait for a long time. And if one of the external systems goes down, they should stop sending in new requests. Everything should come to a halt. They just have to stop doing what they are doing.</em></p>    <p><em>George: This means that because you lose the original request, some external systems might be set up correctly while others are not. Then someone has to manually fix these issues.</em></p>    <p><em>Stan: Then so be it!</em>&#160;</p> </blockquote>  <p>For starters, I was shocked by this conversation. This is just insane. Everything should come to a halt? Think about this scenario for a while: suppose you’re finding yourself in a grocery store with a cart full of food, drinks and other stuff. You come at the cash register where the lady kindly says “Can you put everything back on the shelves please? There are some issues with the cash register software and we are instructed to stop scanning items and serve customers until these issues are fixed. Can you come back tomorrow please?”. Uhm, no! How much money do you think this is going to cost compared to the system that makes use of stabilization points? An end-user that is able to keep doing its work, whether the entire production system is down or not has tremendous business value. </p>  <p>I’m not saying that message queues are a silver bullet. I’m just using these as an example. As always, there is a time and place for using them. There are other things a developer can incorporate in order to increase the stability of the system he’s working on, like <a href="http://davybrion.com/blog/2008/05/the-circuit-breaker/" target="_blank">the circuit breaker pattern</a>. I’m also not saying that every system should be built using every stabilization point one can think of. This become a business decision depending on the kind of solution. As usual, it depends.</p>  <p>But the point that I’m trying to make here is that we should stop putting software systems into production and just hoping for the best. That’s just wishful thinking. Software systems are going to behave badly and at some point they will go down. It’s just a matter of when this is going to happen and how much damage this is going to make.</p>  <p>The first step to take is awareness. I encourage you to pick up this book titled ‘<a href="http://www.amazon.com/exec/obidos/ASIN/0978739213/elegantcode-20" target="_blank">Release It!</a>’, written by <a href="http://www.michaelnygard.com/" target="_blank">Michael Nygard</a>. This book is all about designing software that can survive this though environment called production. I can only hope that Stan picks up a copy as well along with some common sense.</p>  <p>Till next time.&#160;&#160;&#160; </p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Could sealing a class be a sign of a good design</title>
		<link>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=could-sealing-a-class-be-a-sign-of-a-good-design</link>
		<comments>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:50:15 +0000</pubDate>
		<dc:creator>Andreas Håkansson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/</guid>
		<description><![CDATA[I recently attended this years Øredev conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, Philip Laureano. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended this years <a title="Read more about the Øredev conference" href="http://oredev.com/2010" target="_blank">Øredev</a> conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, <a title="Visit the twitter profile of Philip Laureano" href="http://twitter.com/philiplaureano" target="_blank">Philip Laureano</a>. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do not know the full details of his exact opinions). Anyway, the short version is that the person suggested that classes should be sealed by default, or at least have the developer explicitly state if the class should be sealed or closed.</p>  <p>My immediate reaction was that this was a terrible idea and that I had been struck down too many times by sealed classes before. But then I started thinking that maybe it was not such a bad idea after all. Maybe it even was a sign of a well designed class and that more developers would be better of by sealing their classes.</p>  <p>Now let me inform you that I am still on the ropes about this, but I would like your thoughts on it. In fact I am hoping that the most interesting part of this post will end up being the discussion in the comment section.</p>  <p>So when you take a moment to think about the <em>S.O.L.I.D principles</em>, most specifically the <em>Open-Closed Principle</em> and <em>Dependency Inversion Principle</em>, a long with the old design principle of ‘Favor <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> over <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)">class inheritance</a>’ then maybe it is not such a bad thing after all. Throw in interfaces into the mix and program to an interface and not an implementation, and it will enables you to create different branches if needed. If your classes can flourish while being sealed, chances are that you have some pretty nice structures code in your hands.</p>  <p>There probably are some legit reasons to not seal classes at time, despite the reasoning above, so I am not going to be definitive and say that is never the case. Voice your thoughts in the comments and let us see where this ends up – who knows, I might be left standing as a fool!</p>  <p>As always, you can find me on twitter by the name of <a title="Visit me on twitter" href="http://twitter.com/thecodejunkie" target="_blank">@thecodejunkie</a></p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
		<comments>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 22:40:49 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/</guid>
		<description><![CDATA[Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended? I was working on building an automated testing framework for a welfare system in which cases could be added [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended?</p>  <p>I was working on building an automated testing framework for a welfare system in which cases could be added and benefits run for a given month.</p>  <p>A typical scenario might be something like:</p>  <ol>   <li>Create a new case for this month. </li>    <li>Add some people, do some things. </li>    <li>Run benefits for this month. </li>    <li>Run benefits for the next month.&#160; Something should happen because the child on the case is now 19. </li> </ol>  <p>Seems pretty straightforward until you consider what happens if someone hard codes dates into the test.</p>  <p>I am sure you can imagine plenty of scenarios in a situation like this where hard coded dates would eventually cause all kinds of problems.</p>  <p>The problem is… </p>  <p><strong>If you create an API which takes in various dates, how do you ensure the dates passed in are calculated and not just hard coded?</strong></p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pigsinblanket" border="0" alt="pigsinblanket" src="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket_thumb.jpg" width="514" height="514" /></a> </p>  <h2>Why convention doesn’t work</h2>  <p>Your first response might be to create some documentation that describes the importance of making dates “float” forward with time, and not be hard coded.</p>  <p>You might clearly describe how you should not hard code July 7th 1990 to be the birth date of a 20 year old for a test case.</p>  <p>You might give some guidelines of how to properly calculate ages.</p>  <p>But, you have no way of making sure the users of your API will follow those conventions or even read your document.</p>  <p>What if we do the hard work for them?</p>  <h2>Why utilities are still not good enough</h2>  <p>The next idea you might have is to create utilities that would do date conversions and calculate ages for the user of your API, so that they just have to remember to use them and all will be good.</p>  <p>This solution is better than one relying purely on convention, but still has some major flaws.&#160; Part of the problem of utility methods is that they are not self-discoverable.&#160; I’ve <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">talked about before</a> how DateUtilities like classes can get overlooked if you don’t know the utility class is there.</p>  <p>If you are relying on your users to go out and find your utility methods to make life easier for them, you are putting a large amount of responsibility in the wrong place.&#160; In my experience, it is very unlikely that anyone but yourself will actually use the utility methods.</p>  <p>You really need a way to stop them from being able to hard code dates.</p>  <h2>How can you stop someone from hard coding dates?</h2>  <p>Don’t accept dates in your API.</p>  <p>It is simple.</p>  <p>What?&#160; What do you mean?&#160; You can’t just stop accepting dates, you need dates.&#160; Not just dates, but integers, or strings.&#160; You can’t just not accept the bad data… or can you?</p>  <p>Consider wrapping the data type in another data type which creates your desired data type, but only using the convention or rules you desire.</p>  <p>Let me show you an example with the dates:</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(DateTime applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>    DoSomethingWithTheDate(applicationDate);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(<span style="color: #0000ff">new</span> DateTime(1990, 7, 8));</pre>
<!--CRLF--></div>
</div>

<p></p>

<p>In the above example, you can see that I am directly taking a .NET DateTime object.&#160; You can also see that I am directly hard coding a date when calling this method.</p>

<p>Let’s see if we can fix that.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(CaseDate applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     DoSomethingWithTheDate(CaseDate.ToDateTime());</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(CaseDate.YearsAgo(20));</pre>
<!--CRLF--></div>
</div>

<p></p>

<h2>What happened?</h2>

<p>Here is what we did:</p>

<ol>
  <li>We created a custom type called CaseDate. </li>

  <li>We replaced all the external usages of DateTime with CaseDate. </li>

  <li>We provided methods on CaseDate which allow the creation of dates, only through the way we want to allow them to be created. </li>
</ol>

<ol>Now we can easily prevent users of the API from being able to create hard coded dates.&#160; The API only will take CaseDate objects and internally creates DateTime objects from the CaseDate objects.</ol>

<ol>We can add other methods to CaseDate to allow the creation of dates from x number of months ago or in the future, or any other valid creation method we want.</ol>

<p>By doing this, we are restricting the valid set of inputs to our methods at compile time, not throwing exceptions at run time.</p>

<p>We are achieving the same kind of valuable input constrictions that we have been able to <a href="http://elegantcode.com/2010/05/08/the-power-of-enum/">achieve with enumerations</a>, except we are adding more complex restrictions than a simple list of selections.</p>

<h2>Where can I use this?</h2>

<p>Not just dates.&#160; There are many places where restricting the input to your method or API is going to simplify logic, protect against error conditions, and enforce constraints.</p>

<p>Consider using this pattern in some of these scenarios:</p>

<ul>
  <li>You want to use an enumeration, but your list of possible choices is too large, or repetitive. </li>

  <li>Anywhere you are using a primitive type and that primitive type represents some more complex concept. </li>

  <li>Anywhere you have parameter validation or manipulation repeated in multiple methods. </li>

  <li>Anytime you process some input or repeat a series of steps to transform it before sending it as input. </li>
</ul>

<p>Every time you are about to make a primitive type a parameter to a method you should ask yourself if it makes sense to wrap the primitive type into an class.</p>

<p>Remember, especially when creating an API, any time your method takes a primitive type, you lose the ability to constrain that input, and are forced to validate it instead.</p>

<p>Should you always wrap all primitive types?&#160; No, but it is another tool you can use to provide an extra layer of indirection between the logic of your API and your callers use of it.</p>

<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Prefer Additional Methods Over Additional Overloads</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
		<comments>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 17:35:54 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/</guid>
		<description><![CDATA[If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do. Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do.</p>  <p>Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are conscious of making that code as readable and terse as possible.</p>  <p><strong>Seldom do we think about the use of our code from an API standpoint.</strong></p>  <p>There is a subtle difference between designing your code in a way that will make it easier for someone else to maintain, and designing your code in a way that will make it easier for someone else to use.</p>  <h2>Intellisenselessness</h2>  <p>How often are you working against some API and you type a method name you want to use only to have intellisense present you with 5 overloads for the method all with several different parameters choices?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginOverloads" border="0" alt="LoginOverloads" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads_thumb.png" width="600" height="151" /></a> </p>  <p>Which one do you use?&#160; It is hard to be sure, you end up having to read through the long lists of parameters to figure out what method you should call and what parameters you should pass it.</p>  <p>Wouldn’t it be better if you were presented with what the method does in the method name rather than guessing what it does in the parameter list?&#160; Something like this?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginMoreMethods" border="0" alt="LoginMoreMethods" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods_thumb.png" width="596" height="261" /></a> </p>  <h2>Perspective</h2>  <p>From the perspective of the person writing the <em>Login</em> method(s), overloads probably seem like the most efficient and correct way to implement the multiple ways the method can be called.</p>  <p>From the perspective of the person using the <em>Login</em> method(s), additional methods are much preferred, because they are easier to understand and know what you are looking for.</p>  <p><strong>Try to think from the perspective of someone using your code when writing your code.</strong></p>  <h2>Extract boolean parameter to two methods</h2>  <p>I want to take a look at a very specific example that can be of great benefit to the readability and use of your code.</p>  <p>Take a look at this code below.</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login(<span style="color: #0000ff">bool</span> rememberMe)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>
Seems like a fine overload of a <em>Login</em> method.&#160; I have written code just like this, you probably have also.&#160; <br />

<p>&#160;</p>

<p>Unfortunately, by adding this overload, we have added some complexity to our API, because now the user of that code has to see that there is an additional overload that take a bool parameter called <em>rememberMe</em>.</p>

<p>Consider this longer alternative.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginDoNotRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Instead of overloading <em>Login</em> and making the user have to decide which overload to call and pass in a parameter, we have elected to create two differently named methods which take 0 parameters and clearly state what they are going to do.</p>

<p>I’m not saying you should never write overloads, but anytime you see an overload in your code base, you should stop and think if it would be more clear to make that overloaded method into two different methods that can eliminate one or more of the parameters.</p>

<p><strong>Any time you are restricting the number of choices someone using your code has to make, you are making that code simpler to use.</strong></p>

<p>If you don’t believe me, consider why the iPhone has only one button.</p>

<h5><strong>As always, you can subscribe to this </strong><a href="http://feeds2.feedburner.com/ElegantCode"><strong>RSS feed</strong></a><strong> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at </strong><a href="http://simpleprogrammer.com"><strong>http://simpleprogrammer.com</strong></a><strong>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Say &#8220;No&#8221; to &#8220;Null&#8221;</title>
		<link>http://elegantcode.com/2010/05/01/say-no-to-null/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=say-no-to-null</link>
		<comments>http://elegantcode.com/2010/05/01/say-no-to-null/#comments</comments>
		<pubDate>Sat, 01 May 2010 19:35:05 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/05/01/say-no-to-null/</guid>
		<description><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after. What do you do if "null” [...]]]></description>
			<content:encoded><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after.
<blockquote>What do you do if "null” is passed in?</blockquote>
My answer may turn out to be a bit of a surprise.
<blockquote><span style="background-color: #f4f5f7;">Nothing, I don’t handle nulls in code that I control the use of.</span></blockquote>
“What?  What?” you say.  “You don’t handle null?  What kind of heresy is that?”  It is the kind of heresy that helps produce elegant code and I will show you why.
<h2>How well do you handle null right now?</h2>
Would you say that in most of the code you write you properly check all arguments for null?

Or, do you like most developers, handle null in certain cases when you happen to think about it, or after the application dumps a “null pointer exception” stack trace?

Be honest, look at your code if you have to.

The problem is “d00d ur d0ing it r0ng!”

<a href="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="john-mccarthy-programming-completely-wrong" src="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong_thumb.jpg" border="0" alt="john-mccarthy-programming-completely-wrong" width="349" height="452" /></a>

Unless you are some kind of anal retentive perfectionist, you are probably not handling null in every single method call.  That means there are huge potential bugs in the code that you are writing which will throw null pointer exceptions.  That is bad, I agree.

So, if you are not handling it correctly right now, then what can you do to fix that?
<h2>Avoiding null in the code you “own”</h2>
You can’t control external libraries.  And you can’t control how people will use your code, but you can control the code you write and you can, to a degree, control the code your shop writes.

The better strategy is to never pass null in the first place.

You can either focus your efforts on:
<ul>
	<li>Checking for null</li>
	<li>Not ever passing null</li>
</ul>
<ul>The more elegant solution is to focus on never passing null.  By doing this you will end up writing less code and avoid decisions about how to handle null inside of a method that doesn’t have enough context to decide what to do.</ul>
Let’s look at an example:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> TransmographyThreeStrings(<span class="kwrd">string</span> first, <span class="kwrd">string</span> second, <span class="kwrd">string</span> third)
{
     <span class="kwrd">if</span>(<span class="kwrd">string</span>.isNull(first) || <span class="kwrd">string</span>.isNull(second) || <span class="kwrd">string</span>.isNull(third))
    {
           <span class="rem">// hmm, I donno, what should I do?  Should I throw an exception?</span>
           <span class="rem">// should I return an empty string?</span>
           <span class="rem">// what if the first string wasn't null, can we still do something meaningful?</span>
           <span class="rem">// how will the caller of the method know what I will do?</span>
    }

}</pre>
You can see there that we are checking each parameter for null.  The problem is we don’t know what we should do.  We have lots of options, but none of them are obvious.

How much better is it to make sure that we never pass null into methods, rather than write this kind of code in every method?
<h2>What about accidentally passing in null?</h2>
Many of you are probably thinking at this point that the main way null gets passed into a method is because someone calls a method without knowing that it contains a null value.
<pre class="csharpcode">TransmographyThreeStrings(<span class="str">"Hello"</span>, <span class="str">"World"</span>, mysteryObject.Text);</pre>
Perhaps <em>mysteryObject.Text </em>is null.  You wouldn’t even know it.

Ah, but you can.  Or you can prevent it at least.  Somewhere <em>mysteryObject </em>gets created.  When it gets created its values either get initialized or not.  You can prevent any of its values from being null, several ways:
<ul>
	<li>Always initialize variables when they are declared.</li>
	<li>Use a <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> to ensure that objects are always fully constructed before being created.</li>
	<li>Use properties to provide default values or lazy initialize.</li>
	<li>Make your objects <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> as much as possible.</li>
</ul>
The practices that prevent null from accidentally being passed in make your code much more elegant than repeating <em>if blah == null</em> code all over the place.

<strong>In general, you should always strive to eliminate the passing of null rather than checking for null.  By doing so you reduce extra lines of code in each method, and are forced to use better design practices.</strong>
<h2>Exceptions</h2>
Yes, there are times when you need to check for null.  If you are writing a library that external developers will use, then you will probably want to check for null in all of your methods that are exposed as part of the API.  (On your internal methods, you don’t need to since you have already cleansed the input.)

Also, if your code is being used as a callback to some API and you don’t know if it can ever pass null into your code, you probably should check for null.

A bad excuse is that other developers may pass null to your method. <strong>It is much better as a software shop to put the onus of not passing null on the caller of any method rather than putting it on the writer of the method being called.</strong>

You will also reduce your exception handling code, because you will have less exceptions for invalid parameters.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/05/01/say-no-to-null/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>If Self-Documenting Code is the What, Unit Tests are the Why</title>
		<link>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-self-documenting-code-is-the-what-unit-tests-are-the-why</link>
		<comments>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:09:04 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/</guid>
		<description><![CDATA[It is not enough to just write code that is clean and self-documenting.  Eliminating comments and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it. If you recall from my original post on [...]]]></description>
			<content:encoded><![CDATA[It is not enough to just write code that is clean and self-documenting.  <a href="http://elegantcode.com/2010/04/18/eliminating-comments-the-road-to-clarity/">Eliminating comments</a> and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it.

If you recall from my <a href="http://elegantcode.com/2010/04/09/what-does-elegant-code-mean-to-me/">original post</a> on Elegant code, I stated that elegant code is:
<blockquote>Something that is simple yet effective, delivered with grace.</blockquote>
By writing self-documenting code we are hopefully able to achieve some of the aspects of simplicity and grace, but it tells us nothing about the effectiveness of the code.
<h2>Bringing the dead to life</h2>
<a href="http://elegantcode.com/wp-content/uploads/2010/04/zombies.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="zombies" src="http://elegantcode.com/wp-content/uploads/2010/04/zombies_thumb.jpg" border="0" alt="zombies" width="441" height="295" /></a>

Throwing out comments is a debatable topic.  <a href="http://www.reddit.com/r/programming/comments/bsutx/">It raises quite a bit of controversy</a>, as you can see from some of the comments on my post about the subject.  The reason, perhaps, that so many people are so staunchly opposed to the idea, is because they are worried, and rightly so, that throwing out comments will reduce the documentation of what the code is doing.

Think about that for a second.  Is documentation of what the code is doing important?  It better be.  What we are trying to accomplish by writing self-documenting code instead of comments, is to take the vessel, which is the code itself, and make that same vessel be the documentation of what the code does.  It is by doing this that we creating a living representation of the functionality of the code.  Comments are akin to a dead representation of the functionality of the code because they do not change automatically with the code.

I diverge to talk about comments so that I can draw a parallel to another form of documentation which is valuable and should be considered necessary.  That other set of documentation is requirements.  Have you ever written requirements documents?  Have you ever captured requirements from the customer and put them into UML diagrams, or perhaps plopped them into some templated Word document, which is never updated again, and no one reads, because no one trusts it is correct?  Wouldn’t it be great if we would replace that dead document or set of documents, with a living one?

The good news is we can, and some of us have.  And I fully expect this recommendation will be just as controversial, because <strong>I am suggesting that we don’t have to write low level specifications of the system at all, instead we can write good unit tests. </strong>When we do this, we are taking a dead form of document and bringing it to life.
<h2>Unit tests tell us why and how our code is effective</h2>
If
<pre class="csharpcode">i = 5;  // Widget count defaults to five.</pre>
is replaced with
<pre class="csharpcode">widgetCount = DEFAULT_WIDGET_COUNT;</pre>
<!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

then
<blockquote><span style="background-color: #ffffff;">1.1.5 When a new widget is created, the widget count should be increased by one.</span></blockquote>
is replaced with
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> When_NewWidgetIsCreated_Then_WidgetCountIsIncreasedByOne()
{
     WidgetFactory.Count = 3;
     WidgetFactory.CreateNew();
     assertEquals(4, WidgetFactory.Count);
}</pre>
The unit test is replacing the low level requirement, which is somewhat open to interpretation and untied to the code, with an absolute and completely tied-to-the-code, specific requirement.

The unit test is telling us why our code is built the way it is.  It is telling us what requirement that particular structure of code is trying to address.  <strong>It is telling us what end result that code is trying to accomplish and what the expectations are on the results of a given condition.</strong>

The unit test is telling us how the code is to be used in order to achieve its result.  It is serving as a living reference to the syntax and use of the code we built.  <strong>Instead of providing instructions on how to use our API, we are providing a living example, and proof that it will indeed work.</strong> Examples are often much more effective than instructions anyway.
<h2>What exactly are we replacing?</h2>
At this point we are not trying to replace all the documentation of the system (at this point).

With self-documenting code, we sought to eliminate comments, and replace them with good variable and method names.

With unit tests, we seek to eliminate technical documentation and requirements of the system, that is targeted at a developer or technical audience.

We are NOT trying to eliminate high level specifications of the system, or use cases. <strong>Unit tests DO NOT replace that kind of documentation! </strong>We will talk about replacing that kind of documentation when we talk about automated functional or system tests.

Simply put, any kind of documentation that you would give to a developer so they understand how the system works and how to use the code or APIs, can be easily replaced by writing good unit tests.

Our simple goal is to replace the “dead” documentation (meaning that it does not update automatically with the thing it is documenting), with “living” documentation in the form of unit tests.

One last point.  I want to be clear that I am not saying that having unit tests automatically results in the ability to replace technical documentation.  Just like having long-named methods and variables doesn’t automatically replace the need for comments.  It is a matter of the quality of the unit tests that are written, just as it is a matter of the quality of the self-documenting code.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>REST: Resources, URI&#8217;s and Representations</title>
		<link>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rest-resources-uris-and-representations</link>
		<comments>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 04:00:13 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/</guid>
		<description><![CDATA[In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions. Resources Resources are at the heart of REST.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions.</p>  <h3>Resources</h3>  <p>Resources are at the heart of REST.&#160; You are already used to resources as a web browsing consumer.&#160; A resource is not something specific to REST, instead it is the first thing you probably want to consider when architecting a RESTful application.&#160; A resource is simply the entity, item, or thing you want to expose.</p>  <p>Perhaps you have approached application architecture using one or many of several modeling and design techniques.&#160; Data First practitioners typically begin with databases and data models.&#160; DDD proponents like to begin by modeling around business entities and interactions, while their cousins in the BDD camp model around business activities.</p>  <p>When you decide to apply REST you will need to think a lot more about data entities and domain objects as resources.&#160; Your existing models may or may not closely map to resources.&#160; The shift in thinking may appear slight, but is very important.&#160; It centers around making things&#160; addressable.&#160; Each resources must by uniquely identifiable as we will see in the next section.&#160; We are used to identity with most data entities, but our domain objects may not always be as easily identifiable.&#160; Likewise, our data entites may have identity, but not map to a resource.&#160; </p>  <p>Consider the classic customer and order scenario for example.&#160; If each customer and each order can be identified then it will be easy to design RESTful systems around them.&#160; However, if the model requires a lot of context then our challenge is a little bit larger.&#160; Perhaps we must first identify a partner, then a year, then a customer, and finally the order.&#160; Yes, that is a design smell in general.&#160; It makes fetching an order very difficult.&#160; Developing RESTfuly would only further expose that difficulty.&#160; Identifying your resources up front will help you reduce the possible impedance mismatches you might end up with between what you want to expose and your data or domain models.</p>  <p>REST is about interacting with Resources!</p>  <h3>URI’s</h3>  <p>REST defines the identity of a resource via URI.&#160; Each resources has a unique address in URL form (ie. using the http protocol).&#160; Interaction with a resource will take place at its URI.&#160; As an example, my twitter status feed resource URI is <a title="http://twitter.com/optionstrict" href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; That URI is unique to my feed and that is what you expect to find at that URI.&#160; In the Twitter databases or domain models my account may be referred to by the string optionstrict, or perhaps as some random number or guid.</p>  <p>To consume my status history via a service interface twitter provides another URI at <a title="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict" href="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict">http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict</a>.&#160; I would actually prefer to have access at the same URI for html, json, and xml formats.&#160; Twitter probably has its reasons for distinguishing API access from HTML rendering, but they have actually complicated their architecture by doing so.&#160; When designing the URI’s for your resources, make them easy for your users to work with.&#160; </p>  <h3>Representation</h3>  <p>Lets continue with the twitter example to describe what is meant by Representation.&#160; Given a URI and a Resource, what will your consumers receive when they issue a GET request to the URI?&#160; Twitter chose a representation of my account and included status history and profile for the response at <a href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; They decided to put a representation of my profile photo at <a title="http://twitter.com/account/profile_image/optionstrict" href="http://twitter.com/account/profile_image/optionstrict">http://twitter.com/account/profile_image/optionstrict</a>.&#160; In your REST solutions you will need to consider how you want to represent a resource at its URI.&#160; Each representation will have a unique URI.&#160; </p>  <p>Representations are also important for manipulating resources.&#160; You must define the representation required to create and update resources.&#160; Twitter status updates require a text representation with a maximum of 140 characters.&#160; They allow additional values in the status representation, such as latitude and longitude.&#160; Your REST solutions similarly must define representations for Requests and Responses.</p>  <p>I hope that this short introduction has helped you to see that the core essence of REST is simple and fairly obvious.&#160; As you look at your current solutions what are the resources you are exposing?&#160; Could you make those resources identifiable by URI?&#160; What representation would you place at each URI?&#160; What representation would you require for manipulating a given resource?</p>  <p>Also, notice I did not mention much about data formats, Content Type, Mime, etc.&#160; Those details can cloud your design if you try to start with them. If you can’t wait for my post about how REST handles html, json, xml from the same URI, then start googling Content Negotiation, Accept header, and Content-Type header.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Driven Architecture: Publishing Events using an IOC container</title>
		<link>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=christmas-light-architectures-are-not-that-shiny</link>
		<comments>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:00:00 +0000</pubDate>
		<dc:creator>Jan Van Ryswyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/</guid>
		<description><![CDATA[I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way [...]]]></description>
			<content:encoded><![CDATA[<p>I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way overdue :-).</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb1.png" width="202" height="172" /></a> </p>  <p><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles\778e7174-33ed-4def-8d4c-61f9b172c5e8\10274611.jpg"></a><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles\778e7174-33ed-4def-8d4c-61f9b172c5e8\10274611.jpg"></a>What's the major malfunction with those old, classic Christmas lights? We've all experienced it at some point. When one goes out, all the others go out as well. This is due to the fact that these lights are wired in series. The difference compared with today's Christmas lights is that every bulb has a shunt, which basically prevents this kind of failure caused by one or more lamps. Enough about the Christmas lights for now. Where am I going with this? Back in enterprise IT, I'm seeing the same kind of failures as with those classic, old Christmas lights.</p>  <p>The diagram below shows a classic RPC style architecture, much like those classic, old Christmas lights. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb2.png" width="565" height="329" /></a> </p>  <p>This is all fine and dandy as long as every part of the chain runs without too much hassle. But what happens if for some reason the centralized back-end web service goes down (light bulb goes out). This means that every smart client, website and batch application that uses this web service gets affected by this, like some sort of chain reaction. Parts of these client applications will no longer function correctly or they might even go down entirely. Same thing happens when the database of the centralized back-end web service goes down or any other external system that it depends on. When being confronted with this kind of architecture, how would one go about preventing this doomsday scenario to happen?</p>  <p>Suppose you’re a developer that has to work on the centralized back-end web service. This is usually a complex system as it obviously has to provide features for all kinds of applications. When this centralized back-end web service also has to deal with and depend on other external systems that might expose some unexpected behavior, how could one prevent the sky from falling down when things go awry in production?</p>  <p>Well for starters, you could start building in some stabilization points. Suppose for some reason, the centralized web service needs to incorporate some functionality offered by a highly expensive, super enterprise system that for some reason behaves very unstable and unpredictably on every full moon (expensive enterprise software not behaving correctly sounds ridiculous, but bare with me ;-) ). For example, we could use a message queue as a stabilization point. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb3.png" width="570" height="157" /></a> </p>  <p>This means that we put a message on a queue that is processed by some sort of worker process or service that does the actual communication with the misbehaving system. When the external system goes down, the message is either left on the message queue or put on an error queue for later processing when the external system comes back up again. There are some other things you need to think about like idempotent messaging, consistency, message persistence when the server goes down, etc. … . But if one of these dependencies goes down, the centralized back-end web service is still up-and-running which means that the systems that depend on its functionality can also continue to serve their users as they are able to keep doing their work.</p>  <p>Earlier this week I overheard this conversation that somewhat amazed me. I changed the names of the persons involved as well as the exact words used in order to protect the guilty.</p>  <blockquote>   <p><em>George: </em><em>We want to incorporate a message queue in order to guarantee stability and&#160; integrity between several non-transactional systems that our system depends on. It will also improve performance as these systems behave very slow at times and become unstable under pressure. This also gives us the opportunity to root out some major points friction that our end-users are experiencing right now.</em></p>    <p><em>Stan: But this means that the end-users are not completely sure if their actions are indeed fully carried out by the system. </em></p>    <p><em>George: End-users can always check the current state of affairs in their applications. If something goes wrong, their request is not lost and things will get fixed automatically later on as soon as the cause of the error has been fixed. </em></p>    <p><em>Stan:&#160; I don’t think that’s a very good idea. End-users have to wait until everything is processed synchronously, even if that means that they’ll need to wait for a long time. And if one of the external systems goes down, they should stop sending in new requests. Everything should come to a halt. They just have to stop doing what they are doing.</em></p>    <p><em>George: This means that because you lose the original request, some external systems might be set up correctly while others are not. Then someone has to manually fix these issues.</em></p>    <p><em>Stan: Then so be it!</em>&#160;</p> </blockquote>  <p>For starters, I was shocked by this conversation. This is just insane. Everything should come to a halt? Think about this scenario for a while: suppose you’re finding yourself in a grocery store with a cart full of food, drinks and other stuff. You come at the cash register where the lady kindly says “Can you put everything back on the shelves please? There are some issues with the cash register software and we are instructed to stop scanning items and serve customers until these issues are fixed. Can you come back tomorrow please?”. Uhm, no! How much money do you think this is going to cost compared to the system that makes use of stabilization points? An end-user that is able to keep doing its work, whether the entire production system is down or not has tremendous business value. </p>  <p>I’m not saying that message queues are a silver bullet. I’m just using these as an example. As always, there is a time and place for using them. There are other things a developer can incorporate in order to increase the stability of the system he’s working on, like <a href="http://davybrion.com/blog/2008/05/the-circuit-breaker/" target="_blank">the circuit breaker pattern</a>. I’m also not saying that every system should be built using every stabilization point one can think of. This become a business decision depending on the kind of solution. As usual, it depends.</p>  <p>But the point that I’m trying to make here is that we should stop putting software systems into production and just hoping for the best. That’s just wishful thinking. Software systems are going to behave badly and at some point they will go down. It’s just a matter of when this is going to happen and how much damage this is going to make.</p>  <p>The first step to take is awareness. I encourage you to pick up this book titled ‘<a href="http://www.amazon.com/exec/obidos/ASIN/0978739213/elegantcode-20" target="_blank">Release It!</a>’, written by <a href="http://www.michaelnygard.com/" target="_blank">Michael Nygard</a>. This book is all about designing software that can survive this though environment called production. I can only hope that Stan picks up a copy as well along with some common sense.</p>  <p>Till next time.&#160;&#160;&#160; </p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Elegant Code &#187; Architecture</title>
	<atom:link href="http://elegantcode.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quinine For Sale</title>
		<link>http://elegantcode.com/2012/01/18/monitoring-an-mmo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-an-mmo</link>
		<comments>http://elegantcode.com/2012/01/18/monitoring-an-mmo/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:45:32 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MMO]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2012/01/18/monitoring-an-mmo/</guid>
		<description><![CDATA[I’ve been working on a free-to-play MMO Quinine For Sale, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I’ve been working on a free-to-play <a href="http://www.heroup.com" target="_blank">MMO</a> <b>Quinine For Sale</b>, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before they become serious and fixing problems when they inevitably do.&#160; So, there are two questions.&#160; “Is there a problem in the game?” “What is causing the problem?”&#160; </p>  <p>When trying to debug something on our development and test clusters, typically you can tail log files.&#160; We have a python script that can monitor the communication between various parts of the game and pretty-print it along with color to highlight “this is a problem!”&#160; Attaching a debugger to a running process is also not uncommon.&#160; However, looking at logs and bus traffic in realtime on a production environment gives you this neat “Matrix-y” experience.&#160; Attaching a debugger to a production process (assuming you could, which you can’t) would get you smacked with a rolled-up newspaper.&#160; “Bad Developer!&#160; No treat!”&#160; So, what can you do?</p>  <h4>Monitoring</h4>  <p>When you’ve got clusters full of machines, using <a href="http://www.nagios.org/" target="_blank">Nagios</a> to monitor things is an obvious solution.&#160; Beyond making sure the power is on and other sysadmin things, we’ve written other checks to see if the login process is working, the parts are working together, and automating typical in-game functions.&#160; For example, if nagios can’t successfully log into the game do basic game activity, then alerts happen.</p>  <h4>Metrics for EVERYTHING</h4>  <p>Anything that happens in game has metrics reporting tied to it, generating piles of data constantly.&#160; We use <a href="http://www.cacti.net/" target="_blank">Cacti</a> to visualize game activity.&#160; An example metric is concurrent users, or CCU.&#160; We graph how many people are in the game over time, which when things are healthy should be a nice smooth curve climbing to peak game hours, then descending nicely through the night.</p>  <p>We can tell by sight if the game looks healthy or not – if the CCU graph is jaggy, has a sudden drop or spike, or drops to zero then we know that something is wrong.&#160; Typically nagios alerts accompany the graphs, giving more data points on where to look.&#160; But this has also pointed out areas where a nagios check was missing or wasn’t working as intended.</p>  <h4>Log Files</h4>  <p>When a player gets an error in game, the error dialog box gives them the opportunity to submit the error details back to us.&#160; If we see a spike in user-reported errors through this or other customer service means, we know we have something of interest to look for.&#160; </p>  <p>The game server components make use of log4j and similar logging frameworks.&#160; Anything that you’d want to watch happening in game needs to be aggressively logged.&#160; All components are configured so that operations can change the log level on the fly.&#160; That’s still quite a bit of data across many machines though, so all that information is run through <a href="http://www.splunk.com/product" target="_blank">Splunk</a> to be indexed and searchable.&#160; This gives us a great tool for searching through log data, examining trends, or watching selected activity in real time.&#160; Unfortunately it is very expensive so we are selective about the data that passes through it.&#160; </p>.  Buy Quinine from mexico.  Buy Quinine no prescription.  No prescription Quinine online.  Online buying Quinine.  Quinine no prescription.  Quinine street price.  Buy no prescription Quinine online.  Quinine coupon.  Quinine over the counter.  Where can i buy Quinine online.  Quinine steet value.  Where to buy Quinine.  Order Quinine online overnight delivery no prescription.  Quinine recreational.  Quinine canada, mexico, india.  Ordering Quinine online.  Quinine without prescription.  Quinine price, coupon.  Quinine description.  Order Quinine from mexican pharmacy.  Quinine pics.  What is Quinine.  Japan, craiglist, ebay, overseas, paypal.  Order Quinine from United States pharmacy.  Order Quinine online c.o.d.  Quinine trusted pharmacy reviews.  Quinine treatment.  Buy Quinine from canada.  Quinine used for.  Discount Quinine.  Is Quinine addictive.  Quinine forum.  Buy Quinine online no prescription.  Is Quinine safe.  Purchase Quinine for sale.  Effects of Quinine.  Buy Quinine online cod.  Quinine australia, uk, us, usa.  Buy Quinine without prescription.  Quinine online cod.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4721'>Buy Flonase Without Prescription</a>. <a href='http://elegantcode.com/?p=4234'>Buy Periactin Without Prescription</a>. <a href='http://elegantcode.com/?p=4203'>Buy Armour Without Prescription</a>. <a href='http://elegantcode.com/?p=4899'>Buy Macrobid Without Prescription</a>. <a href='http://elegantcode.com/?p=4534'>Xalatan For Sale</a>. <a href='http://elegantcode.com/?p=4302'>Phenergan wiki</a>. <a href='http://elegantcode.com/?p=4268'>Soma maximum dosage</a>. <a href='http://elegantcode.com/?p=4602'>Zovirax treatment</a>. <a href='http://elegantcode.com/?p=4578'>Cialis price, coupon</a>. <a href='http://elegantcode.com/?p=4189'>Flexeril price</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.leaduganda.org/?p=514'>Quinine For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=4820'>Quinine For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2780'>Quinine For Sale</a>. <a href='http://www.thegriffonnews.com/?p=10177'>Quinine For Sale</a>. <a href='http://www.independentworldreport.com/?p=2409'>Quinine For Sale</a>. <a href='http://changecamp.ca/?p=295'>Quinine description</a>. <a href='http://social-blend.com/?p=624'>Quinine price, coupon</a>. <a href='http://blog.farmland.org/?p=3946'>Online buying Quinine hcl</a>. <a href='http://4realz.net/?p=1595'>Quinine from canada</a>. <a href='http://reversemortgagedaily.com/?p=14535'>Where to buy Quinine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2012/01/18/monitoring-an-mmo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temovate Cream For Sale</title>
		<link>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-software-development-will-never-be-engineering</link>
		<comments>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 03:37:48 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/</guid>
		<description><![CDATA[I always find it rather interesting when academics try to quantify generalized metrics about software development. Temovate Cream For Sale, Things like: per lines of code, there will be X number of bugs. Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.” These are all interesting [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I always find it rather interesting when academics try to quantify generalized metrics about software development.</p>  <p> <b>Temovate Cream For Sale</b>, Things like: per lines of code, there will be X number of bugs.</p>  <p>Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.”</p>  <p>These are all interesting thoughts, but software development will never conform to rigid engineering principles like many other engineering practices.&#160; The longer I work in the field, the more and more I realize that software development has nothing to do with engineering.&#160; We just happen to attend some of the same math classes in school.</p>  <h2>Building bridges</h2>  <p>One of the main arguments I hear people make about the current state of software development as an engineering practice is based around its relative maturity to other engineering fields.</p>  <p>There is a huge problem with this line of thinking.</p>  <p>The argument goes something like this:&#160; “<em>Engineering has been around for hundreds of years and has matured to the point where it is a measurable science, but software development has only been around in earnest for the last few decades or so, therefore it is relatively immature as an engineering discipline.”</em></p>  <p>On the surface this argument seems sounds.&#160; And certainly in 50 years software development will be different than it is now.&#160; Heck, it is much more different than it was just 10 years ago.</p>  <p>But, here is the problem.&#160; We build much more software than we do bridges.</p>  <p><img src="http://www.nps.gov/glca/historyculture/images/Navajo_Bridges_1.gif" width="589" height="442" /></p>  <h6 align="center">&#160;</h6>  <p>Let me give you an example that came to light in another area of my interest… poker.</p>  <h1></h1>  <h2>The poker quickening</h2>  <p>An interesting thing happened in the poker community in the last 10 years; poker pros with decades of experience started getting beat time and time again by 19 year old poker prodigies.</p>  <p>From an outside perspective it looks like the poker world opening up just widened the search for talent and there it was.&#160; But, a closer examination of the evidence leads to the truth.</p>  <p>Before the online poker industry was born, poker was played in card rooms and casinos in states where it was legal and occasionally at small home games throughout the US.</p>  <p>A poker pro might play poker tournaments perhaps 100 times to 150 times a year.&#160; The sum knowledge of the poker community and the meta game around it was based on this base of professional poker players playing tournaments and gaining experience at this mediocre rate.</p>  <p>Once the internet poker rooms started opening up, things changed, and they changed rapidly.&#160; Now anyone could play poker from their home PC.&#160; Not only could they play poker, they could play poker tournaments at all hours of the day.</p>  <p>Here is a list of some of the major changes that took place:</p>  <ul>   <li>Hands are dealt at 60-80 hands per hour instead of 10-30</li>    <li>Players can play in many tournaments at one time, 10 tournaments at once is not unheard of</li>    <li>Players can analyze hand histories and historical data about their play and opponents play through the use of software </li>    <li>Age requirements are out the window, technically any one of any age could be playing online</li>    <li>Players can play 24 hours a day</li>    <li>The professional online tournament player could easily play over 3000 tournaments in a year, while a brick and mortar pro would be lucky to reach 100 in a year.</li>   <img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://t1.gstatic.com/images?q=tbn:ANd9GcRj9uGNWSyqGWEneiH6xaBAyS6COwGYicdNadZu-06KWQLhIi6LMw&amp;t=1" width="316" height="270" /></ul>  <p>&#160;</p>  <p>So where am I going with all this?</p>  <p>The point is that as a whole more hands were dealt and more poker knowledge and experience was obtained in 1 year of online poker than probably the entire history of poker before that.&#160; We reached such an accelerated pace of play that all previous knowledge of poker became obsolete.&#160; </p>  <p>The strategy of tournament poker completely changed.&#160; The game evolved perhaps 500 years into the future in a matter of 5 years time.</p>  <p>The same has happened with software development.</p>  <h2>Back to the bridge building</h2>  <p>So let’s take that poker example and look at it through the lens of software development.</p>  <p>Let us compare the engineering maturity to software development to the engineering maturity of the engineering discipline of building bridges.</p>  <p>I think most people would agree that bridge building is a very mature engineering discipline but many people would argue that software development is not.</p>  <p><strong>How many bridges do you think have been built in the world?</strong></p>  <p>Well there are <a href="http://www.betterroads.com/category/bridge-inventory/erroads.randallreillycms.com/files/2009/11/BR1109_BridgeInventory.pdf">about 600,000 bridges in the United States alone</a>, so the world figure must be at least somewhere around 10 times that number perhaps 20.</p>  <p><strong>How many software programs have been written?</strong></p>  <p>This is a very hard number to estimate, but lets take a rough guess based on <a href="http://stackoverflow.com/questions/453880/how-many-developers-are-there-in-the-world">how many software developers there are in the world</a>.&#160; </p>  <p>If we say there are about 12 million software developers and each software developer has written approximately 3 programs, we can estimate that a large amount more programs have been written than bridges built.</p>  <p>My point is not to knock bridge building, we are pretty good at it as a whole, but rather to show that collectively, even though we have been building bridges for hundreds of years, we have probably devoted an equivalent amount of time to building software.</p>  <p>This line of thinking may lead you to argue back that software development and bridge building are very different.&#160; Bridge building has a fixed set of requirements that are pretty close to the the same for each bridge you build, but software development is a big open void of whims and ambiguously contradictory statements.</p>  <p>I agree with you 100%!&#160; And in essence that is my point.</p>  <h2>Software development is different</h2>  <p>And we have had enough time to realize that.&#160; Waiting for software development to gel into some kind of engineering discipline like other engineering disciplines is like waiting for water without gelatin mix to turn into Jello.&#160; </p>  <p>It’s just not going to happen!</p>  <p>In my mind it is clear that the argument that we haven’t given it enough time is just wishful thinking.&#160; The nature of software development, just like online poker, leads itself to rapid evolution.</p>  <p>Consider what direction software development is evolving.&#160; Is it even evolving in the direction of rigid engineering practices or is it evolving in the exact OPPOSITE direction?</p>  <p>Ten years ago, we tried to use UML diagrams and CASE tools to develop software.&#160; Ten years ago waterfall was all the rage.&#160; Ten years ago, we thought that ten years in the future we would have programs that would allow us to build software in the same way that CAD tools allow for building machine parts.</p>  <p>Not only did it not happen.&#160; It went completely the other way.&#160; Now we are all talking about Agile.&#160; Now people don’t even remember what CASE tools are.&#160; Now we are building software without trying to define the whole system in UML diagrams.</p>  <p><strong>The fact of the matter is software systems are unruly beasts!</strong></p>  <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://aznbadger.files.wordpress.com/2010/06/beast.jpg" /></p>  <p>In my mind it comes down to one simple distinction.&#160; Software is living, bridges aren’t.&#160; When you are done building a bridge, you are done building the bridge.&#160; </p>  <p>Sure someone, probably not you, will have to come along and do some routine maintenance on it.&#160; Sure, some small things might change about it, but for all intents and purposes the work is done.</p>  <p>In most software development scenarios, this is not the case.&#160; In most software development scenarios, releasing V1 is not even close to the end.&#160; Sometimes V1 and V2 don’t even look that same at all.&#160; Software development is about operating on a living breathing thing and all the while keeping it alive.</p>  <p>The truth is, we software developers have more in common with surgeons than with other engineers.</p>  <h6>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com/">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>.  Buy Temovate Cream without a prescription.  Temovate Cream trusted pharmacy reviews.  Temovate Cream over the counter.  Where can i order Temovate Cream without prescription.  Online buy Temovate Cream without a prescription.  Temovate Cream no rx.  Buy cheap Temovate Cream no rx.  Temovate Cream photos.  Buy Temovate Cream online no prescription.  Order Temovate Cream online c.o.d.  Herbal Temovate Cream.  About Temovate Cream.  Australia, uk, us, usa.  Cheap Temovate Cream.  Temovate Cream class.  Temovate Cream brand name.  Online Temovate Cream without a prescription.  Buy Temovate Cream without prescription.  Buy Temovate Cream from canada.  After Temovate Cream.  Order Temovate Cream from mexican pharmacy.  Temovate Cream without a prescription.  Purchase Temovate Cream.  Temovate Cream natural.  Temovate Cream overnight.  Temovate Cream online cod.  Where can i buy cheapest Temovate Cream online.  Purchase Temovate Cream for sale.  Online buying Temovate Cream.  Purchase Temovate Cream online.  Temovate Cream used for.  Temovate Cream coupon.  Temovate Cream description.  Order Temovate Cream no prescription.  Temovate Cream maximum dosage.  Cheap Temovate Cream no rx.  Temovate Cream images.  Temovate Cream blogs.  Buy Temovate Cream online cod.  Buy generic Temovate Cream.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4472'>Bactroban For Sale</a>. <a href='http://elegantcode.com/?p=4632'>Armour For Sale</a>. <a href='http://elegantcode.com/?p=4639'>Buy Estrace Vaginal Cream Without Prescription</a>. <a href='http://elegantcode.com/?p=4668'>Buy Augmentin Without Prescription</a>. <a href='http://elegantcode.com/?p=4535'>Buy Tindamax Without Prescription</a>. <a href='http://elegantcode.com/?p=4931'>Fast shipping Diclofenac</a>. <a href='http://elegantcode.com/?p=4240'>Combivent brand name</a>. <a href='http://elegantcode.com/?p=4417'>Levaquin overnight</a>. <a href='http://elegantcode.com/?p=4597'>Purchase Toradol online</a>. <a href='http://elegantcode.com/?p=4221'>Australia, uk, us, usa</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.quarterlives.com/?p=1148'>Temovate Cream For Sale</a>. <a href='http://4realz.net/?p=1972'>Temovate Cream For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=5997'>Temovate Cream For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2476'>Temovate Cream For Sale</a>. <a href='http://www.thegriffonnews.com/?p=9947'>Temovate Cream For Sale</a>. <a href='http://social-blend.com/?p=1160'>Temovate Cream brand name</a>. <a href='http://blog.farmland.org/?p=3812'>Where can i find Temovate Cream online</a>. <a href='http://reversemortgagedaily.com/?p=14136'>Generic Temovate Cream</a>. <a href='http://linuxologist.com/?p=1792'>Temovate Cream photos</a>. <a href='http://home.officesnapshots.com/?p=114'>Order Temovate Cream from mexican pharmacy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
		<item>
		<title>Christmas Light Architectures Are Not That Shiny</title>
		<link>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=christmas-light-architectures-are-not-that-shiny</link>
		<comments>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:00:00 +0000</pubDate>
		<dc:creator>Jan Van Ryswyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/</guid>
		<description><![CDATA[I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way [...]]]></description>
			<content:encoded><![CDATA[<p>I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way overdue :-).</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb1.png" width="202" height="172" /></a> </p>  <p><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a>What's the major malfunction with those old, classic Christmas lights? We've all experienced it at some point. When one goes out, all the others go out as well. This is due to the fact that these lights are wired in series. The difference compared with today's Christmas lights is that every bulb has a shunt, which basically prevents this kind of failure caused by one or more lamps. Enough about the Christmas lights for now. Where am I going with this? Back in enterprise IT, I'm seeing the same kind of failures as with those classic, old Christmas lights.</p>  <p>The diagram below shows a classic RPC style architecture, much like those classic, old Christmas lights. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb2.png" width="565" height="329" /></a> </p>  <p>This is all fine and dandy as long as every part of the chain runs without too much hassle. But what happens if for some reason the centralized back-end web service goes down (light bulb goes out). This means that every smart client, website and batch application that uses this web service gets affected by this, like some sort of chain reaction. Parts of these client applications will no longer function correctly or they might even go down entirely. Same thing happens when the database of the centralized back-end web service goes down or any other external system that it depends on. When being confronted with this kind of architecture, how would one go about preventing this doomsday scenario to happen?</p>  <p>Suppose you’re a developer that has to work on the centralized back-end web service. This is usually a complex system as it obviously has to provide features for all kinds of applications. When this centralized back-end web service also has to deal with and depend on other external systems that might expose some unexpected behavior, how could one prevent the sky from falling down when things go awry in production?</p>  <p>Well for starters, you could start building in some stabilization points. Suppose for some reason, the centralized web service needs to incorporate some functionality offered by a highly expensive, super enterprise system that for some reason behaves very unstable and unpredictably on every full moon (expensive enterprise software not behaving correctly sounds ridiculous, but bare with me ;-) ). For example, we could use a message queue as a stabilization point. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb3.png" width="570" height="157" /></a> </p>  <p>This means that we put a message on a queue that is processed by some sort of worker process or service that does the actual communication with the misbehaving system. When the external system goes down, the message is either left on the message queue or put on an error queue for later processing when the external system comes back up again. There are some other things you need to think about like idempotent messaging, consistency, message persistence when the server goes down, etc. … . But if one of these dependencies goes down, the centralized back-end web service is still up-and-running which means that the systems that depend on its functionality can also continue to serve their users as they are able to keep doing their work.</p>  <p>Earlier this week I overheard this conversation that somewhat amazed me. I changed the names of the persons involved as well as the exact words used in order to protect the guilty.</p>  <blockquote>   <p><em>George: </em><em>We want to incorporate a message queue in order to guarantee stability and&#160; integrity between several non-transactional systems that our system depends on. It will also improve performance as these systems behave very slow at times and become unstable under pressure. This also gives us the opportunity to root out some major points friction that our end-users are experiencing right now.</em></p>    <p><em>Stan: But this means that the end-users are not completely sure if their actions are indeed fully carried out by the system. </em></p>    <p><em>George: End-users can always check the current state of affairs in their applications. If something goes wrong, their request is not lost and things will get fixed automatically later on as soon as the cause of the error has been fixed. </em></p>    <p><em>Stan:&#160; I don’t think that’s a very good idea. End-users have to wait until everything is processed synchronously, even if that means that they’ll need to wait for a long time. And if one of the external systems goes down, they should stop sending in new requests. Everything should come to a halt. They just have to stop doing what they are doing.</em></p>    <p><em>George: This means that because you lose the original request, some external systems might be set up correctly while others are not. Then someone has to manually fix these issues.</em></p>    <p><em>Stan: Then so be it!</em>&#160;</p> </blockquote>  <p>For starters, I was shocked by this conversation. This is just insane. Everything should come to a halt? Think about this scenario for a while: suppose you’re finding yourself in a grocery store with a cart full of food, drinks and other stuff. You come at the cash register where the lady kindly says “Can you put everything back on the shelves please? There are some issues with the cash register software and we are instructed to stop scanning items and serve customers until these issues are fixed. Can you come back tomorrow please?”. Uhm, no! How much money do you think this is going to cost compared to the system that makes use of stabilization points? An end-user that is able to keep doing its work, whether the entire production system is down or not has tremendous business value. </p>  <p>I’m not saying that message queues are a silver bullet. I’m just using these as an example. As always, there is a time and place for using them. There are other things a developer can incorporate in order to increase the stability of the system he’s working on, like <a href="http://davybrion.com/blog/2008/05/the-circuit-breaker/" target="_blank">the circuit breaker pattern</a>. I’m also not saying that every system should be built using every stabilization point one can think of. This become a business decision depending on the kind of solution. As usual, it depends.</p>  <p>But the point that I’m trying to make here is that we should stop putting software systems into production and just hoping for the best. That’s just wishful thinking. Software systems are going to behave badly and at some point they will go down. It’s just a matter of when this is going to happen and how much damage this is going to make.</p>  <p>The first step to take is awareness. I encourage you to pick up this book titled ‘<a href="http://www.amazon.com/exec/obidos/ASIN/0978739213/elegantcode-20" target="_blank">Release It!</a>’, written by <a href="http://www.michaelnygard.com/" target="_blank">Michael Nygard</a>. This book is all about designing software that can survive this though environment called production. I can only hope that Stan picks up a copy as well along with some common sense.</p>  <p>Till next time.&#160;&#160;&#160; </p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Could sealing a class be a sign of a good design</title>
		<link>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=could-sealing-a-class-be-a-sign-of-a-good-design</link>
		<comments>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:50:15 +0000</pubDate>
		<dc:creator>Andreas Håkansson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/</guid>
		<description><![CDATA[I recently attended this years Øredev conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, Philip Laureano. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended this years <a title="Read more about the Øredev conference" href="http://oredev.com/2010" target="_blank">Øredev</a> conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, <a title="Visit the twitter profile of Philip Laureano" href="http://twitter.com/philiplaureano" target="_blank">Philip Laureano</a>. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do not know the full details of his exact opinions). Anyway, the short version is that the person suggested that classes should be sealed by default, or at least have the developer explicitly state if the class should be sealed or closed.</p>  <p>My immediate reaction was that this was a terrible idea and that I had been struck down too many times by sealed classes before. But then I started thinking that maybe it was not such a bad idea after all. Maybe it even was a sign of a well designed class and that more developers would be better of by sealing their classes.</p>  <p>Now let me inform you that I am still on the ropes about this, but I would like your thoughts on it. In fact I am hoping that the most interesting part of this post will end up being the discussion in the comment section.</p>  <p>So when you take a moment to think about the <em>S.O.L.I.D principles</em>, most specifically the <em>Open-Closed Principle</em> and <em>Dependency Inversion Principle</em>, a long with the old design principle of ‘Favor <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> over <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)">class inheritance</a>’ then maybe it is not such a bad thing after all. Throw in interfaces into the mix and program to an interface and not an implementation, and it will enables you to create different branches if needed. If your classes can flourish while being sealed, chances are that you have some pretty nice structures code in your hands.</p>  <p>There probably are some legit reasons to not seal classes at time, despite the reasoning above, so I am not going to be definitive and say that is never the case. Voice your thoughts in the comments and let us see where this ends up – who knows, I might be left standing as a fool!</p>  <p>As always, you can find me on twitter by the name of <a title="Visit me on twitter" href="http://twitter.com/thecodejunkie" target="_blank">@thecodejunkie</a></p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
		<comments>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 22:40:49 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/</guid>
		<description><![CDATA[Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended? I was working on building an automated testing framework for a welfare system in which cases could be added [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended?</p>  <p>I was working on building an automated testing framework for a welfare system in which cases could be added and benefits run for a given month.</p>  <p>A typical scenario might be something like:</p>  <ol>   <li>Create a new case for this month. </li>    <li>Add some people, do some things. </li>    <li>Run benefits for this month. </li>    <li>Run benefits for the next month.&#160; Something should happen because the child on the case is now 19. </li> </ol>  <p>Seems pretty straightforward until you consider what happens if someone hard codes dates into the test.</p>  <p>I am sure you can imagine plenty of scenarios in a situation like this where hard coded dates would eventually cause all kinds of problems.</p>  <p>The problem is… </p>  <p><strong>If you create an API which takes in various dates, how do you ensure the dates passed in are calculated and not just hard coded?</strong></p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pigsinblanket" border="0" alt="pigsinblanket" src="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket_thumb.jpg" width="514" height="514" /></a> </p>  <h2>Why convention doesn’t work</h2>  <p>Your first response might be to create some documentation that describes the importance of making dates “float” forward with time, and not be hard coded.</p>  <p>You might clearly describe how you should not hard code July 7th 1990 to be the birth date of a 20 year old for a test case.</p>  <p>You might give some guidelines of how to properly calculate ages.</p>  <p>But, you have no way of making sure the users of your API will follow those conventions or even read your document.</p>  <p>What if we do the hard work for them?</p>  <h2>Why utilities are still not good enough</h2>  <p>The next idea you might have is to create utilities that would do date conversions and calculate ages for the user of your API, so that they just have to remember to use them and all will be good.</p>  <p>This solution is better than one relying purely on convention, but still has some major flaws.&#160; Part of the problem of utility methods is that they are not self-discoverable.&#160; I’ve <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">talked about before</a> how DateUtilities like classes can get overlooked if you don’t know the utility class is there.</p>  <p>If you are relying on your users to go out and find your utility methods to make life easier for them, you are putting a large amount of responsibility in the wrong place.&#160; In my experience, it is very unlikely that anyone but yourself will actually use the utility methods.</p>  <p>You really need a way to stop them from being able to hard code dates.</p>  <h2>How can you stop someone from hard coding dates?</h2>  <p>Don’t accept dates in your API.</p>  <p>It is simple.</p>  <p>What?&#160; What do you mean?&#160; You can’t just stop accepting dates, you need dates.&#160; Not just dates, but integers, or strings.&#160; You can’t just not accept the bad data… or can you?</p>  <p>Consider wrapping the data type in another data type which creates your desired data type, but only using the convention or rules you desire.</p>  <p>Let me show you an example with the dates:</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(DateTime applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>    DoSomethingWithTheDate(applicationDate);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(<span style="color: #0000ff">new</span> DateTime(1990, 7, 8));</pre>
<!--CRLF--></div>
</div>

<p></p>

<p>In the above example, you can see that I am directly taking a .NET DateTime object.&#160; You can also see that I am directly hard coding a date when calling this method.</p>

<p>Let’s see if we can fix that.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(CaseDate applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     DoSomethingWithTheDate(CaseDate.ToDateTime());</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(CaseDate.YearsAgo(20));</pre>
<!--CRLF--></div>
</div>

<p></p>

<h2>What happened?</h2>

<p>Here is what we did:</p>

<ol>
  <li>We created a custom type called CaseDate. </li>

  <li>We replaced all the external usages of DateTime with CaseDate. </li>

  <li>We provided methods on CaseDate which allow the creation of dates, only through the way we want to allow them to be created. </li>
</ol>

<ol>Now we can easily prevent users of the API from being able to create hard coded dates.&#160; The API only will take CaseDate objects and internally creates DateTime objects from the CaseDate objects.</ol>

<ol>We can add other methods to CaseDate to allow the creation of dates from x number of months ago or in the future, or any other valid creation method we want.</ol>

<p>By doing this, we are restricting the valid set of inputs to our methods at compile time, not throwing exceptions at run time.</p>

<p>We are achieving the same kind of valuable input constrictions that we have been able to <a href="http://elegantcode.com/2010/05/08/the-power-of-enum/">achieve with enumerations</a>, except we are adding more complex restrictions than a simple list of selections.</p>

<h2>Where can I use this?</h2>

<p>Not just dates.&#160; There are many places where restricting the input to your method or API is going to simplify logic, protect against error conditions, and enforce constraints.</p>

<p>Consider using this pattern in some of these scenarios:</p>

<ul>
  <li>You want to use an enumeration, but your list of possible choices is too large, or repetitive. </li>

  <li>Anywhere you are using a primitive type and that primitive type represents some more complex concept. </li>

  <li>Anywhere you have parameter validation or manipulation repeated in multiple methods. </li>

  <li>Anytime you process some input or repeat a series of steps to transform it before sending it as input. </li>
</ul>

<p>Every time you are about to make a primitive type a parameter to a method you should ask yourself if it makes sense to wrap the primitive type into an class.</p>

<p>Remember, especially when creating an API, any time your method takes a primitive type, you lose the ability to constrain that input, and are forced to validate it instead.</p>

<p>Should you always wrap all primitive types?&#160; No, but it is another tool you can use to provide an extra layer of indirection between the logic of your API and your callers use of it.</p>

<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Prefer Additional Methods Over Additional Overloads</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
		<comments>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 17:35:54 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/</guid>
		<description><![CDATA[If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do. Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do.</p>  <p>Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are conscious of making that code as readable and terse as possible.</p>  <p><strong>Seldom do we think about the use of our code from an API standpoint.</strong></p>  <p>There is a subtle difference between designing your code in a way that will make it easier for someone else to maintain, and designing your code in a way that will make it easier for someone else to use.</p>  <h2>Intellisenselessness</h2>  <p>How often are you working against some API and you type a method name you want to use only to have intellisense present you with 5 overloads for the method all with several different parameters choices?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginOverloads" border="0" alt="LoginOverloads" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads_thumb.png" width="600" height="151" /></a> </p>  <p>Which one do you use?&#160; It is hard to be sure, you end up having to read through the long lists of parameters to figure out what method you should call and what parameters you should pass it.</p>  <p>Wouldn’t it be better if you were presented with what the method does in the method name rather than guessing what it does in the parameter list?&#160; Something like this?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginMoreMethods" border="0" alt="LoginMoreMethods" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods_thumb.png" width="596" height="261" /></a> </p>  <h2>Perspective</h2>  <p>From the perspective of the person writing the <em>Login</em> method(s), overloads probably seem like the most efficient and correct way to implement the multiple ways the method can be called.</p>  <p>From the perspective of the person using the <em>Login</em> method(s), additional methods are much preferred, because they are easier to understand and know what you are looking for.</p>  <p><strong>Try to think from the perspective of someone using your code when writing your code.</strong></p>  <h2>Extract boolean parameter to two methods</h2>  <p>I want to take a look at a very specific example that can be of great benefit to the readability and use of your code.</p>  <p>Take a look at this code below.</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login(<span style="color: #0000ff">bool</span> rememberMe)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>
Seems like a fine overload of a <em>Login</em> method.&#160; I have written code just like this, you probably have also.&#160; <br />

<p>&#160;</p>

<p>Unfortunately, by adding this overload, we have added some complexity to our API, because now the user of that code has to see that there is an additional overload that take a bool parameter called <em>rememberMe</em>.</p>

<p>Consider this longer alternative.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginDoNotRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Instead of overloading <em>Login</em> and making the user have to decide which overload to call and pass in a parameter, we have elected to create two differently named methods which take 0 parameters and clearly state what they are going to do.</p>

<p>I’m not saying you should never write overloads, but anytime you see an overload in your code base, you should stop and think if it would be more clear to make that overloaded method into two different methods that can eliminate one or more of the parameters.</p>

<p><strong>Any time you are restricting the number of choices someone using your code has to make, you are making that code simpler to use.</strong></p>

<p>If you don’t believe me, consider why the iPhone has only one button.</p>

<h5><strong>As always, you can subscribe to this </strong><a href="http://feeds2.feedburner.com/ElegantCode"><strong>RSS feed</strong></a><strong> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at </strong><a href="http://simpleprogrammer.com"><strong>http://simpleprogrammer.com</strong></a><strong>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Say &#8220;No&#8221; to &#8220;Null&#8221;</title>
		<link>http://elegantcode.com/2010/05/01/say-no-to-null/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=say-no-to-null</link>
		<comments>http://elegantcode.com/2010/05/01/say-no-to-null/#comments</comments>
		<pubDate>Sat, 01 May 2010 19:35:05 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/05/01/say-no-to-null/</guid>
		<description><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after. What do you do if "null” [...]]]></description>
			<content:encoded><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after.
<blockquote>What do you do if "null” is passed in?</blockquote>
My answer may turn out to be a bit of a surprise.
<blockquote><span style="background-color: #f4f5f7;">Nothing, I don’t handle nulls in code that I control the use of.</span></blockquote>
“What?  What?” you say.  “You don’t handle null?  What kind of heresy is that?”  It is the kind of heresy that helps produce elegant code and I will show you why.
<h2>How well do you handle null right now?</h2>
Would you say that in most of the code you write you properly check all arguments for null?

Or, do you like most developers, handle null in certain cases when you happen to think about it, or after the application dumps a “null pointer exception” stack trace?

Be honest, look at your code if you have to.

The problem is “d00d ur d0ing it r0ng!”

<a href="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="john-mccarthy-programming-completely-wrong" src="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong_thumb.jpg" border="0" alt="john-mccarthy-programming-completely-wrong" width="349" height="452" /></a>

Unless you are some kind of anal retentive perfectionist, you are probably not handling null in every single method call.  That means there are huge potential bugs in the code that you are writing which will throw null pointer exceptions.  That is bad, I agree.

So, if you are not handling it correctly right now, then what can you do to fix that?
<h2>Avoiding null in the code you “own”</h2>
You can’t control external libraries.  And you can’t control how people will use your code, but you can control the code you write and you can, to a degree, control the code your shop writes.

The better strategy is to never pass null in the first place.

You can either focus your efforts on:
<ul>
	<li>Checking for null</li>
	<li>Not ever passing null</li>
</ul>
<ul>The more elegant solution is to focus on never passing null.  By doing this you will end up writing less code and avoid decisions about how to handle null inside of a method that doesn’t have enough context to decide what to do.</ul>
Let’s look at an example:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> TransmographyThreeStrings(<span class="kwrd">string</span> first, <span class="kwrd">string</span> second, <span class="kwrd">string</span> third)
{
     <span class="kwrd">if</span>(<span class="kwrd">string</span>.isNull(first) || <span class="kwrd">string</span>.isNull(second) || <span class="kwrd">string</span>.isNull(third))
    {
           <span class="rem">// hmm, I donno, what should I do?  Should I throw an exception?</span>
           <span class="rem">// should I return an empty string?</span>
           <span class="rem">// what if the first string wasn't null, can we still do something meaningful?</span>
           <span class="rem">// how will the caller of the method know what I will do?</span>
    }

}</pre>
You can see there that we are checking each parameter for null.  The problem is we don’t know what we should do.  We have lots of options, but none of them are obvious.

How much better is it to make sure that we never pass null into methods, rather than write this kind of code in every method?
<h2>What about accidentally passing in null?</h2>
Many of you are probably thinking at this point that the main way null gets passed into a method is because someone calls a method without knowing that it contains a null value.
<pre class="csharpcode">TransmographyThreeStrings(<span class="str">"Hello"</span>, <span class="str">"World"</span>, mysteryObject.Text);</pre>
Perhaps <em>mysteryObject.Text </em>is null.  You wouldn’t even know it.

Ah, but you can.  Or you can prevent it at least.  Somewhere <em>mysteryObject </em>gets created.  When it gets created its values either get initialized or not.  You can prevent any of its values from being null, several ways:
<ul>
	<li>Always initialize variables when they are declared.</li>
	<li>Use a <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> to ensure that objects are always fully constructed before being created.</li>
	<li>Use properties to provide default values or lazy initialize.</li>
	<li>Make your objects <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> as much as possible.</li>
</ul>
The practices that prevent null from accidentally being passed in make your code much more elegant than repeating <em>if blah == null</em> code all over the place.

<strong>In general, you should always strive to eliminate the passing of null rather than checking for null.  By doing so you reduce extra lines of code in each method, and are forced to use better design practices.</strong>
<h2>Exceptions</h2>
Yes, there are times when you need to check for null.  If you are writing a library that external developers will use, then you will probably want to check for null in all of your methods that are exposed as part of the API.  (On your internal methods, you don’t need to since you have already cleansed the input.)

Also, if your code is being used as a callback to some API and you don’t know if it can ever pass null into your code, you probably should check for null.

A bad excuse is that other developers may pass null to your method. <strong>It is much better as a software shop to put the onus of not passing null on the caller of any method rather than putting it on the writer of the method being called.</strong>

You will also reduce your exception handling code, because you will have less exceptions for invalid parameters.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/05/01/say-no-to-null/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>If Self-Documenting Code is the What, Unit Tests are the Why</title>
		<link>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-self-documenting-code-is-the-what-unit-tests-are-the-why</link>
		<comments>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:09:04 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/</guid>
		<description><![CDATA[It is not enough to just write code that is clean and self-documenting.  Eliminating comments and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it. If you recall from my original post on [...]]]></description>
			<content:encoded><![CDATA[It is not enough to just write code that is clean and self-documenting.  <a href="http://elegantcode.com/2010/04/18/eliminating-comments-the-road-to-clarity/">Eliminating comments</a> and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it.

If you recall from my <a href="http://elegantcode.com/2010/04/09/what-does-elegant-code-mean-to-me/">original post</a> on Elegant code, I stated that elegant code is:
<blockquote>Something that is simple yet effective, delivered with grace.</blockquote>
By writing self-documenting code we are hopefully able to achieve some of the aspects of simplicity and grace, but it tells us nothing about the effectiveness of the code.
<h2>Bringing the dead to life</h2>
<a href="http://elegantcode.com/wp-content/uploads/2010/04/zombies.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="zombies" src="http://elegantcode.com/wp-content/uploads/2010/04/zombies_thumb.jpg" border="0" alt="zombies" width="441" height="295" /></a>

Throwing out comments is a debatable topic.  <a href="http://www.reddit.com/r/programming/comments/bsutx/">It raises quite a bit of controversy</a>, as you can see from some of the comments on my post about the subject.  The reason, perhaps, that so many people are so staunchly opposed to the idea, is because they are worried, and rightly so, that throwing out comments will reduce the documentation of what the code is doing.

Think about that for a second.  Is documentation of what the code is doing important?  It better be.  What we are trying to accomplish by writing self-documenting code instead of comments, is to take the vessel, which is the code itself, and make that same vessel be the documentation of what the code does.  It is by doing this that we creating a living representation of the functionality of the code.  Comments are akin to a dead representation of the functionality of the code because they do not change automatically with the code.

I diverge to talk about comments so that I can draw a parallel to another form of documentation which is valuable and should be considered necessary.  That other set of documentation is requirements.  Have you ever written requirements documents?  Have you ever captured requirements from the customer and put them into UML diagrams, or perhaps plopped them into some templated Word document, which is never updated again, and no one reads, because no one trusts it is correct?  Wouldn’t it be great if we would replace that dead document or set of documents, with a living one?

The good news is we can, and some of us have.  And I fully expect this recommendation will be just as controversial, because <strong>I am suggesting that we don’t have to write low level specifications of the system at all, instead we can write good unit tests. </strong>When we do this, we are taking a dead form of document and bringing it to life.
<h2>Unit tests tell us why and how our code is effective</h2>
If
<pre class="csharpcode">i = 5;  // Widget count defaults to five.</pre>
is replaced with
<pre class="csharpcode">widgetCount = DEFAULT_WIDGET_COUNT;</pre>
<!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

then
<blockquote><span style="background-color: #ffffff;">1.1.5 When a new widget is created, the widget count should be increased by one.</span></blockquote>
is replaced with
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> When_NewWidgetIsCreated_Then_WidgetCountIsIncreasedByOne()
{
     WidgetFactory.Count = 3;
     WidgetFactory.CreateNew();
     assertEquals(4, WidgetFactory.Count);
}</pre>
The unit test is replacing the low level requirement, which is somewhat open to interpretation and untied to the code, with an absolute and completely tied-to-the-code, specific requirement.

The unit test is telling us why our code is built the way it is.  It is telling us what requirement that particular structure of code is trying to address.  <strong>It is telling us what end result that code is trying to accomplish and what the expectations are on the results of a given condition.</strong>

The unit test is telling us how the code is to be used in order to achieve its result.  It is serving as a living reference to the syntax and use of the code we built.  <strong>Instead of providing instructions on how to use our API, we are providing a living example, and proof that it will indeed work.</strong> Examples are often much more effective than instructions anyway.
<h2>What exactly are we replacing?</h2>
At this point we are not trying to replace all the documentation of the system (at this point).

With self-documenting code, we sought to eliminate comments, and replace them with good variable and method names.

With unit tests, we seek to eliminate technical documentation and requirements of the system, that is targeted at a developer or technical audience.

We are NOT trying to eliminate high level specifications of the system, or use cases. <strong>Unit tests DO NOT replace that kind of documentation! </strong>We will talk about replacing that kind of documentation when we talk about automated functional or system tests.

Simply put, any kind of documentation that you would give to a developer so they understand how the system works and how to use the code or APIs, can be easily replaced by writing good unit tests.

Our simple goal is to replace the “dead” documentation (meaning that it does not update automatically with the thing it is documenting), with “living” documentation in the form of unit tests.

One last point.  I want to be clear that I am not saying that having unit tests automatically results in the ability to replace technical documentation.  Just like having long-named methods and variables doesn’t automatically replace the need for comments.  It is a matter of the quality of the unit tests that are written, just as it is a matter of the quality of the self-documenting code.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>REST: Resources, URI&#8217;s and Representations</title>
		<link>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rest-resources-uris-and-representations</link>
		<comments>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 04:00:13 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/</guid>
		<description><![CDATA[In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions. Resources Resources are at the heart of REST.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions.</p>  <h3>Resources</h3>  <p>Resources are at the heart of REST.&#160; You are already used to resources as a web browsing consumer.&#160; A resource is not something specific to REST, instead it is the first thing you probably want to consider when architecting a RESTful application.&#160; A resource is simply the entity, item, or thing you want to expose.</p>  <p>Perhaps you have approached application architecture using one or many of several modeling and design techniques.&#160; Data First practitioners typically begin with databases and data models.&#160; DDD proponents like to begin by modeling around business entities and interactions, while their cousins in the BDD camp model around business activities.</p>  <p>When you decide to apply REST you will need to think a lot more about data entities and domain objects as resources.&#160; Your existing models may or may not closely map to resources.&#160; The shift in thinking may appear slight, but is very important.&#160; It centers around making things&#160; addressable.&#160; Each resources must by uniquely identifiable as we will see in the next section.&#160; We are used to identity with most data entities, but our domain objects may not always be as easily identifiable.&#160; Likewise, our data entites may have identity, but not map to a resource.&#160; </p>  <p>Consider the classic customer and order scenario for example.&#160; If each customer and each order can be identified then it will be easy to design RESTful systems around them.&#160; However, if the model requires a lot of context then our challenge is a little bit larger.&#160; Perhaps we must first identify a partner, then a year, then a customer, and finally the order.&#160; Yes, that is a design smell in general.&#160; It makes fetching an order very difficult.&#160; Developing RESTfuly would only further expose that difficulty.&#160; Identifying your resources up front will help you reduce the possible impedance mismatches you might end up with between what you want to expose and your data or domain models.</p>  <p>REST is about interacting with Resources!</p>  <h3>URI’s</h3>  <p>REST defines the identity of a resource via URI.&#160; Each resources has a unique address in URL form (ie. using the http protocol).&#160; Interaction with a resource will take place at its URI.&#160; As an example, my twitter status feed resource URI is <a title="http://twitter.com/optionstrict" href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; That URI is unique to my feed and that is what you expect to find at that URI.&#160; In the Twitter databases or domain models my account may be referred to by the string optionstrict, or perhaps as some random number or guid.</p>  <p>To consume my status history via a service interface twitter provides another URI at <a title="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict" href="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict">http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict</a>.&#160; I would actually prefer to have access at the same URI for html, json, and xml formats.&#160; Twitter probably has its reasons for distinguishing API access from HTML rendering, but they have actually complicated their architecture by doing so.&#160; When designing the URI’s for your resources, make them easy for your users to work with.&#160; </p>  <h3>Representation</h3>  <p>Lets continue with the twitter example to describe what is meant by Representation.&#160; Given a URI and a Resource, what will your consumers receive when they issue a GET request to the URI?&#160; Twitter chose a representation of my account and included status history and profile for the response at <a href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; They decided to put a representation of my profile photo at <a title="http://twitter.com/account/profile_image/optionstrict" href="http://twitter.com/account/profile_image/optionstrict">http://twitter.com/account/profile_image/optionstrict</a>.&#160; In your REST solutions you will need to consider how you want to represent a resource at its URI.&#160; Each representation will have a unique URI.&#160; </p>  <p>Representations are also important for manipulating resources.&#160; You must define the representation required to create and update resources.&#160; Twitter status updates require a text representation with a maximum of 140 characters.&#160; They allow additional values in the status representation, such as latitude and longitude.&#160; Your REST solutions similarly must define representations for Requests and Responses.</p>  <p>I hope that this short introduction has helped you to see that the core essence of REST is simple and fairly obvious.&#160; As you look at your current solutions what are the resources you are exposing?&#160; Could you make those resources identifiable by URI?&#160; What representation would you place at each URI?&#160; What representation would you require for manipulating a given resource?</p>  <p>Also, notice I did not mention much about data formats, Content Type, Mime, etc.&#160; Those details can cloud your design if you try to start with them. If you can’t wait for my post about how REST handles html, json, xml from the same URI, then start googling Content Negotiation, Accept header, and Content-Type header.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Driven Architecture: Publishing Events using an IOC container</title>
		<link>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=could-sealing-a-class-be-a-sign-of-a-good-design</link>
		<comments>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:50:15 +0000</pubDate>
		<dc:creator>Andreas Håkansson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/</guid>
		<description><![CDATA[I recently attended this years Øredev conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, Philip Laureano. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended this years <a title="Read more about the Øredev conference" href="http://oredev.com/2010" target="_blank">Øredev</a> conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, <a title="Visit the twitter profile of Philip Laureano" href="http://twitter.com/philiplaureano" target="_blank">Philip Laureano</a>. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do not know the full details of his exact opinions). Anyway, the short version is that the person suggested that classes should be sealed by default, or at least have the developer explicitly state if the class should be sealed or closed.</p>  <p>My immediate reaction was that this was a terrible idea and that I had been struck down too many times by sealed classes before. But then I started thinking that maybe it was not such a bad idea after all. Maybe it even was a sign of a well designed class and that more developers would be better of by sealing their classes.</p>  <p>Now let me inform you that I am still on the ropes about this, but I would like your thoughts on it. In fact I am hoping that the most interesting part of this post will end up being the discussion in the comment section.</p>  <p>So when you take a moment to think about the <em>S.O.L.I.D principles</em>, most specifically the <em>Open-Closed Principle</em> and <em>Dependency Inversion Principle</em>, a long with the old design principle of ‘Favor <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> over <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)">class inheritance</a>’ then maybe it is not such a bad thing after all. Throw in interfaces into the mix and program to an interface and not an implementation, and it will enables you to create different branches if needed. If your classes can flourish while being sealed, chances are that you have some pretty nice structures code in your hands.</p>  <p>There probably are some legit reasons to not seal classes at time, despite the reasoning above, so I am not going to be definitive and say that is never the case. Voice your thoughts in the comments and let us see where this ends up – who knows, I might be left standing as a fool!</p>  <p>As always, you can find me on twitter by the name of <a title="Visit me on twitter" href="http://twitter.com/thecodejunkie" target="_blank">@thecodejunkie</a></p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Elegant Code &#187; Architecture</title>
	<atom:link href="http://elegantcode.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quinine For Sale</title>
		<link>http://elegantcode.com/2012/01/18/monitoring-an-mmo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-an-mmo</link>
		<comments>http://elegantcode.com/2012/01/18/monitoring-an-mmo/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:45:32 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MMO]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2012/01/18/monitoring-an-mmo/</guid>
		<description><![CDATA[I’ve been working on a free-to-play MMO Quinine For Sale, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I’ve been working on a free-to-play <a href="http://www.heroup.com" target="_blank">MMO</a> <b>Quinine For Sale</b>, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before they become serious and fixing problems when they inevitably do.&#160; So, there are two questions.&#160; “Is there a problem in the game?” “What is causing the problem?”&#160; </p>  <p>When trying to debug something on our development and test clusters, typically you can tail log files.&#160; We have a python script that can monitor the communication between various parts of the game and pretty-print it along with color to highlight “this is a problem!”&#160; Attaching a debugger to a running process is also not uncommon.&#160; However, looking at logs and bus traffic in realtime on a production environment gives you this neat “Matrix-y” experience.&#160; Attaching a debugger to a production process (assuming you could, which you can’t) would get you smacked with a rolled-up newspaper.&#160; “Bad Developer!&#160; No treat!”&#160; So, what can you do?</p>  <h4>Monitoring</h4>  <p>When you’ve got clusters full of machines, using <a href="http://www.nagios.org/" target="_blank">Nagios</a> to monitor things is an obvious solution.&#160; Beyond making sure the power is on and other sysadmin things, we’ve written other checks to see if the login process is working, the parts are working together, and automating typical in-game functions.&#160; For example, if nagios can’t successfully log into the game do basic game activity, then alerts happen.</p>  <h4>Metrics for EVERYTHING</h4>  <p>Anything that happens in game has metrics reporting tied to it, generating piles of data constantly.&#160; We use <a href="http://www.cacti.net/" target="_blank">Cacti</a> to visualize game activity.&#160; An example metric is concurrent users, or CCU.&#160; We graph how many people are in the game over time, which when things are healthy should be a nice smooth curve climbing to peak game hours, then descending nicely through the night.</p>  <p>We can tell by sight if the game looks healthy or not – if the CCU graph is jaggy, has a sudden drop or spike, or drops to zero then we know that something is wrong.&#160; Typically nagios alerts accompany the graphs, giving more data points on where to look.&#160; But this has also pointed out areas where a nagios check was missing or wasn’t working as intended.</p>  <h4>Log Files</h4>  <p>When a player gets an error in game, the error dialog box gives them the opportunity to submit the error details back to us.&#160; If we see a spike in user-reported errors through this or other customer service means, we know we have something of interest to look for.&#160; </p>  <p>The game server components make use of log4j and similar logging frameworks.&#160; Anything that you’d want to watch happening in game needs to be aggressively logged.&#160; All components are configured so that operations can change the log level on the fly.&#160; That’s still quite a bit of data across many machines though, so all that information is run through <a href="http://www.splunk.com/product" target="_blank">Splunk</a> to be indexed and searchable.&#160; This gives us a great tool for searching through log data, examining trends, or watching selected activity in real time.&#160; Unfortunately it is very expensive so we are selective about the data that passes through it.&#160; </p>.  Buy Quinine from mexico.  Buy Quinine no prescription.  No prescription Quinine online.  Online buying Quinine.  Quinine no prescription.  Quinine street price.  Buy no prescription Quinine online.  Quinine coupon.  Quinine over the counter.  Where can i buy Quinine online.  Quinine steet value.  Where to buy Quinine.  Order Quinine online overnight delivery no prescription.  Quinine recreational.  Quinine canada, mexico, india.  Ordering Quinine online.  Quinine without prescription.  Quinine price, coupon.  Quinine description.  Order Quinine from mexican pharmacy.  Quinine pics.  What is Quinine.  Japan, craiglist, ebay, overseas, paypal.  Order Quinine from United States pharmacy.  Order Quinine online c.o.d.  Quinine trusted pharmacy reviews.  Quinine treatment.  Buy Quinine from canada.  Quinine used for.  Discount Quinine.  Is Quinine addictive.  Quinine forum.  Buy Quinine online no prescription.  Is Quinine safe.  Purchase Quinine for sale.  Effects of Quinine.  Buy Quinine online cod.  Quinine australia, uk, us, usa.  Buy Quinine without prescription.  Quinine online cod.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4721'>Buy Flonase Without Prescription</a>. <a href='http://elegantcode.com/?p=4234'>Buy Periactin Without Prescription</a>. <a href='http://elegantcode.com/?p=4203'>Buy Armour Without Prescription</a>. <a href='http://elegantcode.com/?p=4899'>Buy Macrobid Without Prescription</a>. <a href='http://elegantcode.com/?p=4534'>Xalatan For Sale</a>. <a href='http://elegantcode.com/?p=4302'>Phenergan wiki</a>. <a href='http://elegantcode.com/?p=4268'>Soma maximum dosage</a>. <a href='http://elegantcode.com/?p=4602'>Zovirax treatment</a>. <a href='http://elegantcode.com/?p=4578'>Cialis price, coupon</a>. <a href='http://elegantcode.com/?p=4189'>Flexeril price</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.leaduganda.org/?p=514'>Quinine For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=4820'>Quinine For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2780'>Quinine For Sale</a>. <a href='http://www.thegriffonnews.com/?p=10177'>Quinine For Sale</a>. <a href='http://www.independentworldreport.com/?p=2409'>Quinine For Sale</a>. <a href='http://changecamp.ca/?p=295'>Quinine description</a>. <a href='http://social-blend.com/?p=624'>Quinine price, coupon</a>. <a href='http://blog.farmland.org/?p=3946'>Online buying Quinine hcl</a>. <a href='http://4realz.net/?p=1595'>Quinine from canada</a>. <a href='http://reversemortgagedaily.com/?p=14535'>Where to buy Quinine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2012/01/18/monitoring-an-mmo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temovate Cream For Sale</title>
		<link>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-software-development-will-never-be-engineering</link>
		<comments>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 03:37:48 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/</guid>
		<description><![CDATA[I always find it rather interesting when academics try to quantify generalized metrics about software development. Temovate Cream For Sale, Things like: per lines of code, there will be X number of bugs. Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.” These are all interesting [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I always find it rather interesting when academics try to quantify generalized metrics about software development.</p>  <p> <b>Temovate Cream For Sale</b>, Things like: per lines of code, there will be X number of bugs.</p>  <p>Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.”</p>  <p>These are all interesting thoughts, but software development will never conform to rigid engineering principles like many other engineering practices.&#160; The longer I work in the field, the more and more I realize that software development has nothing to do with engineering.&#160; We just happen to attend some of the same math classes in school.</p>  <h2>Building bridges</h2>  <p>One of the main arguments I hear people make about the current state of software development as an engineering practice is based around its relative maturity to other engineering fields.</p>  <p>There is a huge problem with this line of thinking.</p>  <p>The argument goes something like this:&#160; “<em>Engineering has been around for hundreds of years and has matured to the point where it is a measurable science, but software development has only been around in earnest for the last few decades or so, therefore it is relatively immature as an engineering discipline.”</em></p>  <p>On the surface this argument seems sounds.&#160; And certainly in 50 years software development will be different than it is now.&#160; Heck, it is much more different than it was just 10 years ago.</p>  <p>But, here is the problem.&#160; We build much more software than we do bridges.</p>  <p><img src="http://www.nps.gov/glca/historyculture/images/Navajo_Bridges_1.gif" width="589" height="442" /></p>  <h6 align="center">&#160;</h6>  <p>Let me give you an example that came to light in another area of my interest… poker.</p>  <h1></h1>  <h2>The poker quickening</h2>  <p>An interesting thing happened in the poker community in the last 10 years; poker pros with decades of experience started getting beat time and time again by 19 year old poker prodigies.</p>  <p>From an outside perspective it looks like the poker world opening up just widened the search for talent and there it was.&#160; But, a closer examination of the evidence leads to the truth.</p>  <p>Before the online poker industry was born, poker was played in card rooms and casinos in states where it was legal and occasionally at small home games throughout the US.</p>  <p>A poker pro might play poker tournaments perhaps 100 times to 150 times a year.&#160; The sum knowledge of the poker community and the meta game around it was based on this base of professional poker players playing tournaments and gaining experience at this mediocre rate.</p>  <p>Once the internet poker rooms started opening up, things changed, and they changed rapidly.&#160; Now anyone could play poker from their home PC.&#160; Not only could they play poker, they could play poker tournaments at all hours of the day.</p>  <p>Here is a list of some of the major changes that took place:</p>  <ul>   <li>Hands are dealt at 60-80 hands per hour instead of 10-30</li>    <li>Players can play in many tournaments at one time, 10 tournaments at once is not unheard of</li>    <li>Players can analyze hand histories and historical data about their play and opponents play through the use of software </li>    <li>Age requirements are out the window, technically any one of any age could be playing online</li>    <li>Players can play 24 hours a day</li>    <li>The professional online tournament player could easily play over 3000 tournaments in a year, while a brick and mortar pro would be lucky to reach 100 in a year.</li>   <img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://t1.gstatic.com/images?q=tbn:ANd9GcRj9uGNWSyqGWEneiH6xaBAyS6COwGYicdNadZu-06KWQLhIi6LMw&amp;t=1" width="316" height="270" /></ul>  <p>&#160;</p>  <p>So where am I going with all this?</p>  <p>The point is that as a whole more hands were dealt and more poker knowledge and experience was obtained in 1 year of online poker than probably the entire history of poker before that.&#160; We reached such an accelerated pace of play that all previous knowledge of poker became obsolete.&#160; </p>  <p>The strategy of tournament poker completely changed.&#160; The game evolved perhaps 500 years into the future in a matter of 5 years time.</p>  <p>The same has happened with software development.</p>  <h2>Back to the bridge building</h2>  <p>So let’s take that poker example and look at it through the lens of software development.</p>  <p>Let us compare the engineering maturity to software development to the engineering maturity of the engineering discipline of building bridges.</p>  <p>I think most people would agree that bridge building is a very mature engineering discipline but many people would argue that software development is not.</p>  <p><strong>How many bridges do you think have been built in the world?</strong></p>  <p>Well there are <a href="http://www.betterroads.com/category/bridge-inventory/erroads.randallreillycms.com/files/2009/11/BR1109_BridgeInventory.pdf">about 600,000 bridges in the United States alone</a>, so the world figure must be at least somewhere around 10 times that number perhaps 20.</p>  <p><strong>How many software programs have been written?</strong></p>  <p>This is a very hard number to estimate, but lets take a rough guess based on <a href="http://stackoverflow.com/questions/453880/how-many-developers-are-there-in-the-world">how many software developers there are in the world</a>.&#160; </p>  <p>If we say there are about 12 million software developers and each software developer has written approximately 3 programs, we can estimate that a large amount more programs have been written than bridges built.</p>  <p>My point is not to knock bridge building, we are pretty good at it as a whole, but rather to show that collectively, even though we have been building bridges for hundreds of years, we have probably devoted an equivalent amount of time to building software.</p>  <p>This line of thinking may lead you to argue back that software development and bridge building are very different.&#160; Bridge building has a fixed set of requirements that are pretty close to the the same for each bridge you build, but software development is a big open void of whims and ambiguously contradictory statements.</p>  <p>I agree with you 100%!&#160; And in essence that is my point.</p>  <h2>Software development is different</h2>  <p>And we have had enough time to realize that.&#160; Waiting for software development to gel into some kind of engineering discipline like other engineering disciplines is like waiting for water without gelatin mix to turn into Jello.&#160; </p>  <p>It’s just not going to happen!</p>  <p>In my mind it is clear that the argument that we haven’t given it enough time is just wishful thinking.&#160; The nature of software development, just like online poker, leads itself to rapid evolution.</p>  <p>Consider what direction software development is evolving.&#160; Is it even evolving in the direction of rigid engineering practices or is it evolving in the exact OPPOSITE direction?</p>  <p>Ten years ago, we tried to use UML diagrams and CASE tools to develop software.&#160; Ten years ago waterfall was all the rage.&#160; Ten years ago, we thought that ten years in the future we would have programs that would allow us to build software in the same way that CAD tools allow for building machine parts.</p>  <p>Not only did it not happen.&#160; It went completely the other way.&#160; Now we are all talking about Agile.&#160; Now people don’t even remember what CASE tools are.&#160; Now we are building software without trying to define the whole system in UML diagrams.</p>  <p><strong>The fact of the matter is software systems are unruly beasts!</strong></p>  <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://aznbadger.files.wordpress.com/2010/06/beast.jpg" /></p>  <p>In my mind it comes down to one simple distinction.&#160; Software is living, bridges aren’t.&#160; When you are done building a bridge, you are done building the bridge.&#160; </p>  <p>Sure someone, probably not you, will have to come along and do some routine maintenance on it.&#160; Sure, some small things might change about it, but for all intents and purposes the work is done.</p>  <p>In most software development scenarios, this is not the case.&#160; In most software development scenarios, releasing V1 is not even close to the end.&#160; Sometimes V1 and V2 don’t even look that same at all.&#160; Software development is about operating on a living breathing thing and all the while keeping it alive.</p>  <p>The truth is, we software developers have more in common with surgeons than with other engineers.</p>  <h6>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com/">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>.  Buy Temovate Cream without a prescription.  Temovate Cream trusted pharmacy reviews.  Temovate Cream over the counter.  Where can i order Temovate Cream without prescription.  Online buy Temovate Cream without a prescription.  Temovate Cream no rx.  Buy cheap Temovate Cream no rx.  Temovate Cream photos.  Buy Temovate Cream online no prescription.  Order Temovate Cream online c.o.d.  Herbal Temovate Cream.  About Temovate Cream.  Australia, uk, us, usa.  Cheap Temovate Cream.  Temovate Cream class.  Temovate Cream brand name.  Online Temovate Cream without a prescription.  Buy Temovate Cream without prescription.  Buy Temovate Cream from canada.  After Temovate Cream.  Order Temovate Cream from mexican pharmacy.  Temovate Cream without a prescription.  Purchase Temovate Cream.  Temovate Cream natural.  Temovate Cream overnight.  Temovate Cream online cod.  Where can i buy cheapest Temovate Cream online.  Purchase Temovate Cream for sale.  Online buying Temovate Cream.  Purchase Temovate Cream online.  Temovate Cream used for.  Temovate Cream coupon.  Temovate Cream description.  Order Temovate Cream no prescription.  Temovate Cream maximum dosage.  Cheap Temovate Cream no rx.  Temovate Cream images.  Temovate Cream blogs.  Buy Temovate Cream online cod.  Buy generic Temovate Cream.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4472'>Bactroban For Sale</a>. <a href='http://elegantcode.com/?p=4632'>Armour For Sale</a>. <a href='http://elegantcode.com/?p=4639'>Buy Estrace Vaginal Cream Without Prescription</a>. <a href='http://elegantcode.com/?p=4668'>Buy Augmentin Without Prescription</a>. <a href='http://elegantcode.com/?p=4535'>Buy Tindamax Without Prescription</a>. <a href='http://elegantcode.com/?p=4931'>Fast shipping Diclofenac</a>. <a href='http://elegantcode.com/?p=4240'>Combivent brand name</a>. <a href='http://elegantcode.com/?p=4417'>Levaquin overnight</a>. <a href='http://elegantcode.com/?p=4597'>Purchase Toradol online</a>. <a href='http://elegantcode.com/?p=4221'>Australia, uk, us, usa</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.quarterlives.com/?p=1148'>Temovate Cream For Sale</a>. <a href='http://4realz.net/?p=1972'>Temovate Cream For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=5997'>Temovate Cream For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2476'>Temovate Cream For Sale</a>. <a href='http://www.thegriffonnews.com/?p=9947'>Temovate Cream For Sale</a>. <a href='http://social-blend.com/?p=1160'>Temovate Cream brand name</a>. <a href='http://blog.farmland.org/?p=3812'>Where can i find Temovate Cream online</a>. <a href='http://reversemortgagedaily.com/?p=14136'>Generic Temovate Cream</a>. <a href='http://linuxologist.com/?p=1792'>Temovate Cream photos</a>. <a href='http://home.officesnapshots.com/?p=114'>Order Temovate Cream from mexican pharmacy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
		<item>
		<title>Christmas Light Architectures Are Not That Shiny</title>
		<link>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=christmas-light-architectures-are-not-that-shiny</link>
		<comments>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:00:00 +0000</pubDate>
		<dc:creator>Jan Van Ryswyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/</guid>
		<description><![CDATA[I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way [...]]]></description>
			<content:encoded><![CDATA[<p>I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way overdue :-).</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb1.png" width="202" height="172" /></a> </p>  <p><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a>What's the major malfunction with those old, classic Christmas lights? We've all experienced it at some point. When one goes out, all the others go out as well. This is due to the fact that these lights are wired in series. The difference compared with today's Christmas lights is that every bulb has a shunt, which basically prevents this kind of failure caused by one or more lamps. Enough about the Christmas lights for now. Where am I going with this? Back in enterprise IT, I'm seeing the same kind of failures as with those classic, old Christmas lights.</p>  <p>The diagram below shows a classic RPC style architecture, much like those classic, old Christmas lights. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb2.png" width="565" height="329" /></a> </p>  <p>This is all fine and dandy as long as every part of the chain runs without too much hassle. But what happens if for some reason the centralized back-end web service goes down (light bulb goes out). This means that every smart client, website and batch application that uses this web service gets affected by this, like some sort of chain reaction. Parts of these client applications will no longer function correctly or they might even go down entirely. Same thing happens when the database of the centralized back-end web service goes down or any other external system that it depends on. When being confronted with this kind of architecture, how would one go about preventing this doomsday scenario to happen?</p>  <p>Suppose you’re a developer that has to work on the centralized back-end web service. This is usually a complex system as it obviously has to provide features for all kinds of applications. When this centralized back-end web service also has to deal with and depend on other external systems that might expose some unexpected behavior, how could one prevent the sky from falling down when things go awry in production?</p>  <p>Well for starters, you could start building in some stabilization points. Suppose for some reason, the centralized web service needs to incorporate some functionality offered by a highly expensive, super enterprise system that for some reason behaves very unstable and unpredictably on every full moon (expensive enterprise software not behaving correctly sounds ridiculous, but bare with me ;-) ). For example, we could use a message queue as a stabilization point. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb3.png" width="570" height="157" /></a> </p>  <p>This means that we put a message on a queue that is processed by some sort of worker process or service that does the actual communication with the misbehaving system. When the external system goes down, the message is either left on the message queue or put on an error queue for later processing when the external system comes back up again. There are some other things you need to think about like idempotent messaging, consistency, message persistence when the server goes down, etc. … . But if one of these dependencies goes down, the centralized back-end web service is still up-and-running which means that the systems that depend on its functionality can also continue to serve their users as they are able to keep doing their work.</p>  <p>Earlier this week I overheard this conversation that somewhat amazed me. I changed the names of the persons involved as well as the exact words used in order to protect the guilty.</p>  <blockquote>   <p><em>George: </em><em>We want to incorporate a message queue in order to guarantee stability and&#160; integrity between several non-transactional systems that our system depends on. It will also improve performance as these systems behave very slow at times and become unstable under pressure. This also gives us the opportunity to root out some major points friction that our end-users are experiencing right now.</em></p>    <p><em>Stan: But this means that the end-users are not completely sure if their actions are indeed fully carried out by the system. </em></p>    <p><em>George: End-users can always check the current state of affairs in their applications. If something goes wrong, their request is not lost and things will get fixed automatically later on as soon as the cause of the error has been fixed. </em></p>    <p><em>Stan:&#160; I don’t think that’s a very good idea. End-users have to wait until everything is processed synchronously, even if that means that they’ll need to wait for a long time. And if one of the external systems goes down, they should stop sending in new requests. Everything should come to a halt. They just have to stop doing what they are doing.</em></p>    <p><em>George: This means that because you lose the original request, some external systems might be set up correctly while others are not. Then someone has to manually fix these issues.</em></p>    <p><em>Stan: Then so be it!</em>&#160;</p> </blockquote>  <p>For starters, I was shocked by this conversation. This is just insane. Everything should come to a halt? Think about this scenario for a while: suppose you’re finding yourself in a grocery store with a cart full of food, drinks and other stuff. You come at the cash register where the lady kindly says “Can you put everything back on the shelves please? There are some issues with the cash register software and we are instructed to stop scanning items and serve customers until these issues are fixed. Can you come back tomorrow please?”. Uhm, no! How much money do you think this is going to cost compared to the system that makes use of stabilization points? An end-user that is able to keep doing its work, whether the entire production system is down or not has tremendous business value. </p>  <p>I’m not saying that message queues are a silver bullet. I’m just using these as an example. As always, there is a time and place for using them. There are other things a developer can incorporate in order to increase the stability of the system he’s working on, like <a href="http://davybrion.com/blog/2008/05/the-circuit-breaker/" target="_blank">the circuit breaker pattern</a>. I’m also not saying that every system should be built using every stabilization point one can think of. This become a business decision depending on the kind of solution. As usual, it depends.</p>  <p>But the point that I’m trying to make here is that we should stop putting software systems into production and just hoping for the best. That’s just wishful thinking. Software systems are going to behave badly and at some point they will go down. It’s just a matter of when this is going to happen and how much damage this is going to make.</p>  <p>The first step to take is awareness. I encourage you to pick up this book titled ‘<a href="http://www.amazon.com/exec/obidos/ASIN/0978739213/elegantcode-20" target="_blank">Release It!</a>’, written by <a href="http://www.michaelnygard.com/" target="_blank">Michael Nygard</a>. This book is all about designing software that can survive this though environment called production. I can only hope that Stan picks up a copy as well along with some common sense.</p>  <p>Till next time.&#160;&#160;&#160; </p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Could sealing a class be a sign of a good design</title>
		<link>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=could-sealing-a-class-be-a-sign-of-a-good-design</link>
		<comments>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:50:15 +0000</pubDate>
		<dc:creator>Andreas Håkansson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/</guid>
		<description><![CDATA[I recently attended this years Øredev conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, Philip Laureano. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended this years <a title="Read more about the Øredev conference" href="http://oredev.com/2010" target="_blank">Øredev</a> conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, <a title="Visit the twitter profile of Philip Laureano" href="http://twitter.com/philiplaureano" target="_blank">Philip Laureano</a>. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do not know the full details of his exact opinions). Anyway, the short version is that the person suggested that classes should be sealed by default, or at least have the developer explicitly state if the class should be sealed or closed.</p>  <p>My immediate reaction was that this was a terrible idea and that I had been struck down too many times by sealed classes before. But then I started thinking that maybe it was not such a bad idea after all. Maybe it even was a sign of a well designed class and that more developers would be better of by sealing their classes.</p>  <p>Now let me inform you that I am still on the ropes about this, but I would like your thoughts on it. In fact I am hoping that the most interesting part of this post will end up being the discussion in the comment section.</p>  <p>So when you take a moment to think about the <em>S.O.L.I.D principles</em>, most specifically the <em>Open-Closed Principle</em> and <em>Dependency Inversion Principle</em>, a long with the old design principle of ‘Favor <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> over <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)">class inheritance</a>’ then maybe it is not such a bad thing after all. Throw in interfaces into the mix and program to an interface and not an implementation, and it will enables you to create different branches if needed. If your classes can flourish while being sealed, chances are that you have some pretty nice structures code in your hands.</p>  <p>There probably are some legit reasons to not seal classes at time, despite the reasoning above, so I am not going to be definitive and say that is never the case. Voice your thoughts in the comments and let us see where this ends up – who knows, I might be left standing as a fool!</p>  <p>As always, you can find me on twitter by the name of <a title="Visit me on twitter" href="http://twitter.com/thecodejunkie" target="_blank">@thecodejunkie</a></p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
		<comments>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 22:40:49 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/</guid>
		<description><![CDATA[Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended? I was working on building an automated testing framework for a welfare system in which cases could be added [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended?</p>  <p>I was working on building an automated testing framework for a welfare system in which cases could be added and benefits run for a given month.</p>  <p>A typical scenario might be something like:</p>  <ol>   <li>Create a new case for this month. </li>    <li>Add some people, do some things. </li>    <li>Run benefits for this month. </li>    <li>Run benefits for the next month.&#160; Something should happen because the child on the case is now 19. </li> </ol>  <p>Seems pretty straightforward until you consider what happens if someone hard codes dates into the test.</p>  <p>I am sure you can imagine plenty of scenarios in a situation like this where hard coded dates would eventually cause all kinds of problems.</p>  <p>The problem is… </p>  <p><strong>If you create an API which takes in various dates, how do you ensure the dates passed in are calculated and not just hard coded?</strong></p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pigsinblanket" border="0" alt="pigsinblanket" src="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket_thumb.jpg" width="514" height="514" /></a> </p>  <h2>Why convention doesn’t work</h2>  <p>Your first response might be to create some documentation that describes the importance of making dates “float” forward with time, and not be hard coded.</p>  <p>You might clearly describe how you should not hard code July 7th 1990 to be the birth date of a 20 year old for a test case.</p>  <p>You might give some guidelines of how to properly calculate ages.</p>  <p>But, you have no way of making sure the users of your API will follow those conventions or even read your document.</p>  <p>What if we do the hard work for them?</p>  <h2>Why utilities are still not good enough</h2>  <p>The next idea you might have is to create utilities that would do date conversions and calculate ages for the user of your API, so that they just have to remember to use them and all will be good.</p>  <p>This solution is better than one relying purely on convention, but still has some major flaws.&#160; Part of the problem of utility methods is that they are not self-discoverable.&#160; I’ve <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">talked about before</a> how DateUtilities like classes can get overlooked if you don’t know the utility class is there.</p>  <p>If you are relying on your users to go out and find your utility methods to make life easier for them, you are putting a large amount of responsibility in the wrong place.&#160; In my experience, it is very unlikely that anyone but yourself will actually use the utility methods.</p>  <p>You really need a way to stop them from being able to hard code dates.</p>  <h2>How can you stop someone from hard coding dates?</h2>  <p>Don’t accept dates in your API.</p>  <p>It is simple.</p>  <p>What?&#160; What do you mean?&#160; You can’t just stop accepting dates, you need dates.&#160; Not just dates, but integers, or strings.&#160; You can’t just not accept the bad data… or can you?</p>  <p>Consider wrapping the data type in another data type which creates your desired data type, but only using the convention or rules you desire.</p>  <p>Let me show you an example with the dates:</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(DateTime applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>    DoSomethingWithTheDate(applicationDate);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(<span style="color: #0000ff">new</span> DateTime(1990, 7, 8));</pre>
<!--CRLF--></div>
</div>

<p></p>

<p>In the above example, you can see that I am directly taking a .NET DateTime object.&#160; You can also see that I am directly hard coding a date when calling this method.</p>

<p>Let’s see if we can fix that.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(CaseDate applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     DoSomethingWithTheDate(CaseDate.ToDateTime());</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(CaseDate.YearsAgo(20));</pre>
<!--CRLF--></div>
</div>

<p></p>

<h2>What happened?</h2>

<p>Here is what we did:</p>

<ol>
  <li>We created a custom type called CaseDate. </li>

  <li>We replaced all the external usages of DateTime with CaseDate. </li>

  <li>We provided methods on CaseDate which allow the creation of dates, only through the way we want to allow them to be created. </li>
</ol>

<ol>Now we can easily prevent users of the API from being able to create hard coded dates.&#160; The API only will take CaseDate objects and internally creates DateTime objects from the CaseDate objects.</ol>

<ol>We can add other methods to CaseDate to allow the creation of dates from x number of months ago or in the future, or any other valid creation method we want.</ol>

<p>By doing this, we are restricting the valid set of inputs to our methods at compile time, not throwing exceptions at run time.</p>

<p>We are achieving the same kind of valuable input constrictions that we have been able to <a href="http://elegantcode.com/2010/05/08/the-power-of-enum/">achieve with enumerations</a>, except we are adding more complex restrictions than a simple list of selections.</p>

<h2>Where can I use this?</h2>

<p>Not just dates.&#160; There are many places where restricting the input to your method or API is going to simplify logic, protect against error conditions, and enforce constraints.</p>

<p>Consider using this pattern in some of these scenarios:</p>

<ul>
  <li>You want to use an enumeration, but your list of possible choices is too large, or repetitive. </li>

  <li>Anywhere you are using a primitive type and that primitive type represents some more complex concept. </li>

  <li>Anywhere you have parameter validation or manipulation repeated in multiple methods. </li>

  <li>Anytime you process some input or repeat a series of steps to transform it before sending it as input. </li>
</ul>

<p>Every time you are about to make a primitive type a parameter to a method you should ask yourself if it makes sense to wrap the primitive type into an class.</p>

<p>Remember, especially when creating an API, any time your method takes a primitive type, you lose the ability to constrain that input, and are forced to validate it instead.</p>

<p>Should you always wrap all primitive types?&#160; No, but it is another tool you can use to provide an extra layer of indirection between the logic of your API and your callers use of it.</p>

<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Prefer Additional Methods Over Additional Overloads</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
		<comments>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 17:35:54 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/</guid>
		<description><![CDATA[If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do. Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do.</p>  <p>Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are conscious of making that code as readable and terse as possible.</p>  <p><strong>Seldom do we think about the use of our code from an API standpoint.</strong></p>  <p>There is a subtle difference between designing your code in a way that will make it easier for someone else to maintain, and designing your code in a way that will make it easier for someone else to use.</p>  <h2>Intellisenselessness</h2>  <p>How often are you working against some API and you type a method name you want to use only to have intellisense present you with 5 overloads for the method all with several different parameters choices?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginOverloads" border="0" alt="LoginOverloads" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads_thumb.png" width="600" height="151" /></a> </p>  <p>Which one do you use?&#160; It is hard to be sure, you end up having to read through the long lists of parameters to figure out what method you should call and what parameters you should pass it.</p>  <p>Wouldn’t it be better if you were presented with what the method does in the method name rather than guessing what it does in the parameter list?&#160; Something like this?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginMoreMethods" border="0" alt="LoginMoreMethods" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods_thumb.png" width="596" height="261" /></a> </p>  <h2>Perspective</h2>  <p>From the perspective of the person writing the <em>Login</em> method(s), overloads probably seem like the most efficient and correct way to implement the multiple ways the method can be called.</p>  <p>From the perspective of the person using the <em>Login</em> method(s), additional methods are much preferred, because they are easier to understand and know what you are looking for.</p>  <p><strong>Try to think from the perspective of someone using your code when writing your code.</strong></p>  <h2>Extract boolean parameter to two methods</h2>  <p>I want to take a look at a very specific example that can be of great benefit to the readability and use of your code.</p>  <p>Take a look at this code below.</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login(<span style="color: #0000ff">bool</span> rememberMe)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>
Seems like a fine overload of a <em>Login</em> method.&#160; I have written code just like this, you probably have also.&#160; <br />

<p>&#160;</p>

<p>Unfortunately, by adding this overload, we have added some complexity to our API, because now the user of that code has to see that there is an additional overload that take a bool parameter called <em>rememberMe</em>.</p>

<p>Consider this longer alternative.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginDoNotRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Instead of overloading <em>Login</em> and making the user have to decide which overload to call and pass in a parameter, we have elected to create two differently named methods which take 0 parameters and clearly state what they are going to do.</p>

<p>I’m not saying you should never write overloads, but anytime you see an overload in your code base, you should stop and think if it would be more clear to make that overloaded method into two different methods that can eliminate one or more of the parameters.</p>

<p><strong>Any time you are restricting the number of choices someone using your code has to make, you are making that code simpler to use.</strong></p>

<p>If you don’t believe me, consider why the iPhone has only one button.</p>

<h5><strong>As always, you can subscribe to this </strong><a href="http://feeds2.feedburner.com/ElegantCode"><strong>RSS feed</strong></a><strong> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at </strong><a href="http://simpleprogrammer.com"><strong>http://simpleprogrammer.com</strong></a><strong>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Say &#8220;No&#8221; to &#8220;Null&#8221;</title>
		<link>http://elegantcode.com/2010/05/01/say-no-to-null/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=say-no-to-null</link>
		<comments>http://elegantcode.com/2010/05/01/say-no-to-null/#comments</comments>
		<pubDate>Sat, 01 May 2010 19:35:05 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/05/01/say-no-to-null/</guid>
		<description><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after. What do you do if "null” [...]]]></description>
			<content:encoded><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after.
<blockquote>What do you do if "null” is passed in?</blockquote>
My answer may turn out to be a bit of a surprise.
<blockquote><span style="background-color: #f4f5f7;">Nothing, I don’t handle nulls in code that I control the use of.</span></blockquote>
“What?  What?” you say.  “You don’t handle null?  What kind of heresy is that?”  It is the kind of heresy that helps produce elegant code and I will show you why.
<h2>How well do you handle null right now?</h2>
Would you say that in most of the code you write you properly check all arguments for null?

Or, do you like most developers, handle null in certain cases when you happen to think about it, or after the application dumps a “null pointer exception” stack trace?

Be honest, look at your code if you have to.

The problem is “d00d ur d0ing it r0ng!”

<a href="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="john-mccarthy-programming-completely-wrong" src="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong_thumb.jpg" border="0" alt="john-mccarthy-programming-completely-wrong" width="349" height="452" /></a>

Unless you are some kind of anal retentive perfectionist, you are probably not handling null in every single method call.  That means there are huge potential bugs in the code that you are writing which will throw null pointer exceptions.  That is bad, I agree.

So, if you are not handling it correctly right now, then what can you do to fix that?
<h2>Avoiding null in the code you “own”</h2>
You can’t control external libraries.  And you can’t control how people will use your code, but you can control the code you write and you can, to a degree, control the code your shop writes.

The better strategy is to never pass null in the first place.

You can either focus your efforts on:
<ul>
	<li>Checking for null</li>
	<li>Not ever passing null</li>
</ul>
<ul>The more elegant solution is to focus on never passing null.  By doing this you will end up writing less code and avoid decisions about how to handle null inside of a method that doesn’t have enough context to decide what to do.</ul>
Let’s look at an example:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> TransmographyThreeStrings(<span class="kwrd">string</span> first, <span class="kwrd">string</span> second, <span class="kwrd">string</span> third)
{
     <span class="kwrd">if</span>(<span class="kwrd">string</span>.isNull(first) || <span class="kwrd">string</span>.isNull(second) || <span class="kwrd">string</span>.isNull(third))
    {
           <span class="rem">// hmm, I donno, what should I do?  Should I throw an exception?</span>
           <span class="rem">// should I return an empty string?</span>
           <span class="rem">// what if the first string wasn't null, can we still do something meaningful?</span>
           <span class="rem">// how will the caller of the method know what I will do?</span>
    }

}</pre>
You can see there that we are checking each parameter for null.  The problem is we don’t know what we should do.  We have lots of options, but none of them are obvious.

How much better is it to make sure that we never pass null into methods, rather than write this kind of code in every method?
<h2>What about accidentally passing in null?</h2>
Many of you are probably thinking at this point that the main way null gets passed into a method is because someone calls a method without knowing that it contains a null value.
<pre class="csharpcode">TransmographyThreeStrings(<span class="str">"Hello"</span>, <span class="str">"World"</span>, mysteryObject.Text);</pre>
Perhaps <em>mysteryObject.Text </em>is null.  You wouldn’t even know it.

Ah, but you can.  Or you can prevent it at least.  Somewhere <em>mysteryObject </em>gets created.  When it gets created its values either get initialized or not.  You can prevent any of its values from being null, several ways:
<ul>
	<li>Always initialize variables when they are declared.</li>
	<li>Use a <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> to ensure that objects are always fully constructed before being created.</li>
	<li>Use properties to provide default values or lazy initialize.</li>
	<li>Make your objects <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> as much as possible.</li>
</ul>
The practices that prevent null from accidentally being passed in make your code much more elegant than repeating <em>if blah == null</em> code all over the place.

<strong>In general, you should always strive to eliminate the passing of null rather than checking for null.  By doing so you reduce extra lines of code in each method, and are forced to use better design practices.</strong>
<h2>Exceptions</h2>
Yes, there are times when you need to check for null.  If you are writing a library that external developers will use, then you will probably want to check for null in all of your methods that are exposed as part of the API.  (On your internal methods, you don’t need to since you have already cleansed the input.)

Also, if your code is being used as a callback to some API and you don’t know if it can ever pass null into your code, you probably should check for null.

A bad excuse is that other developers may pass null to your method. <strong>It is much better as a software shop to put the onus of not passing null on the caller of any method rather than putting it on the writer of the method being called.</strong>

You will also reduce your exception handling code, because you will have less exceptions for invalid parameters.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/05/01/say-no-to-null/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>If Self-Documenting Code is the What, Unit Tests are the Why</title>
		<link>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-self-documenting-code-is-the-what-unit-tests-are-the-why</link>
		<comments>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:09:04 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/</guid>
		<description><![CDATA[It is not enough to just write code that is clean and self-documenting.  Eliminating comments and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it. If you recall from my original post on [...]]]></description>
			<content:encoded><![CDATA[It is not enough to just write code that is clean and self-documenting.  <a href="http://elegantcode.com/2010/04/18/eliminating-comments-the-road-to-clarity/">Eliminating comments</a> and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it.

If you recall from my <a href="http://elegantcode.com/2010/04/09/what-does-elegant-code-mean-to-me/">original post</a> on Elegant code, I stated that elegant code is:
<blockquote>Something that is simple yet effective, delivered with grace.</blockquote>
By writing self-documenting code we are hopefully able to achieve some of the aspects of simplicity and grace, but it tells us nothing about the effectiveness of the code.
<h2>Bringing the dead to life</h2>
<a href="http://elegantcode.com/wp-content/uploads/2010/04/zombies.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="zombies" src="http://elegantcode.com/wp-content/uploads/2010/04/zombies_thumb.jpg" border="0" alt="zombies" width="441" height="295" /></a>

Throwing out comments is a debatable topic.  <a href="http://www.reddit.com/r/programming/comments/bsutx/">It raises quite a bit of controversy</a>, as you can see from some of the comments on my post about the subject.  The reason, perhaps, that so many people are so staunchly opposed to the idea, is because they are worried, and rightly so, that throwing out comments will reduce the documentation of what the code is doing.

Think about that for a second.  Is documentation of what the code is doing important?  It better be.  What we are trying to accomplish by writing self-documenting code instead of comments, is to take the vessel, which is the code itself, and make that same vessel be the documentation of what the code does.  It is by doing this that we creating a living representation of the functionality of the code.  Comments are akin to a dead representation of the functionality of the code because they do not change automatically with the code.

I diverge to talk about comments so that I can draw a parallel to another form of documentation which is valuable and should be considered necessary.  That other set of documentation is requirements.  Have you ever written requirements documents?  Have you ever captured requirements from the customer and put them into UML diagrams, or perhaps plopped them into some templated Word document, which is never updated again, and no one reads, because no one trusts it is correct?  Wouldn’t it be great if we would replace that dead document or set of documents, with a living one?

The good news is we can, and some of us have.  And I fully expect this recommendation will be just as controversial, because <strong>I am suggesting that we don’t have to write low level specifications of the system at all, instead we can write good unit tests. </strong>When we do this, we are taking a dead form of document and bringing it to life.
<h2>Unit tests tell us why and how our code is effective</h2>
If
<pre class="csharpcode">i = 5;  // Widget count defaults to five.</pre>
is replaced with
<pre class="csharpcode">widgetCount = DEFAULT_WIDGET_COUNT;</pre>
<!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

then
<blockquote><span style="background-color: #ffffff;">1.1.5 When a new widget is created, the widget count should be increased by one.</span></blockquote>
is replaced with
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> When_NewWidgetIsCreated_Then_WidgetCountIsIncreasedByOne()
{
     WidgetFactory.Count = 3;
     WidgetFactory.CreateNew();
     assertEquals(4, WidgetFactory.Count);
}</pre>
The unit test is replacing the low level requirement, which is somewhat open to interpretation and untied to the code, with an absolute and completely tied-to-the-code, specific requirement.

The unit test is telling us why our code is built the way it is.  It is telling us what requirement that particular structure of code is trying to address.  <strong>It is telling us what end result that code is trying to accomplish and what the expectations are on the results of a given condition.</strong>

The unit test is telling us how the code is to be used in order to achieve its result.  It is serving as a living reference to the syntax and use of the code we built.  <strong>Instead of providing instructions on how to use our API, we are providing a living example, and proof that it will indeed work.</strong> Examples are often much more effective than instructions anyway.
<h2>What exactly are we replacing?</h2>
At this point we are not trying to replace all the documentation of the system (at this point).

With self-documenting code, we sought to eliminate comments, and replace them with good variable and method names.

With unit tests, we seek to eliminate technical documentation and requirements of the system, that is targeted at a developer or technical audience.

We are NOT trying to eliminate high level specifications of the system, or use cases. <strong>Unit tests DO NOT replace that kind of documentation! </strong>We will talk about replacing that kind of documentation when we talk about automated functional or system tests.

Simply put, any kind of documentation that you would give to a developer so they understand how the system works and how to use the code or APIs, can be easily replaced by writing good unit tests.

Our simple goal is to replace the “dead” documentation (meaning that it does not update automatically with the thing it is documenting), with “living” documentation in the form of unit tests.

One last point.  I want to be clear that I am not saying that having unit tests automatically results in the ability to replace technical documentation.  Just like having long-named methods and variables doesn’t automatically replace the need for comments.  It is a matter of the quality of the unit tests that are written, just as it is a matter of the quality of the self-documenting code.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>REST: Resources, URI&#8217;s and Representations</title>
		<link>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rest-resources-uris-and-representations</link>
		<comments>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 04:00:13 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/</guid>
		<description><![CDATA[In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions. Resources Resources are at the heart of REST.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions.</p>  <h3>Resources</h3>  <p>Resources are at the heart of REST.&#160; You are already used to resources as a web browsing consumer.&#160; A resource is not something specific to REST, instead it is the first thing you probably want to consider when architecting a RESTful application.&#160; A resource is simply the entity, item, or thing you want to expose.</p>  <p>Perhaps you have approached application architecture using one or many of several modeling and design techniques.&#160; Data First practitioners typically begin with databases and data models.&#160; DDD proponents like to begin by modeling around business entities and interactions, while their cousins in the BDD camp model around business activities.</p>  <p>When you decide to apply REST you will need to think a lot more about data entities and domain objects as resources.&#160; Your existing models may or may not closely map to resources.&#160; The shift in thinking may appear slight, but is very important.&#160; It centers around making things&#160; addressable.&#160; Each resources must by uniquely identifiable as we will see in the next section.&#160; We are used to identity with most data entities, but our domain objects may not always be as easily identifiable.&#160; Likewise, our data entites may have identity, but not map to a resource.&#160; </p>  <p>Consider the classic customer and order scenario for example.&#160; If each customer and each order can be identified then it will be easy to design RESTful systems around them.&#160; However, if the model requires a lot of context then our challenge is a little bit larger.&#160; Perhaps we must first identify a partner, then a year, then a customer, and finally the order.&#160; Yes, that is a design smell in general.&#160; It makes fetching an order very difficult.&#160; Developing RESTfuly would only further expose that difficulty.&#160; Identifying your resources up front will help you reduce the possible impedance mismatches you might end up with between what you want to expose and your data or domain models.</p>  <p>REST is about interacting with Resources!</p>  <h3>URI’s</h3>  <p>REST defines the identity of a resource via URI.&#160; Each resources has a unique address in URL form (ie. using the http protocol).&#160; Interaction with a resource will take place at its URI.&#160; As an example, my twitter status feed resource URI is <a title="http://twitter.com/optionstrict" href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; That URI is unique to my feed and that is what you expect to find at that URI.&#160; In the Twitter databases or domain models my account may be referred to by the string optionstrict, or perhaps as some random number or guid.</p>  <p>To consume my status history via a service interface twitter provides another URI at <a title="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict" href="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict">http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict</a>.&#160; I would actually prefer to have access at the same URI for html, json, and xml formats.&#160; Twitter probably has its reasons for distinguishing API access from HTML rendering, but they have actually complicated their architecture by doing so.&#160; When designing the URI’s for your resources, make them easy for your users to work with.&#160; </p>  <h3>Representation</h3>  <p>Lets continue with the twitter example to describe what is meant by Representation.&#160; Given a URI and a Resource, what will your consumers receive when they issue a GET request to the URI?&#160; Twitter chose a representation of my account and included status history and profile for the response at <a href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; They decided to put a representation of my profile photo at <a title="http://twitter.com/account/profile_image/optionstrict" href="http://twitter.com/account/profile_image/optionstrict">http://twitter.com/account/profile_image/optionstrict</a>.&#160; In your REST solutions you will need to consider how you want to represent a resource at its URI.&#160; Each representation will have a unique URI.&#160; </p>  <p>Representations are also important for manipulating resources.&#160; You must define the representation required to create and update resources.&#160; Twitter status updates require a text representation with a maximum of 140 characters.&#160; They allow additional values in the status representation, such as latitude and longitude.&#160; Your REST solutions similarly must define representations for Requests and Responses.</p>  <p>I hope that this short introduction has helped you to see that the core essence of REST is simple and fairly obvious.&#160; As you look at your current solutions what are the resources you are exposing?&#160; Could you make those resources identifiable by URI?&#160; What representation would you place at each URI?&#160; What representation would you require for manipulating a given resource?</p>  <p>Also, notice I did not mention much about data formats, Content Type, Mime, etc.&#160; Those details can cloud your design if you try to start with them. If you can’t wait for my post about how REST handles html, json, xml from the same URI, then start googling Content Negotiation, Accept header, and Content-Type header.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Driven Architecture: Publishing Events using an IOC container</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
		<comments>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 22:40:49 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/</guid>
		<description><![CDATA[Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended? I was working on building an automated testing framework for a welfare system in which cases could be added [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended?</p>  <p>I was working on building an automated testing framework for a welfare system in which cases could be added and benefits run for a given month.</p>  <p>A typical scenario might be something like:</p>  <ol>   <li>Create a new case for this month. </li>    <li>Add some people, do some things. </li>    <li>Run benefits for this month. </li>    <li>Run benefits for the next month.&#160; Something should happen because the child on the case is now 19. </li> </ol>  <p>Seems pretty straightforward until you consider what happens if someone hard codes dates into the test.</p>  <p>I am sure you can imagine plenty of scenarios in a situation like this where hard coded dates would eventually cause all kinds of problems.</p>  <p>The problem is… </p>  <p><strong>If you create an API which takes in various dates, how do you ensure the dates passed in are calculated and not just hard coded?</strong></p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pigsinblanket" border="0" alt="pigsinblanket" src="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket_thumb.jpg" width="514" height="514" /></a> </p>  <h2>Why convention doesn’t work</h2>  <p>Your first response might be to create some documentation that describes the importance of making dates “float” forward with time, and not be hard coded.</p>  <p>You might clearly describe how you should not hard code July 7th 1990 to be the birth date of a 20 year old for a test case.</p>  <p>You might give some guidelines of how to properly calculate ages.</p>  <p>But, you have no way of making sure the users of your API will follow those conventions or even read your document.</p>  <p>What if we do the hard work for them?</p>  <h2>Why utilities are still not good enough</h2>  <p>The next idea you might have is to create utilities that would do date conversions and calculate ages for the user of your API, so that they just have to remember to use them and all will be good.</p>  <p>This solution is better than one relying purely on convention, but still has some major flaws.&#160; Part of the problem of utility methods is that they are not self-discoverable.&#160; I’ve <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">talked about before</a> how DateUtilities like classes can get overlooked if you don’t know the utility class is there.</p>  <p>If you are relying on your users to go out and find your utility methods to make life easier for them, you are putting a large amount of responsibility in the wrong place.&#160; In my experience, it is very unlikely that anyone but yourself will actually use the utility methods.</p>  <p>You really need a way to stop them from being able to hard code dates.</p>  <h2>How can you stop someone from hard coding dates?</h2>  <p>Don’t accept dates in your API.</p>  <p>It is simple.</p>  <p>What?&#160; What do you mean?&#160; You can’t just stop accepting dates, you need dates.&#160; Not just dates, but integers, or strings.&#160; You can’t just not accept the bad data… or can you?</p>  <p>Consider wrapping the data type in another data type which creates your desired data type, but only using the convention or rules you desire.</p>  <p>Let me show you an example with the dates:</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(DateTime applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>    DoSomethingWithTheDate(applicationDate);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(<span style="color: #0000ff">new</span> DateTime(1990, 7, 8));</pre>
<!--CRLF--></div>
</div>

<p></p>

<p>In the above example, you can see that I am directly taking a .NET DateTime object.&#160; You can also see that I am directly hard coding a date when calling this method.</p>

<p>Let’s see if we can fix that.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(CaseDate applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     DoSomethingWithTheDate(CaseDate.ToDateTime());</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(CaseDate.YearsAgo(20));</pre>
<!--CRLF--></div>
</div>

<p></p>

<h2>What happened?</h2>

<p>Here is what we did:</p>

<ol>
  <li>We created a custom type called CaseDate. </li>

  <li>We replaced all the external usages of DateTime with CaseDate. </li>

  <li>We provided methods on CaseDate which allow the creation of dates, only through the way we want to allow them to be created. </li>
</ol>

<ol>Now we can easily prevent users of the API from being able to create hard coded dates.&#160; The API only will take CaseDate objects and internally creates DateTime objects from the CaseDate objects.</ol>

<ol>We can add other methods to CaseDate to allow the creation of dates from x number of months ago or in the future, or any other valid creation method we want.</ol>

<p>By doing this, we are restricting the valid set of inputs to our methods at compile time, not throwing exceptions at run time.</p>

<p>We are achieving the same kind of valuable input constrictions that we have been able to <a href="http://elegantcode.com/2010/05/08/the-power-of-enum/">achieve with enumerations</a>, except we are adding more complex restrictions than a simple list of selections.</p>

<h2>Where can I use this?</h2>

<p>Not just dates.&#160; There are many places where restricting the input to your method or API is going to simplify logic, protect against error conditions, and enforce constraints.</p>

<p>Consider using this pattern in some of these scenarios:</p>

<ul>
  <li>You want to use an enumeration, but your list of possible choices is too large, or repetitive. </li>

  <li>Anywhere you are using a primitive type and that primitive type represents some more complex concept. </li>

  <li>Anywhere you have parameter validation or manipulation repeated in multiple methods. </li>

  <li>Anytime you process some input or repeat a series of steps to transform it before sending it as input. </li>
</ul>

<p>Every time you are about to make a primitive type a parameter to a method you should ask yourself if it makes sense to wrap the primitive type into an class.</p>

<p>Remember, especially when creating an API, any time your method takes a primitive type, you lose the ability to constrain that input, and are forced to validate it instead.</p>

<p>Should you always wrap all primitive types?&#160; No, but it is another tool you can use to provide an extra layer of indirection between the logic of your API and your callers use of it.</p>

<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Elegant Code &#187; Architecture</title>
	<atom:link href="http://elegantcode.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quinine For Sale</title>
		<link>http://elegantcode.com/2012/01/18/monitoring-an-mmo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-an-mmo</link>
		<comments>http://elegantcode.com/2012/01/18/monitoring-an-mmo/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:45:32 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MMO]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2012/01/18/monitoring-an-mmo/</guid>
		<description><![CDATA[I’ve been working on a free-to-play MMO Quinine For Sale, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I’ve been working on a free-to-play <a href="http://www.heroup.com" target="_blank">MMO</a> <b>Quinine For Sale</b>, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before they become serious and fixing problems when they inevitably do.&#160; So, there are two questions.&#160; “Is there a problem in the game?” “What is causing the problem?”&#160; </p>  <p>When trying to debug something on our development and test clusters, typically you can tail log files.&#160; We have a python script that can monitor the communication between various parts of the game and pretty-print it along with color to highlight “this is a problem!”&#160; Attaching a debugger to a running process is also not uncommon.&#160; However, looking at logs and bus traffic in realtime on a production environment gives you this neat “Matrix-y” experience.&#160; Attaching a debugger to a production process (assuming you could, which you can’t) would get you smacked with a rolled-up newspaper.&#160; “Bad Developer!&#160; No treat!”&#160; So, what can you do?</p>  <h4>Monitoring</h4>  <p>When you’ve got clusters full of machines, using <a href="http://www.nagios.org/" target="_blank">Nagios</a> to monitor things is an obvious solution.&#160; Beyond making sure the power is on and other sysadmin things, we’ve written other checks to see if the login process is working, the parts are working together, and automating typical in-game functions.&#160; For example, if nagios can’t successfully log into the game do basic game activity, then alerts happen.</p>  <h4>Metrics for EVERYTHING</h4>  <p>Anything that happens in game has metrics reporting tied to it, generating piles of data constantly.&#160; We use <a href="http://www.cacti.net/" target="_blank">Cacti</a> to visualize game activity.&#160; An example metric is concurrent users, or CCU.&#160; We graph how many people are in the game over time, which when things are healthy should be a nice smooth curve climbing to peak game hours, then descending nicely through the night.</p>  <p>We can tell by sight if the game looks healthy or not – if the CCU graph is jaggy, has a sudden drop or spike, or drops to zero then we know that something is wrong.&#160; Typically nagios alerts accompany the graphs, giving more data points on where to look.&#160; But this has also pointed out areas where a nagios check was missing or wasn’t working as intended.</p>  <h4>Log Files</h4>  <p>When a player gets an error in game, the error dialog box gives them the opportunity to submit the error details back to us.&#160; If we see a spike in user-reported errors through this or other customer service means, we know we have something of interest to look for.&#160; </p>  <p>The game server components make use of log4j and similar logging frameworks.&#160; Anything that you’d want to watch happening in game needs to be aggressively logged.&#160; All components are configured so that operations can change the log level on the fly.&#160; That’s still quite a bit of data across many machines though, so all that information is run through <a href="http://www.splunk.com/product" target="_blank">Splunk</a> to be indexed and searchable.&#160; This gives us a great tool for searching through log data, examining trends, or watching selected activity in real time.&#160; Unfortunately it is very expensive so we are selective about the data that passes through it.&#160; </p>.  Buy Quinine from mexico.  Buy Quinine no prescription.  No prescription Quinine online.  Online buying Quinine.  Quinine no prescription.  Quinine street price.  Buy no prescription Quinine online.  Quinine coupon.  Quinine over the counter.  Where can i buy Quinine online.  Quinine steet value.  Where to buy Quinine.  Order Quinine online overnight delivery no prescription.  Quinine recreational.  Quinine canada, mexico, india.  Ordering Quinine online.  Quinine without prescription.  Quinine price, coupon.  Quinine description.  Order Quinine from mexican pharmacy.  Quinine pics.  What is Quinine.  Japan, craiglist, ebay, overseas, paypal.  Order Quinine from United States pharmacy.  Order Quinine online c.o.d.  Quinine trusted pharmacy reviews.  Quinine treatment.  Buy Quinine from canada.  Quinine used for.  Discount Quinine.  Is Quinine addictive.  Quinine forum.  Buy Quinine online no prescription.  Is Quinine safe.  Purchase Quinine for sale.  Effects of Quinine.  Buy Quinine online cod.  Quinine australia, uk, us, usa.  Buy Quinine without prescription.  Quinine online cod.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4721'>Buy Flonase Without Prescription</a>. <a href='http://elegantcode.com/?p=4234'>Buy Periactin Without Prescription</a>. <a href='http://elegantcode.com/?p=4203'>Buy Armour Without Prescription</a>. <a href='http://elegantcode.com/?p=4899'>Buy Macrobid Without Prescription</a>. <a href='http://elegantcode.com/?p=4534'>Xalatan For Sale</a>. <a href='http://elegantcode.com/?p=4302'>Phenergan wiki</a>. <a href='http://elegantcode.com/?p=4268'>Soma maximum dosage</a>. <a href='http://elegantcode.com/?p=4602'>Zovirax treatment</a>. <a href='http://elegantcode.com/?p=4578'>Cialis price, coupon</a>. <a href='http://elegantcode.com/?p=4189'>Flexeril price</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.leaduganda.org/?p=514'>Quinine For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=4820'>Quinine For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2780'>Quinine For Sale</a>. <a href='http://www.thegriffonnews.com/?p=10177'>Quinine For Sale</a>. <a href='http://www.independentworldreport.com/?p=2409'>Quinine For Sale</a>. <a href='http://changecamp.ca/?p=295'>Quinine description</a>. <a href='http://social-blend.com/?p=624'>Quinine price, coupon</a>. <a href='http://blog.farmland.org/?p=3946'>Online buying Quinine hcl</a>. <a href='http://4realz.net/?p=1595'>Quinine from canada</a>. <a href='http://reversemortgagedaily.com/?p=14535'>Where to buy Quinine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2012/01/18/monitoring-an-mmo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temovate Cream For Sale</title>
		<link>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-software-development-will-never-be-engineering</link>
		<comments>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 03:37:48 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/</guid>
		<description><![CDATA[I always find it rather interesting when academics try to quantify generalized metrics about software development. Temovate Cream For Sale, Things like: per lines of code, there will be X number of bugs. Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.” These are all interesting [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I always find it rather interesting when academics try to quantify generalized metrics about software development.</p>  <p> <b>Temovate Cream For Sale</b>, Things like: per lines of code, there will be X number of bugs.</p>  <p>Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.”</p>  <p>These are all interesting thoughts, but software development will never conform to rigid engineering principles like many other engineering practices.&#160; The longer I work in the field, the more and more I realize that software development has nothing to do with engineering.&#160; We just happen to attend some of the same math classes in school.</p>  <h2>Building bridges</h2>  <p>One of the main arguments I hear people make about the current state of software development as an engineering practice is based around its relative maturity to other engineering fields.</p>  <p>There is a huge problem with this line of thinking.</p>  <p>The argument goes something like this:&#160; “<em>Engineering has been around for hundreds of years and has matured to the point where it is a measurable science, but software development has only been around in earnest for the last few decades or so, therefore it is relatively immature as an engineering discipline.”</em></p>  <p>On the surface this argument seems sounds.&#160; And certainly in 50 years software development will be different than it is now.&#160; Heck, it is much more different than it was just 10 years ago.</p>  <p>But, here is the problem.&#160; We build much more software than we do bridges.</p>  <p><img src="http://www.nps.gov/glca/historyculture/images/Navajo_Bridges_1.gif" width="589" height="442" /></p>  <h6 align="center">&#160;</h6>  <p>Let me give you an example that came to light in another area of my interest… poker.</p>  <h1></h1>  <h2>The poker quickening</h2>  <p>An interesting thing happened in the poker community in the last 10 years; poker pros with decades of experience started getting beat time and time again by 19 year old poker prodigies.</p>  <p>From an outside perspective it looks like the poker world opening up just widened the search for talent and there it was.&#160; But, a closer examination of the evidence leads to the truth.</p>  <p>Before the online poker industry was born, poker was played in card rooms and casinos in states where it was legal and occasionally at small home games throughout the US.</p>  <p>A poker pro might play poker tournaments perhaps 100 times to 150 times a year.&#160; The sum knowledge of the poker community and the meta game around it was based on this base of professional poker players playing tournaments and gaining experience at this mediocre rate.</p>  <p>Once the internet poker rooms started opening up, things changed, and they changed rapidly.&#160; Now anyone could play poker from their home PC.&#160; Not only could they play poker, they could play poker tournaments at all hours of the day.</p>  <p>Here is a list of some of the major changes that took place:</p>  <ul>   <li>Hands are dealt at 60-80 hands per hour instead of 10-30</li>    <li>Players can play in many tournaments at one time, 10 tournaments at once is not unheard of</li>    <li>Players can analyze hand histories and historical data about their play and opponents play through the use of software </li>    <li>Age requirements are out the window, technically any one of any age could be playing online</li>    <li>Players can play 24 hours a day</li>    <li>The professional online tournament player could easily play over 3000 tournaments in a year, while a brick and mortar pro would be lucky to reach 100 in a year.</li>   <img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://t1.gstatic.com/images?q=tbn:ANd9GcRj9uGNWSyqGWEneiH6xaBAyS6COwGYicdNadZu-06KWQLhIi6LMw&amp;t=1" width="316" height="270" /></ul>  <p>&#160;</p>  <p>So where am I going with all this?</p>  <p>The point is that as a whole more hands were dealt and more poker knowledge and experience was obtained in 1 year of online poker than probably the entire history of poker before that.&#160; We reached such an accelerated pace of play that all previous knowledge of poker became obsolete.&#160; </p>  <p>The strategy of tournament poker completely changed.&#160; The game evolved perhaps 500 years into the future in a matter of 5 years time.</p>  <p>The same has happened with software development.</p>  <h2>Back to the bridge building</h2>  <p>So let’s take that poker example and look at it through the lens of software development.</p>  <p>Let us compare the engineering maturity to software development to the engineering maturity of the engineering discipline of building bridges.</p>  <p>I think most people would agree that bridge building is a very mature engineering discipline but many people would argue that software development is not.</p>  <p><strong>How many bridges do you think have been built in the world?</strong></p>  <p>Well there are <a href="http://www.betterroads.com/category/bridge-inventory/erroads.randallreillycms.com/files/2009/11/BR1109_BridgeInventory.pdf">about 600,000 bridges in the United States alone</a>, so the world figure must be at least somewhere around 10 times that number perhaps 20.</p>  <p><strong>How many software programs have been written?</strong></p>  <p>This is a very hard number to estimate, but lets take a rough guess based on <a href="http://stackoverflow.com/questions/453880/how-many-developers-are-there-in-the-world">how many software developers there are in the world</a>.&#160; </p>  <p>If we say there are about 12 million software developers and each software developer has written approximately 3 programs, we can estimate that a large amount more programs have been written than bridges built.</p>  <p>My point is not to knock bridge building, we are pretty good at it as a whole, but rather to show that collectively, even though we have been building bridges for hundreds of years, we have probably devoted an equivalent amount of time to building software.</p>  <p>This line of thinking may lead you to argue back that software development and bridge building are very different.&#160; Bridge building has a fixed set of requirements that are pretty close to the the same for each bridge you build, but software development is a big open void of whims and ambiguously contradictory statements.</p>  <p>I agree with you 100%!&#160; And in essence that is my point.</p>  <h2>Software development is different</h2>  <p>And we have had enough time to realize that.&#160; Waiting for software development to gel into some kind of engineering discipline like other engineering disciplines is like waiting for water without gelatin mix to turn into Jello.&#160; </p>  <p>It’s just not going to happen!</p>  <p>In my mind it is clear that the argument that we haven’t given it enough time is just wishful thinking.&#160; The nature of software development, just like online poker, leads itself to rapid evolution.</p>  <p>Consider what direction software development is evolving.&#160; Is it even evolving in the direction of rigid engineering practices or is it evolving in the exact OPPOSITE direction?</p>  <p>Ten years ago, we tried to use UML diagrams and CASE tools to develop software.&#160; Ten years ago waterfall was all the rage.&#160; Ten years ago, we thought that ten years in the future we would have programs that would allow us to build software in the same way that CAD tools allow for building machine parts.</p>  <p>Not only did it not happen.&#160; It went completely the other way.&#160; Now we are all talking about Agile.&#160; Now people don’t even remember what CASE tools are.&#160; Now we are building software without trying to define the whole system in UML diagrams.</p>  <p><strong>The fact of the matter is software systems are unruly beasts!</strong></p>  <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://aznbadger.files.wordpress.com/2010/06/beast.jpg" /></p>  <p>In my mind it comes down to one simple distinction.&#160; Software is living, bridges aren’t.&#160; When you are done building a bridge, you are done building the bridge.&#160; </p>  <p>Sure someone, probably not you, will have to come along and do some routine maintenance on it.&#160; Sure, some small things might change about it, but for all intents and purposes the work is done.</p>  <p>In most software development scenarios, this is not the case.&#160; In most software development scenarios, releasing V1 is not even close to the end.&#160; Sometimes V1 and V2 don’t even look that same at all.&#160; Software development is about operating on a living breathing thing and all the while keeping it alive.</p>  <p>The truth is, we software developers have more in common with surgeons than with other engineers.</p>  <h6>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com/">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>.  Buy Temovate Cream without a prescription.  Temovate Cream trusted pharmacy reviews.  Temovate Cream over the counter.  Where can i order Temovate Cream without prescription.  Online buy Temovate Cream without a prescription.  Temovate Cream no rx.  Buy cheap Temovate Cream no rx.  Temovate Cream photos.  Buy Temovate Cream online no prescription.  Order Temovate Cream online c.o.d.  Herbal Temovate Cream.  About Temovate Cream.  Australia, uk, us, usa.  Cheap Temovate Cream.  Temovate Cream class.  Temovate Cream brand name.  Online Temovate Cream without a prescription.  Buy Temovate Cream without prescription.  Buy Temovate Cream from canada.  After Temovate Cream.  Order Temovate Cream from mexican pharmacy.  Temovate Cream without a prescription.  Purchase Temovate Cream.  Temovate Cream natural.  Temovate Cream overnight.  Temovate Cream online cod.  Where can i buy cheapest Temovate Cream online.  Purchase Temovate Cream for sale.  Online buying Temovate Cream.  Purchase Temovate Cream online.  Temovate Cream used for.  Temovate Cream coupon.  Temovate Cream description.  Order Temovate Cream no prescription.  Temovate Cream maximum dosage.  Cheap Temovate Cream no rx.  Temovate Cream images.  Temovate Cream blogs.  Buy Temovate Cream online cod.  Buy generic Temovate Cream.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4472'>Bactroban For Sale</a>. <a href='http://elegantcode.com/?p=4632'>Armour For Sale</a>. <a href='http://elegantcode.com/?p=4639'>Buy Estrace Vaginal Cream Without Prescription</a>. <a href='http://elegantcode.com/?p=4668'>Buy Augmentin Without Prescription</a>. <a href='http://elegantcode.com/?p=4535'>Buy Tindamax Without Prescription</a>. <a href='http://elegantcode.com/?p=4931'>Fast shipping Diclofenac</a>. <a href='http://elegantcode.com/?p=4240'>Combivent brand name</a>. <a href='http://elegantcode.com/?p=4417'>Levaquin overnight</a>. <a href='http://elegantcode.com/?p=4597'>Purchase Toradol online</a>. <a href='http://elegantcode.com/?p=4221'>Australia, uk, us, usa</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.quarterlives.com/?p=1148'>Temovate Cream For Sale</a>. <a href='http://4realz.net/?p=1972'>Temovate Cream For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=5997'>Temovate Cream For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2476'>Temovate Cream For Sale</a>. <a href='http://www.thegriffonnews.com/?p=9947'>Temovate Cream For Sale</a>. <a href='http://social-blend.com/?p=1160'>Temovate Cream brand name</a>. <a href='http://blog.farmland.org/?p=3812'>Where can i find Temovate Cream online</a>. <a href='http://reversemortgagedaily.com/?p=14136'>Generic Temovate Cream</a>. <a href='http://linuxologist.com/?p=1792'>Temovate Cream photos</a>. <a href='http://home.officesnapshots.com/?p=114'>Order Temovate Cream from mexican pharmacy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
		<item>
		<title>Christmas Light Architectures Are Not That Shiny</title>
		<link>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=christmas-light-architectures-are-not-that-shiny</link>
		<comments>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:00:00 +0000</pubDate>
		<dc:creator>Jan Van Ryswyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/</guid>
		<description><![CDATA[I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way [...]]]></description>
			<content:encoded><![CDATA[<p>I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way overdue :-).</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb1.png" width="202" height="172" /></a> </p>  <p><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a>What's the major malfunction with those old, classic Christmas lights? We've all experienced it at some point. When one goes out, all the others go out as well. This is due to the fact that these lights are wired in series. The difference compared with today's Christmas lights is that every bulb has a shunt, which basically prevents this kind of failure caused by one or more lamps. Enough about the Christmas lights for now. Where am I going with this? Back in enterprise IT, I'm seeing the same kind of failures as with those classic, old Christmas lights.</p>  <p>The diagram below shows a classic RPC style architecture, much like those classic, old Christmas lights. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb2.png" width="565" height="329" /></a> </p>  <p>This is all fine and dandy as long as every part of the chain runs without too much hassle. But what happens if for some reason the centralized back-end web service goes down (light bulb goes out). This means that every smart client, website and batch application that uses this web service gets affected by this, like some sort of chain reaction. Parts of these client applications will no longer function correctly or they might even go down entirely. Same thing happens when the database of the centralized back-end web service goes down or any other external system that it depends on. When being confronted with this kind of architecture, how would one go about preventing this doomsday scenario to happen?</p>  <p>Suppose you’re a developer that has to work on the centralized back-end web service. This is usually a complex system as it obviously has to provide features for all kinds of applications. When this centralized back-end web service also has to deal with and depend on other external systems that might expose some unexpected behavior, how could one prevent the sky from falling down when things go awry in production?</p>  <p>Well for starters, you could start building in some stabilization points. Suppose for some reason, the centralized web service needs to incorporate some functionality offered by a highly expensive, super enterprise system that for some reason behaves very unstable and unpredictably on every full moon (expensive enterprise software not behaving correctly sounds ridiculous, but bare with me ;-) ). For example, we could use a message queue as a stabilization point. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb3.png" width="570" height="157" /></a> </p>  <p>This means that we put a message on a queue that is processed by some sort of worker process or service that does the actual communication with the misbehaving system. When the external system goes down, the message is either left on the message queue or put on an error queue for later processing when the external system comes back up again. There are some other things you need to think about like idempotent messaging, consistency, message persistence when the server goes down, etc. … . But if one of these dependencies goes down, the centralized back-end web service is still up-and-running which means that the systems that depend on its functionality can also continue to serve their users as they are able to keep doing their work.</p>  <p>Earlier this week I overheard this conversation that somewhat amazed me. I changed the names of the persons involved as well as the exact words used in order to protect the guilty.</p>  <blockquote>   <p><em>George: </em><em>We want to incorporate a message queue in order to guarantee stability and&#160; integrity between several non-transactional systems that our system depends on. It will also improve performance as these systems behave very slow at times and become unstable under pressure. This also gives us the opportunity to root out some major points friction that our end-users are experiencing right now.</em></p>    <p><em>Stan: But this means that the end-users are not completely sure if their actions are indeed fully carried out by the system. </em></p>    <p><em>George: End-users can always check the current state of affairs in their applications. If something goes wrong, their request is not lost and things will get fixed automatically later on as soon as the cause of the error has been fixed. </em></p>    <p><em>Stan:&#160; I don’t think that’s a very good idea. End-users have to wait until everything is processed synchronously, even if that means that they’ll need to wait for a long time. And if one of the external systems goes down, they should stop sending in new requests. Everything should come to a halt. They just have to stop doing what they are doing.</em></p>    <p><em>George: This means that because you lose the original request, some external systems might be set up correctly while others are not. Then someone has to manually fix these issues.</em></p>    <p><em>Stan: Then so be it!</em>&#160;</p> </blockquote>  <p>For starters, I was shocked by this conversation. This is just insane. Everything should come to a halt? Think about this scenario for a while: suppose you’re finding yourself in a grocery store with a cart full of food, drinks and other stuff. You come at the cash register where the lady kindly says “Can you put everything back on the shelves please? There are some issues with the cash register software and we are instructed to stop scanning items and serve customers until these issues are fixed. Can you come back tomorrow please?”. Uhm, no! How much money do you think this is going to cost compared to the system that makes use of stabilization points? An end-user that is able to keep doing its work, whether the entire production system is down or not has tremendous business value. </p>  <p>I’m not saying that message queues are a silver bullet. I’m just using these as an example. As always, there is a time and place for using them. There are other things a developer can incorporate in order to increase the stability of the system he’s working on, like <a href="http://davybrion.com/blog/2008/05/the-circuit-breaker/" target="_blank">the circuit breaker pattern</a>. I’m also not saying that every system should be built using every stabilization point one can think of. This become a business decision depending on the kind of solution. As usual, it depends.</p>  <p>But the point that I’m trying to make here is that we should stop putting software systems into production and just hoping for the best. That’s just wishful thinking. Software systems are going to behave badly and at some point they will go down. It’s just a matter of when this is going to happen and how much damage this is going to make.</p>  <p>The first step to take is awareness. I encourage you to pick up this book titled ‘<a href="http://www.amazon.com/exec/obidos/ASIN/0978739213/elegantcode-20" target="_blank">Release It!</a>’, written by <a href="http://www.michaelnygard.com/" target="_blank">Michael Nygard</a>. This book is all about designing software that can survive this though environment called production. I can only hope that Stan picks up a copy as well along with some common sense.</p>  <p>Till next time.&#160;&#160;&#160; </p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Could sealing a class be a sign of a good design</title>
		<link>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=could-sealing-a-class-be-a-sign-of-a-good-design</link>
		<comments>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:50:15 +0000</pubDate>
		<dc:creator>Andreas Håkansson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/</guid>
		<description><![CDATA[I recently attended this years Øredev conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, Philip Laureano. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended this years <a title="Read more about the Øredev conference" href="http://oredev.com/2010" target="_blank">Øredev</a> conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, <a title="Visit the twitter profile of Philip Laureano" href="http://twitter.com/philiplaureano" target="_blank">Philip Laureano</a>. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do not know the full details of his exact opinions). Anyway, the short version is that the person suggested that classes should be sealed by default, or at least have the developer explicitly state if the class should be sealed or closed.</p>  <p>My immediate reaction was that this was a terrible idea and that I had been struck down too many times by sealed classes before. But then I started thinking that maybe it was not such a bad idea after all. Maybe it even was a sign of a well designed class and that more developers would be better of by sealing their classes.</p>  <p>Now let me inform you that I am still on the ropes about this, but I would like your thoughts on it. In fact I am hoping that the most interesting part of this post will end up being the discussion in the comment section.</p>  <p>So when you take a moment to think about the <em>S.O.L.I.D principles</em>, most specifically the <em>Open-Closed Principle</em> and <em>Dependency Inversion Principle</em>, a long with the old design principle of ‘Favor <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> over <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)">class inheritance</a>’ then maybe it is not such a bad thing after all. Throw in interfaces into the mix and program to an interface and not an implementation, and it will enables you to create different branches if needed. If your classes can flourish while being sealed, chances are that you have some pretty nice structures code in your hands.</p>  <p>There probably are some legit reasons to not seal classes at time, despite the reasoning above, so I am not going to be definitive and say that is never the case. Voice your thoughts in the comments and let us see where this ends up – who knows, I might be left standing as a fool!</p>  <p>As always, you can find me on twitter by the name of <a title="Visit me on twitter" href="http://twitter.com/thecodejunkie" target="_blank">@thecodejunkie</a></p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
		<comments>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 22:40:49 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/</guid>
		<description><![CDATA[Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended? I was working on building an automated testing framework for a welfare system in which cases could be added [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended?</p>  <p>I was working on building an automated testing framework for a welfare system in which cases could be added and benefits run for a given month.</p>  <p>A typical scenario might be something like:</p>  <ol>   <li>Create a new case for this month. </li>    <li>Add some people, do some things. </li>    <li>Run benefits for this month. </li>    <li>Run benefits for the next month.&#160; Something should happen because the child on the case is now 19. </li> </ol>  <p>Seems pretty straightforward until you consider what happens if someone hard codes dates into the test.</p>  <p>I am sure you can imagine plenty of scenarios in a situation like this where hard coded dates would eventually cause all kinds of problems.</p>  <p>The problem is… </p>  <p><strong>If you create an API which takes in various dates, how do you ensure the dates passed in are calculated and not just hard coded?</strong></p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pigsinblanket" border="0" alt="pigsinblanket" src="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket_thumb.jpg" width="514" height="514" /></a> </p>  <h2>Why convention doesn’t work</h2>  <p>Your first response might be to create some documentation that describes the importance of making dates “float” forward with time, and not be hard coded.</p>  <p>You might clearly describe how you should not hard code July 7th 1990 to be the birth date of a 20 year old for a test case.</p>  <p>You might give some guidelines of how to properly calculate ages.</p>  <p>But, you have no way of making sure the users of your API will follow those conventions or even read your document.</p>  <p>What if we do the hard work for them?</p>  <h2>Why utilities are still not good enough</h2>  <p>The next idea you might have is to create utilities that would do date conversions and calculate ages for the user of your API, so that they just have to remember to use them and all will be good.</p>  <p>This solution is better than one relying purely on convention, but still has some major flaws.&#160; Part of the problem of utility methods is that they are not self-discoverable.&#160; I’ve <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">talked about before</a> how DateUtilities like classes can get overlooked if you don’t know the utility class is there.</p>  <p>If you are relying on your users to go out and find your utility methods to make life easier for them, you are putting a large amount of responsibility in the wrong place.&#160; In my experience, it is very unlikely that anyone but yourself will actually use the utility methods.</p>  <p>You really need a way to stop them from being able to hard code dates.</p>  <h2>How can you stop someone from hard coding dates?</h2>  <p>Don’t accept dates in your API.</p>  <p>It is simple.</p>  <p>What?&#160; What do you mean?&#160; You can’t just stop accepting dates, you need dates.&#160; Not just dates, but integers, or strings.&#160; You can’t just not accept the bad data… or can you?</p>  <p>Consider wrapping the data type in another data type which creates your desired data type, but only using the convention or rules you desire.</p>  <p>Let me show you an example with the dates:</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(DateTime applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>    DoSomethingWithTheDate(applicationDate);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(<span style="color: #0000ff">new</span> DateTime(1990, 7, 8));</pre>
<!--CRLF--></div>
</div>

<p></p>

<p>In the above example, you can see that I am directly taking a .NET DateTime object.&#160; You can also see that I am directly hard coding a date when calling this method.</p>

<p>Let’s see if we can fix that.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(CaseDate applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     DoSomethingWithTheDate(CaseDate.ToDateTime());</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(CaseDate.YearsAgo(20));</pre>
<!--CRLF--></div>
</div>

<p></p>

<h2>What happened?</h2>

<p>Here is what we did:</p>

<ol>
  <li>We created a custom type called CaseDate. </li>

  <li>We replaced all the external usages of DateTime with CaseDate. </li>

  <li>We provided methods on CaseDate which allow the creation of dates, only through the way we want to allow them to be created. </li>
</ol>

<ol>Now we can easily prevent users of the API from being able to create hard coded dates.&#160; The API only will take CaseDate objects and internally creates DateTime objects from the CaseDate objects.</ol>

<ol>We can add other methods to CaseDate to allow the creation of dates from x number of months ago or in the future, or any other valid creation method we want.</ol>

<p>By doing this, we are restricting the valid set of inputs to our methods at compile time, not throwing exceptions at run time.</p>

<p>We are achieving the same kind of valuable input constrictions that we have been able to <a href="http://elegantcode.com/2010/05/08/the-power-of-enum/">achieve with enumerations</a>, except we are adding more complex restrictions than a simple list of selections.</p>

<h2>Where can I use this?</h2>

<p>Not just dates.&#160; There are many places where restricting the input to your method or API is going to simplify logic, protect against error conditions, and enforce constraints.</p>

<p>Consider using this pattern in some of these scenarios:</p>

<ul>
  <li>You want to use an enumeration, but your list of possible choices is too large, or repetitive. </li>

  <li>Anywhere you are using a primitive type and that primitive type represents some more complex concept. </li>

  <li>Anywhere you have parameter validation or manipulation repeated in multiple methods. </li>

  <li>Anytime you process some input or repeat a series of steps to transform it before sending it as input. </li>
</ul>

<p>Every time you are about to make a primitive type a parameter to a method you should ask yourself if it makes sense to wrap the primitive type into an class.</p>

<p>Remember, especially when creating an API, any time your method takes a primitive type, you lose the ability to constrain that input, and are forced to validate it instead.</p>

<p>Should you always wrap all primitive types?&#160; No, but it is another tool you can use to provide an extra layer of indirection between the logic of your API and your callers use of it.</p>

<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Prefer Additional Methods Over Additional Overloads</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
		<comments>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 17:35:54 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/</guid>
		<description><![CDATA[If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do. Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do.</p>  <p>Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are conscious of making that code as readable and terse as possible.</p>  <p><strong>Seldom do we think about the use of our code from an API standpoint.</strong></p>  <p>There is a subtle difference between designing your code in a way that will make it easier for someone else to maintain, and designing your code in a way that will make it easier for someone else to use.</p>  <h2>Intellisenselessness</h2>  <p>How often are you working against some API and you type a method name you want to use only to have intellisense present you with 5 overloads for the method all with several different parameters choices?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginOverloads" border="0" alt="LoginOverloads" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads_thumb.png" width="600" height="151" /></a> </p>  <p>Which one do you use?&#160; It is hard to be sure, you end up having to read through the long lists of parameters to figure out what method you should call and what parameters you should pass it.</p>  <p>Wouldn’t it be better if you were presented with what the method does in the method name rather than guessing what it does in the parameter list?&#160; Something like this?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginMoreMethods" border="0" alt="LoginMoreMethods" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods_thumb.png" width="596" height="261" /></a> </p>  <h2>Perspective</h2>  <p>From the perspective of the person writing the <em>Login</em> method(s), overloads probably seem like the most efficient and correct way to implement the multiple ways the method can be called.</p>  <p>From the perspective of the person using the <em>Login</em> method(s), additional methods are much preferred, because they are easier to understand and know what you are looking for.</p>  <p><strong>Try to think from the perspective of someone using your code when writing your code.</strong></p>  <h2>Extract boolean parameter to two methods</h2>  <p>I want to take a look at a very specific example that can be of great benefit to the readability and use of your code.</p>  <p>Take a look at this code below.</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login(<span style="color: #0000ff">bool</span> rememberMe)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>
Seems like a fine overload of a <em>Login</em> method.&#160; I have written code just like this, you probably have also.&#160; <br />

<p>&#160;</p>

<p>Unfortunately, by adding this overload, we have added some complexity to our API, because now the user of that code has to see that there is an additional overload that take a bool parameter called <em>rememberMe</em>.</p>

<p>Consider this longer alternative.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginDoNotRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Instead of overloading <em>Login</em> and making the user have to decide which overload to call and pass in a parameter, we have elected to create two differently named methods which take 0 parameters and clearly state what they are going to do.</p>

<p>I’m not saying you should never write overloads, but anytime you see an overload in your code base, you should stop and think if it would be more clear to make that overloaded method into two different methods that can eliminate one or more of the parameters.</p>

<p><strong>Any time you are restricting the number of choices someone using your code has to make, you are making that code simpler to use.</strong></p>

<p>If you don’t believe me, consider why the iPhone has only one button.</p>

<h5><strong>As always, you can subscribe to this </strong><a href="http://feeds2.feedburner.com/ElegantCode"><strong>RSS feed</strong></a><strong> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at </strong><a href="http://simpleprogrammer.com"><strong>http://simpleprogrammer.com</strong></a><strong>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Say &#8220;No&#8221; to &#8220;Null&#8221;</title>
		<link>http://elegantcode.com/2010/05/01/say-no-to-null/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=say-no-to-null</link>
		<comments>http://elegantcode.com/2010/05/01/say-no-to-null/#comments</comments>
		<pubDate>Sat, 01 May 2010 19:35:05 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/05/01/say-no-to-null/</guid>
		<description><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after. What do you do if "null” [...]]]></description>
			<content:encoded><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after.
<blockquote>What do you do if "null” is passed in?</blockquote>
My answer may turn out to be a bit of a surprise.
<blockquote><span style="background-color: #f4f5f7;">Nothing, I don’t handle nulls in code that I control the use of.</span></blockquote>
“What?  What?” you say.  “You don’t handle null?  What kind of heresy is that?”  It is the kind of heresy that helps produce elegant code and I will show you why.
<h2>How well do you handle null right now?</h2>
Would you say that in most of the code you write you properly check all arguments for null?

Or, do you like most developers, handle null in certain cases when you happen to think about it, or after the application dumps a “null pointer exception” stack trace?

Be honest, look at your code if you have to.

The problem is “d00d ur d0ing it r0ng!”

<a href="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="john-mccarthy-programming-completely-wrong" src="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong_thumb.jpg" border="0" alt="john-mccarthy-programming-completely-wrong" width="349" height="452" /></a>

Unless you are some kind of anal retentive perfectionist, you are probably not handling null in every single method call.  That means there are huge potential bugs in the code that you are writing which will throw null pointer exceptions.  That is bad, I agree.

So, if you are not handling it correctly right now, then what can you do to fix that?
<h2>Avoiding null in the code you “own”</h2>
You can’t control external libraries.  And you can’t control how people will use your code, but you can control the code you write and you can, to a degree, control the code your shop writes.

The better strategy is to never pass null in the first place.

You can either focus your efforts on:
<ul>
	<li>Checking for null</li>
	<li>Not ever passing null</li>
</ul>
<ul>The more elegant solution is to focus on never passing null.  By doing this you will end up writing less code and avoid decisions about how to handle null inside of a method that doesn’t have enough context to decide what to do.</ul>
Let’s look at an example:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> TransmographyThreeStrings(<span class="kwrd">string</span> first, <span class="kwrd">string</span> second, <span class="kwrd">string</span> third)
{
     <span class="kwrd">if</span>(<span class="kwrd">string</span>.isNull(first) || <span class="kwrd">string</span>.isNull(second) || <span class="kwrd">string</span>.isNull(third))
    {
           <span class="rem">// hmm, I donno, what should I do?  Should I throw an exception?</span>
           <span class="rem">// should I return an empty string?</span>
           <span class="rem">// what if the first string wasn't null, can we still do something meaningful?</span>
           <span class="rem">// how will the caller of the method know what I will do?</span>
    }

}</pre>
You can see there that we are checking each parameter for null.  The problem is we don’t know what we should do.  We have lots of options, but none of them are obvious.

How much better is it to make sure that we never pass null into methods, rather than write this kind of code in every method?
<h2>What about accidentally passing in null?</h2>
Many of you are probably thinking at this point that the main way null gets passed into a method is because someone calls a method without knowing that it contains a null value.
<pre class="csharpcode">TransmographyThreeStrings(<span class="str">"Hello"</span>, <span class="str">"World"</span>, mysteryObject.Text);</pre>
Perhaps <em>mysteryObject.Text </em>is null.  You wouldn’t even know it.

Ah, but you can.  Or you can prevent it at least.  Somewhere <em>mysteryObject </em>gets created.  When it gets created its values either get initialized or not.  You can prevent any of its values from being null, several ways:
<ul>
	<li>Always initialize variables when they are declared.</li>
	<li>Use a <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> to ensure that objects are always fully constructed before being created.</li>
	<li>Use properties to provide default values or lazy initialize.</li>
	<li>Make your objects <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> as much as possible.</li>
</ul>
The practices that prevent null from accidentally being passed in make your code much more elegant than repeating <em>if blah == null</em> code all over the place.

<strong>In general, you should always strive to eliminate the passing of null rather than checking for null.  By doing so you reduce extra lines of code in each method, and are forced to use better design practices.</strong>
<h2>Exceptions</h2>
Yes, there are times when you need to check for null.  If you are writing a library that external developers will use, then you will probably want to check for null in all of your methods that are exposed as part of the API.  (On your internal methods, you don’t need to since you have already cleansed the input.)

Also, if your code is being used as a callback to some API and you don’t know if it can ever pass null into your code, you probably should check for null.

A bad excuse is that other developers may pass null to your method. <strong>It is much better as a software shop to put the onus of not passing null on the caller of any method rather than putting it on the writer of the method being called.</strong>

You will also reduce your exception handling code, because you will have less exceptions for invalid parameters.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/05/01/say-no-to-null/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>If Self-Documenting Code is the What, Unit Tests are the Why</title>
		<link>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-self-documenting-code-is-the-what-unit-tests-are-the-why</link>
		<comments>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:09:04 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/</guid>
		<description><![CDATA[It is not enough to just write code that is clean and self-documenting.  Eliminating comments and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it. If you recall from my original post on [...]]]></description>
			<content:encoded><![CDATA[It is not enough to just write code that is clean and self-documenting.  <a href="http://elegantcode.com/2010/04/18/eliminating-comments-the-road-to-clarity/">Eliminating comments</a> and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it.

If you recall from my <a href="http://elegantcode.com/2010/04/09/what-does-elegant-code-mean-to-me/">original post</a> on Elegant code, I stated that elegant code is:
<blockquote>Something that is simple yet effective, delivered with grace.</blockquote>
By writing self-documenting code we are hopefully able to achieve some of the aspects of simplicity and grace, but it tells us nothing about the effectiveness of the code.
<h2>Bringing the dead to life</h2>
<a href="http://elegantcode.com/wp-content/uploads/2010/04/zombies.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="zombies" src="http://elegantcode.com/wp-content/uploads/2010/04/zombies_thumb.jpg" border="0" alt="zombies" width="441" height="295" /></a>

Throwing out comments is a debatable topic.  <a href="http://www.reddit.com/r/programming/comments/bsutx/">It raises quite a bit of controversy</a>, as you can see from some of the comments on my post about the subject.  The reason, perhaps, that so many people are so staunchly opposed to the idea, is because they are worried, and rightly so, that throwing out comments will reduce the documentation of what the code is doing.

Think about that for a second.  Is documentation of what the code is doing important?  It better be.  What we are trying to accomplish by writing self-documenting code instead of comments, is to take the vessel, which is the code itself, and make that same vessel be the documentation of what the code does.  It is by doing this that we creating a living representation of the functionality of the code.  Comments are akin to a dead representation of the functionality of the code because they do not change automatically with the code.

I diverge to talk about comments so that I can draw a parallel to another form of documentation which is valuable and should be considered necessary.  That other set of documentation is requirements.  Have you ever written requirements documents?  Have you ever captured requirements from the customer and put them into UML diagrams, or perhaps plopped them into some templated Word document, which is never updated again, and no one reads, because no one trusts it is correct?  Wouldn’t it be great if we would replace that dead document or set of documents, with a living one?

The good news is we can, and some of us have.  And I fully expect this recommendation will be just as controversial, because <strong>I am suggesting that we don’t have to write low level specifications of the system at all, instead we can write good unit tests. </strong>When we do this, we are taking a dead form of document and bringing it to life.
<h2>Unit tests tell us why and how our code is effective</h2>
If
<pre class="csharpcode">i = 5;  // Widget count defaults to five.</pre>
is replaced with
<pre class="csharpcode">widgetCount = DEFAULT_WIDGET_COUNT;</pre>
<!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

then
<blockquote><span style="background-color: #ffffff;">1.1.5 When a new widget is created, the widget count should be increased by one.</span></blockquote>
is replaced with
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> When_NewWidgetIsCreated_Then_WidgetCountIsIncreasedByOne()
{
     WidgetFactory.Count = 3;
     WidgetFactory.CreateNew();
     assertEquals(4, WidgetFactory.Count);
}</pre>
The unit test is replacing the low level requirement, which is somewhat open to interpretation and untied to the code, with an absolute and completely tied-to-the-code, specific requirement.

The unit test is telling us why our code is built the way it is.  It is telling us what requirement that particular structure of code is trying to address.  <strong>It is telling us what end result that code is trying to accomplish and what the expectations are on the results of a given condition.</strong>

The unit test is telling us how the code is to be used in order to achieve its result.  It is serving as a living reference to the syntax and use of the code we built.  <strong>Instead of providing instructions on how to use our API, we are providing a living example, and proof that it will indeed work.</strong> Examples are often much more effective than instructions anyway.
<h2>What exactly are we replacing?</h2>
At this point we are not trying to replace all the documentation of the system (at this point).

With self-documenting code, we sought to eliminate comments, and replace them with good variable and method names.

With unit tests, we seek to eliminate technical documentation and requirements of the system, that is targeted at a developer or technical audience.

We are NOT trying to eliminate high level specifications of the system, or use cases. <strong>Unit tests DO NOT replace that kind of documentation! </strong>We will talk about replacing that kind of documentation when we talk about automated functional or system tests.

Simply put, any kind of documentation that you would give to a developer so they understand how the system works and how to use the code or APIs, can be easily replaced by writing good unit tests.

Our simple goal is to replace the “dead” documentation (meaning that it does not update automatically with the thing it is documenting), with “living” documentation in the form of unit tests.

One last point.  I want to be clear that I am not saying that having unit tests automatically results in the ability to replace technical documentation.  Just like having long-named methods and variables doesn’t automatically replace the need for comments.  It is a matter of the quality of the unit tests that are written, just as it is a matter of the quality of the self-documenting code.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>REST: Resources, URI&#8217;s and Representations</title>
		<link>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rest-resources-uris-and-representations</link>
		<comments>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 04:00:13 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/</guid>
		<description><![CDATA[In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions. Resources Resources are at the heart of REST.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions.</p>  <h3>Resources</h3>  <p>Resources are at the heart of REST.&#160; You are already used to resources as a web browsing consumer.&#160; A resource is not something specific to REST, instead it is the first thing you probably want to consider when architecting a RESTful application.&#160; A resource is simply the entity, item, or thing you want to expose.</p>  <p>Perhaps you have approached application architecture using one or many of several modeling and design techniques.&#160; Data First practitioners typically begin with databases and data models.&#160; DDD proponents like to begin by modeling around business entities and interactions, while their cousins in the BDD camp model around business activities.</p>  <p>When you decide to apply REST you will need to think a lot more about data entities and domain objects as resources.&#160; Your existing models may or may not closely map to resources.&#160; The shift in thinking may appear slight, but is very important.&#160; It centers around making things&#160; addressable.&#160; Each resources must by uniquely identifiable as we will see in the next section.&#160; We are used to identity with most data entities, but our domain objects may not always be as easily identifiable.&#160; Likewise, our data entites may have identity, but not map to a resource.&#160; </p>  <p>Consider the classic customer and order scenario for example.&#160; If each customer and each order can be identified then it will be easy to design RESTful systems around them.&#160; However, if the model requires a lot of context then our challenge is a little bit larger.&#160; Perhaps we must first identify a partner, then a year, then a customer, and finally the order.&#160; Yes, that is a design smell in general.&#160; It makes fetching an order very difficult.&#160; Developing RESTfuly would only further expose that difficulty.&#160; Identifying your resources up front will help you reduce the possible impedance mismatches you might end up with between what you want to expose and your data or domain models.</p>  <p>REST is about interacting with Resources!</p>  <h3>URI’s</h3>  <p>REST defines the identity of a resource via URI.&#160; Each resources has a unique address in URL form (ie. using the http protocol).&#160; Interaction with a resource will take place at its URI.&#160; As an example, my twitter status feed resource URI is <a title="http://twitter.com/optionstrict" href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; That URI is unique to my feed and that is what you expect to find at that URI.&#160; In the Twitter databases or domain models my account may be referred to by the string optionstrict, or perhaps as some random number or guid.</p>  <p>To consume my status history via a service interface twitter provides another URI at <a title="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict" href="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict">http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict</a>.&#160; I would actually prefer to have access at the same URI for html, json, and xml formats.&#160; Twitter probably has its reasons for distinguishing API access from HTML rendering, but they have actually complicated their architecture by doing so.&#160; When designing the URI’s for your resources, make them easy for your users to work with.&#160; </p>  <h3>Representation</h3>  <p>Lets continue with the twitter example to describe what is meant by Representation.&#160; Given a URI and a Resource, what will your consumers receive when they issue a GET request to the URI?&#160; Twitter chose a representation of my account and included status history and profile for the response at <a href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; They decided to put a representation of my profile photo at <a title="http://twitter.com/account/profile_image/optionstrict" href="http://twitter.com/account/profile_image/optionstrict">http://twitter.com/account/profile_image/optionstrict</a>.&#160; In your REST solutions you will need to consider how you want to represent a resource at its URI.&#160; Each representation will have a unique URI.&#160; </p>  <p>Representations are also important for manipulating resources.&#160; You must define the representation required to create and update resources.&#160; Twitter status updates require a text representation with a maximum of 140 characters.&#160; They allow additional values in the status representation, such as latitude and longitude.&#160; Your REST solutions similarly must define representations for Requests and Responses.</p>  <p>I hope that this short introduction has helped you to see that the core essence of REST is simple and fairly obvious.&#160; As you look at your current solutions what are the resources you are exposing?&#160; Could you make those resources identifiable by URI?&#160; What representation would you place at each URI?&#160; What representation would you require for manipulating a given resource?</p>  <p>Also, notice I did not mention much about data formats, Content Type, Mime, etc.&#160; Those details can cloud your design if you try to start with them. If you can’t wait for my post about how REST handles html, json, xml from the same URI, then start googling Content Negotiation, Accept header, and Content-Type header.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Driven Architecture: Publishing Events using an IOC container</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
		<comments>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 17:35:54 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/</guid>
		<description><![CDATA[If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do. Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do.</p>  <p>Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are conscious of making that code as readable and terse as possible.</p>  <p><strong>Seldom do we think about the use of our code from an API standpoint.</strong></p>  <p>There is a subtle difference between designing your code in a way that will make it easier for someone else to maintain, and designing your code in a way that will make it easier for someone else to use.</p>  <h2>Intellisenselessness</h2>  <p>How often are you working against some API and you type a method name you want to use only to have intellisense present you with 5 overloads for the method all with several different parameters choices?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginOverloads" border="0" alt="LoginOverloads" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads_thumb.png" width="600" height="151" /></a> </p>  <p>Which one do you use?&#160; It is hard to be sure, you end up having to read through the long lists of parameters to figure out what method you should call and what parameters you should pass it.</p>  <p>Wouldn’t it be better if you were presented with what the method does in the method name rather than guessing what it does in the parameter list?&#160; Something like this?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginMoreMethods" border="0" alt="LoginMoreMethods" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods_thumb.png" width="596" height="261" /></a> </p>  <h2>Perspective</h2>  <p>From the perspective of the person writing the <em>Login</em> method(s), overloads probably seem like the most efficient and correct way to implement the multiple ways the method can be called.</p>  <p>From the perspective of the person using the <em>Login</em> method(s), additional methods are much preferred, because they are easier to understand and know what you are looking for.</p>  <p><strong>Try to think from the perspective of someone using your code when writing your code.</strong></p>  <h2>Extract boolean parameter to two methods</h2>  <p>I want to take a look at a very specific example that can be of great benefit to the readability and use of your code.</p>  <p>Take a look at this code below.</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login(<span style="color: #0000ff">bool</span> rememberMe)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>
Seems like a fine overload of a <em>Login</em> method.&#160; I have written code just like this, you probably have also.&#160; <br />

<p>&#160;</p>

<p>Unfortunately, by adding this overload, we have added some complexity to our API, because now the user of that code has to see that there is an additional overload that take a bool parameter called <em>rememberMe</em>.</p>

<p>Consider this longer alternative.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginDoNotRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Instead of overloading <em>Login</em> and making the user have to decide which overload to call and pass in a parameter, we have elected to create two differently named methods which take 0 parameters and clearly state what they are going to do.</p>

<p>I’m not saying you should never write overloads, but anytime you see an overload in your code base, you should stop and think if it would be more clear to make that overloaded method into two different methods that can eliminate one or more of the parameters.</p>

<p><strong>Any time you are restricting the number of choices someone using your code has to make, you are making that code simpler to use.</strong></p>

<p>If you don’t believe me, consider why the iPhone has only one button.</p>

<h5><strong>As always, you can subscribe to this </strong><a href="http://feeds2.feedburner.com/ElegantCode"><strong>RSS feed</strong></a><strong> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at </strong><a href="http://simpleprogrammer.com"><strong>http://simpleprogrammer.com</strong></a><strong>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Elegant Code &#187; Architecture</title>
	<atom:link href="http://elegantcode.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quinine For Sale</title>
		<link>http://elegantcode.com/2012/01/18/monitoring-an-mmo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-an-mmo</link>
		<comments>http://elegantcode.com/2012/01/18/monitoring-an-mmo/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:45:32 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MMO]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2012/01/18/monitoring-an-mmo/</guid>
		<description><![CDATA[I’ve been working on a free-to-play MMO Quinine For Sale, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I’ve been working on a free-to-play <a href="http://www.heroup.com" target="_blank">MMO</a> <b>Quinine For Sale</b>, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before they become serious and fixing problems when they inevitably do.&#160; So, there are two questions.&#160; “Is there a problem in the game?” “What is causing the problem?”&#160; </p>  <p>When trying to debug something on our development and test clusters, typically you can tail log files.&#160; We have a python script that can monitor the communication between various parts of the game and pretty-print it along with color to highlight “this is a problem!”&#160; Attaching a debugger to a running process is also not uncommon.&#160; However, looking at logs and bus traffic in realtime on a production environment gives you this neat “Matrix-y” experience.&#160; Attaching a debugger to a production process (assuming you could, which you can’t) would get you smacked with a rolled-up newspaper.&#160; “Bad Developer!&#160; No treat!”&#160; So, what can you do?</p>  <h4>Monitoring</h4>  <p>When you’ve got clusters full of machines, using <a href="http://www.nagios.org/" target="_blank">Nagios</a> to monitor things is an obvious solution.&#160; Beyond making sure the power is on and other sysadmin things, we’ve written other checks to see if the login process is working, the parts are working together, and automating typical in-game functions.&#160; For example, if nagios can’t successfully log into the game do basic game activity, then alerts happen.</p>  <h4>Metrics for EVERYTHING</h4>  <p>Anything that happens in game has metrics reporting tied to it, generating piles of data constantly.&#160; We use <a href="http://www.cacti.net/" target="_blank">Cacti</a> to visualize game activity.&#160; An example metric is concurrent users, or CCU.&#160; We graph how many people are in the game over time, which when things are healthy should be a nice smooth curve climbing to peak game hours, then descending nicely through the night.</p>  <p>We can tell by sight if the game looks healthy or not – if the CCU graph is jaggy, has a sudden drop or spike, or drops to zero then we know that something is wrong.&#160; Typically nagios alerts accompany the graphs, giving more data points on where to look.&#160; But this has also pointed out areas where a nagios check was missing or wasn’t working as intended.</p>  <h4>Log Files</h4>  <p>When a player gets an error in game, the error dialog box gives them the opportunity to submit the error details back to us.&#160; If we see a spike in user-reported errors through this or other customer service means, we know we have something of interest to look for.&#160; </p>  <p>The game server components make use of log4j and similar logging frameworks.&#160; Anything that you’d want to watch happening in game needs to be aggressively logged.&#160; All components are configured so that operations can change the log level on the fly.&#160; That’s still quite a bit of data across many machines though, so all that information is run through <a href="http://www.splunk.com/product" target="_blank">Splunk</a> to be indexed and searchable.&#160; This gives us a great tool for searching through log data, examining trends, or watching selected activity in real time.&#160; Unfortunately it is very expensive so we are selective about the data that passes through it.&#160; </p>.  Buy Quinine from mexico.  Buy Quinine no prescription.  No prescription Quinine online.  Online buying Quinine.  Quinine no prescription.  Quinine street price.  Buy no prescription Quinine online.  Quinine coupon.  Quinine over the counter.  Where can i buy Quinine online.  Quinine steet value.  Where to buy Quinine.  Order Quinine online overnight delivery no prescription.  Quinine recreational.  Quinine canada, mexico, india.  Ordering Quinine online.  Quinine without prescription.  Quinine price, coupon.  Quinine description.  Order Quinine from mexican pharmacy.  Quinine pics.  What is Quinine.  Japan, craiglist, ebay, overseas, paypal.  Order Quinine from United States pharmacy.  Order Quinine online c.o.d.  Quinine trusted pharmacy reviews.  Quinine treatment.  Buy Quinine from canada.  Quinine used for.  Discount Quinine.  Is Quinine addictive.  Quinine forum.  Buy Quinine online no prescription.  Is Quinine safe.  Purchase Quinine for sale.  Effects of Quinine.  Buy Quinine online cod.  Quinine australia, uk, us, usa.  Buy Quinine without prescription.  Quinine online cod.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4721'>Buy Flonase Without Prescription</a>. <a href='http://elegantcode.com/?p=4234'>Buy Periactin Without Prescription</a>. <a href='http://elegantcode.com/?p=4203'>Buy Armour Without Prescription</a>. <a href='http://elegantcode.com/?p=4899'>Buy Macrobid Without Prescription</a>. <a href='http://elegantcode.com/?p=4534'>Xalatan For Sale</a>. <a href='http://elegantcode.com/?p=4302'>Phenergan wiki</a>. <a href='http://elegantcode.com/?p=4268'>Soma maximum dosage</a>. <a href='http://elegantcode.com/?p=4602'>Zovirax treatment</a>. <a href='http://elegantcode.com/?p=4578'>Cialis price, coupon</a>. <a href='http://elegantcode.com/?p=4189'>Flexeril price</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.leaduganda.org/?p=514'>Quinine For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=4820'>Quinine For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2780'>Quinine For Sale</a>. <a href='http://www.thegriffonnews.com/?p=10177'>Quinine For Sale</a>. <a href='http://www.independentworldreport.com/?p=2409'>Quinine For Sale</a>. <a href='http://changecamp.ca/?p=295'>Quinine description</a>. <a href='http://social-blend.com/?p=624'>Quinine price, coupon</a>. <a href='http://blog.farmland.org/?p=3946'>Online buying Quinine hcl</a>. <a href='http://4realz.net/?p=1595'>Quinine from canada</a>. <a href='http://reversemortgagedaily.com/?p=14535'>Where to buy Quinine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2012/01/18/monitoring-an-mmo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temovate Cream For Sale</title>
		<link>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-software-development-will-never-be-engineering</link>
		<comments>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 03:37:48 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/</guid>
		<description><![CDATA[I always find it rather interesting when academics try to quantify generalized metrics about software development. Temovate Cream For Sale, Things like: per lines of code, there will be X number of bugs. Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.” These are all interesting [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I always find it rather interesting when academics try to quantify generalized metrics about software development.</p>  <p> <b>Temovate Cream For Sale</b>, Things like: per lines of code, there will be X number of bugs.</p>  <p>Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.”</p>  <p>These are all interesting thoughts, but software development will never conform to rigid engineering principles like many other engineering practices.&#160; The longer I work in the field, the more and more I realize that software development has nothing to do with engineering.&#160; We just happen to attend some of the same math classes in school.</p>  <h2>Building bridges</h2>  <p>One of the main arguments I hear people make about the current state of software development as an engineering practice is based around its relative maturity to other engineering fields.</p>  <p>There is a huge problem with this line of thinking.</p>  <p>The argument goes something like this:&#160; “<em>Engineering has been around for hundreds of years and has matured to the point where it is a measurable science, but software development has only been around in earnest for the last few decades or so, therefore it is relatively immature as an engineering discipline.”</em></p>  <p>On the surface this argument seems sounds.&#160; And certainly in 50 years software development will be different than it is now.&#160; Heck, it is much more different than it was just 10 years ago.</p>  <p>But, here is the problem.&#160; We build much more software than we do bridges.</p>  <p><img src="http://www.nps.gov/glca/historyculture/images/Navajo_Bridges_1.gif" width="589" height="442" /></p>  <h6 align="center">&#160;</h6>  <p>Let me give you an example that came to light in another area of my interest… poker.</p>  <h1></h1>  <h2>The poker quickening</h2>  <p>An interesting thing happened in the poker community in the last 10 years; poker pros with decades of experience started getting beat time and time again by 19 year old poker prodigies.</p>  <p>From an outside perspective it looks like the poker world opening up just widened the search for talent and there it was.&#160; But, a closer examination of the evidence leads to the truth.</p>  <p>Before the online poker industry was born, poker was played in card rooms and casinos in states where it was legal and occasionally at small home games throughout the US.</p>  <p>A poker pro might play poker tournaments perhaps 100 times to 150 times a year.&#160; The sum knowledge of the poker community and the meta game around it was based on this base of professional poker players playing tournaments and gaining experience at this mediocre rate.</p>  <p>Once the internet poker rooms started opening up, things changed, and they changed rapidly.&#160; Now anyone could play poker from their home PC.&#160; Not only could they play poker, they could play poker tournaments at all hours of the day.</p>  <p>Here is a list of some of the major changes that took place:</p>  <ul>   <li>Hands are dealt at 60-80 hands per hour instead of 10-30</li>    <li>Players can play in many tournaments at one time, 10 tournaments at once is not unheard of</li>    <li>Players can analyze hand histories and historical data about their play and opponents play through the use of software </li>    <li>Age requirements are out the window, technically any one of any age could be playing online</li>    <li>Players can play 24 hours a day</li>    <li>The professional online tournament player could easily play over 3000 tournaments in a year, while a brick and mortar pro would be lucky to reach 100 in a year.</li>   <img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://t1.gstatic.com/images?q=tbn:ANd9GcRj9uGNWSyqGWEneiH6xaBAyS6COwGYicdNadZu-06KWQLhIi6LMw&amp;t=1" width="316" height="270" /></ul>  <p>&#160;</p>  <p>So where am I going with all this?</p>  <p>The point is that as a whole more hands were dealt and more poker knowledge and experience was obtained in 1 year of online poker than probably the entire history of poker before that.&#160; We reached such an accelerated pace of play that all previous knowledge of poker became obsolete.&#160; </p>  <p>The strategy of tournament poker completely changed.&#160; The game evolved perhaps 500 years into the future in a matter of 5 years time.</p>  <p>The same has happened with software development.</p>  <h2>Back to the bridge building</h2>  <p>So let’s take that poker example and look at it through the lens of software development.</p>  <p>Let us compare the engineering maturity to software development to the engineering maturity of the engineering discipline of building bridges.</p>  <p>I think most people would agree that bridge building is a very mature engineering discipline but many people would argue that software development is not.</p>  <p><strong>How many bridges do you think have been built in the world?</strong></p>  <p>Well there are <a href="http://www.betterroads.com/category/bridge-inventory/erroads.randallreillycms.com/files/2009/11/BR1109_BridgeInventory.pdf">about 600,000 bridges in the United States alone</a>, so the world figure must be at least somewhere around 10 times that number perhaps 20.</p>  <p><strong>How many software programs have been written?</strong></p>  <p>This is a very hard number to estimate, but lets take a rough guess based on <a href="http://stackoverflow.com/questions/453880/how-many-developers-are-there-in-the-world">how many software developers there are in the world</a>.&#160; </p>  <p>If we say there are about 12 million software developers and each software developer has written approximately 3 programs, we can estimate that a large amount more programs have been written than bridges built.</p>  <p>My point is not to knock bridge building, we are pretty good at it as a whole, but rather to show that collectively, even though we have been building bridges for hundreds of years, we have probably devoted an equivalent amount of time to building software.</p>  <p>This line of thinking may lead you to argue back that software development and bridge building are very different.&#160; Bridge building has a fixed set of requirements that are pretty close to the the same for each bridge you build, but software development is a big open void of whims and ambiguously contradictory statements.</p>  <p>I agree with you 100%!&#160; And in essence that is my point.</p>  <h2>Software development is different</h2>  <p>And we have had enough time to realize that.&#160; Waiting for software development to gel into some kind of engineering discipline like other engineering disciplines is like waiting for water without gelatin mix to turn into Jello.&#160; </p>  <p>It’s just not going to happen!</p>  <p>In my mind it is clear that the argument that we haven’t given it enough time is just wishful thinking.&#160; The nature of software development, just like online poker, leads itself to rapid evolution.</p>  <p>Consider what direction software development is evolving.&#160; Is it even evolving in the direction of rigid engineering practices or is it evolving in the exact OPPOSITE direction?</p>  <p>Ten years ago, we tried to use UML diagrams and CASE tools to develop software.&#160; Ten years ago waterfall was all the rage.&#160; Ten years ago, we thought that ten years in the future we would have programs that would allow us to build software in the same way that CAD tools allow for building machine parts.</p>  <p>Not only did it not happen.&#160; It went completely the other way.&#160; Now we are all talking about Agile.&#160; Now people don’t even remember what CASE tools are.&#160; Now we are building software without trying to define the whole system in UML diagrams.</p>  <p><strong>The fact of the matter is software systems are unruly beasts!</strong></p>  <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://aznbadger.files.wordpress.com/2010/06/beast.jpg" /></p>  <p>In my mind it comes down to one simple distinction.&#160; Software is living, bridges aren’t.&#160; When you are done building a bridge, you are done building the bridge.&#160; </p>  <p>Sure someone, probably not you, will have to come along and do some routine maintenance on it.&#160; Sure, some small things might change about it, but for all intents and purposes the work is done.</p>  <p>In most software development scenarios, this is not the case.&#160; In most software development scenarios, releasing V1 is not even close to the end.&#160; Sometimes V1 and V2 don’t even look that same at all.&#160; Software development is about operating on a living breathing thing and all the while keeping it alive.</p>  <p>The truth is, we software developers have more in common with surgeons than with other engineers.</p>  <h6>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com/">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>.  Buy Temovate Cream without a prescription.  Temovate Cream trusted pharmacy reviews.  Temovate Cream over the counter.  Where can i order Temovate Cream without prescription.  Online buy Temovate Cream without a prescription.  Temovate Cream no rx.  Buy cheap Temovate Cream no rx.  Temovate Cream photos.  Buy Temovate Cream online no prescription.  Order Temovate Cream online c.o.d.  Herbal Temovate Cream.  About Temovate Cream.  Australia, uk, us, usa.  Cheap Temovate Cream.  Temovate Cream class.  Temovate Cream brand name.  Online Temovate Cream without a prescription.  Buy Temovate Cream without prescription.  Buy Temovate Cream from canada.  After Temovate Cream.  Order Temovate Cream from mexican pharmacy.  Temovate Cream without a prescription.  Purchase Temovate Cream.  Temovate Cream natural.  Temovate Cream overnight.  Temovate Cream online cod.  Where can i buy cheapest Temovate Cream online.  Purchase Temovate Cream for sale.  Online buying Temovate Cream.  Purchase Temovate Cream online.  Temovate Cream used for.  Temovate Cream coupon.  Temovate Cream description.  Order Temovate Cream no prescription.  Temovate Cream maximum dosage.  Cheap Temovate Cream no rx.  Temovate Cream images.  Temovate Cream blogs.  Buy Temovate Cream online cod.  Buy generic Temovate Cream.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4472'>Bactroban For Sale</a>. <a href='http://elegantcode.com/?p=4632'>Armour For Sale</a>. <a href='http://elegantcode.com/?p=4639'>Buy Estrace Vaginal Cream Without Prescription</a>. <a href='http://elegantcode.com/?p=4668'>Buy Augmentin Without Prescription</a>. <a href='http://elegantcode.com/?p=4535'>Buy Tindamax Without Prescription</a>. <a href='http://elegantcode.com/?p=4931'>Fast shipping Diclofenac</a>. <a href='http://elegantcode.com/?p=4240'>Combivent brand name</a>. <a href='http://elegantcode.com/?p=4417'>Levaquin overnight</a>. <a href='http://elegantcode.com/?p=4597'>Purchase Toradol online</a>. <a href='http://elegantcode.com/?p=4221'>Australia, uk, us, usa</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.quarterlives.com/?p=1148'>Temovate Cream For Sale</a>. <a href='http://4realz.net/?p=1972'>Temovate Cream For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=5997'>Temovate Cream For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2476'>Temovate Cream For Sale</a>. <a href='http://www.thegriffonnews.com/?p=9947'>Temovate Cream For Sale</a>. <a href='http://social-blend.com/?p=1160'>Temovate Cream brand name</a>. <a href='http://blog.farmland.org/?p=3812'>Where can i find Temovate Cream online</a>. <a href='http://reversemortgagedaily.com/?p=14136'>Generic Temovate Cream</a>. <a href='http://linuxologist.com/?p=1792'>Temovate Cream photos</a>. <a href='http://home.officesnapshots.com/?p=114'>Order Temovate Cream from mexican pharmacy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
		<item>
		<title>Christmas Light Architectures Are Not That Shiny</title>
		<link>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=christmas-light-architectures-are-not-that-shiny</link>
		<comments>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:00:00 +0000</pubDate>
		<dc:creator>Jan Van Ryswyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/</guid>
		<description><![CDATA[I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way [...]]]></description>
			<content:encoded><![CDATA[<p>I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way overdue :-).</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb1.png" width="202" height="172" /></a> </p>  <p><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a>What's the major malfunction with those old, classic Christmas lights? We've all experienced it at some point. When one goes out, all the others go out as well. This is due to the fact that these lights are wired in series. The difference compared with today's Christmas lights is that every bulb has a shunt, which basically prevents this kind of failure caused by one or more lamps. Enough about the Christmas lights for now. Where am I going with this? Back in enterprise IT, I'm seeing the same kind of failures as with those classic, old Christmas lights.</p>  <p>The diagram below shows a classic RPC style architecture, much like those classic, old Christmas lights. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb2.png" width="565" height="329" /></a> </p>  <p>This is all fine and dandy as long as every part of the chain runs without too much hassle. But what happens if for some reason the centralized back-end web service goes down (light bulb goes out). This means that every smart client, website and batch application that uses this web service gets affected by this, like some sort of chain reaction. Parts of these client applications will no longer function correctly or they might even go down entirely. Same thing happens when the database of the centralized back-end web service goes down or any other external system that it depends on. When being confronted with this kind of architecture, how would one go about preventing this doomsday scenario to happen?</p>  <p>Suppose you’re a developer that has to work on the centralized back-end web service. This is usually a complex system as it obviously has to provide features for all kinds of applications. When this centralized back-end web service also has to deal with and depend on other external systems that might expose some unexpected behavior, how could one prevent the sky from falling down when things go awry in production?</p>  <p>Well for starters, you could start building in some stabilization points. Suppose for some reason, the centralized web service needs to incorporate some functionality offered by a highly expensive, super enterprise system that for some reason behaves very unstable and unpredictably on every full moon (expensive enterprise software not behaving correctly sounds ridiculous, but bare with me ;-) ). For example, we could use a message queue as a stabilization point. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb3.png" width="570" height="157" /></a> </p>  <p>This means that we put a message on a queue that is processed by some sort of worker process or service that does the actual communication with the misbehaving system. When the external system goes down, the message is either left on the message queue or put on an error queue for later processing when the external system comes back up again. There are some other things you need to think about like idempotent messaging, consistency, message persistence when the server goes down, etc. … . But if one of these dependencies goes down, the centralized back-end web service is still up-and-running which means that the systems that depend on its functionality can also continue to serve their users as they are able to keep doing their work.</p>  <p>Earlier this week I overheard this conversation that somewhat amazed me. I changed the names of the persons involved as well as the exact words used in order to protect the guilty.</p>  <blockquote>   <p><em>George: </em><em>We want to incorporate a message queue in order to guarantee stability and&#160; integrity between several non-transactional systems that our system depends on. It will also improve performance as these systems behave very slow at times and become unstable under pressure. This also gives us the opportunity to root out some major points friction that our end-users are experiencing right now.</em></p>    <p><em>Stan: But this means that the end-users are not completely sure if their actions are indeed fully carried out by the system. </em></p>    <p><em>George: End-users can always check the current state of affairs in their applications. If something goes wrong, their request is not lost and things will get fixed automatically later on as soon as the cause of the error has been fixed. </em></p>    <p><em>Stan:&#160; I don’t think that’s a very good idea. End-users have to wait until everything is processed synchronously, even if that means that they’ll need to wait for a long time. And if one of the external systems goes down, they should stop sending in new requests. Everything should come to a halt. They just have to stop doing what they are doing.</em></p>    <p><em>George: This means that because you lose the original request, some external systems might be set up correctly while others are not. Then someone has to manually fix these issues.</em></p>    <p><em>Stan: Then so be it!</em>&#160;</p> </blockquote>  <p>For starters, I was shocked by this conversation. This is just insane. Everything should come to a halt? Think about this scenario for a while: suppose you’re finding yourself in a grocery store with a cart full of food, drinks and other stuff. You come at the cash register where the lady kindly says “Can you put everything back on the shelves please? There are some issues with the cash register software and we are instructed to stop scanning items and serve customers until these issues are fixed. Can you come back tomorrow please?”. Uhm, no! How much money do you think this is going to cost compared to the system that makes use of stabilization points? An end-user that is able to keep doing its work, whether the entire production system is down or not has tremendous business value. </p>  <p>I’m not saying that message queues are a silver bullet. I’m just using these as an example. As always, there is a time and place for using them. There are other things a developer can incorporate in order to increase the stability of the system he’s working on, like <a href="http://davybrion.com/blog/2008/05/the-circuit-breaker/" target="_blank">the circuit breaker pattern</a>. I’m also not saying that every system should be built using every stabilization point one can think of. This become a business decision depending on the kind of solution. As usual, it depends.</p>  <p>But the point that I’m trying to make here is that we should stop putting software systems into production and just hoping for the best. That’s just wishful thinking. Software systems are going to behave badly and at some point they will go down. It’s just a matter of when this is going to happen and how much damage this is going to make.</p>  <p>The first step to take is awareness. I encourage you to pick up this book titled ‘<a href="http://www.amazon.com/exec/obidos/ASIN/0978739213/elegantcode-20" target="_blank">Release It!</a>’, written by <a href="http://www.michaelnygard.com/" target="_blank">Michael Nygard</a>. This book is all about designing software that can survive this though environment called production. I can only hope that Stan picks up a copy as well along with some common sense.</p>  <p>Till next time.&#160;&#160;&#160; </p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Could sealing a class be a sign of a good design</title>
		<link>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=could-sealing-a-class-be-a-sign-of-a-good-design</link>
		<comments>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:50:15 +0000</pubDate>
		<dc:creator>Andreas Håkansson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/</guid>
		<description><![CDATA[I recently attended this years Øredev conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, Philip Laureano. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended this years <a title="Read more about the Øredev conference" href="http://oredev.com/2010" target="_blank">Øredev</a> conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, <a title="Visit the twitter profile of Philip Laureano" href="http://twitter.com/philiplaureano" target="_blank">Philip Laureano</a>. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do not know the full details of his exact opinions). Anyway, the short version is that the person suggested that classes should be sealed by default, or at least have the developer explicitly state if the class should be sealed or closed.</p>  <p>My immediate reaction was that this was a terrible idea and that I had been struck down too many times by sealed classes before. But then I started thinking that maybe it was not such a bad idea after all. Maybe it even was a sign of a well designed class and that more developers would be better of by sealing their classes.</p>  <p>Now let me inform you that I am still on the ropes about this, but I would like your thoughts on it. In fact I am hoping that the most interesting part of this post will end up being the discussion in the comment section.</p>  <p>So when you take a moment to think about the <em>S.O.L.I.D principles</em>, most specifically the <em>Open-Closed Principle</em> and <em>Dependency Inversion Principle</em>, a long with the old design principle of ‘Favor <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> over <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)">class inheritance</a>’ then maybe it is not such a bad thing after all. Throw in interfaces into the mix and program to an interface and not an implementation, and it will enables you to create different branches if needed. If your classes can flourish while being sealed, chances are that you have some pretty nice structures code in your hands.</p>  <p>There probably are some legit reasons to not seal classes at time, despite the reasoning above, so I am not going to be definitive and say that is never the case. Voice your thoughts in the comments and let us see where this ends up – who knows, I might be left standing as a fool!</p>  <p>As always, you can find me on twitter by the name of <a title="Visit me on twitter" href="http://twitter.com/thecodejunkie" target="_blank">@thecodejunkie</a></p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
		<comments>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 22:40:49 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/</guid>
		<description><![CDATA[Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended? I was working on building an automated testing framework for a welfare system in which cases could be added [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended?</p>  <p>I was working on building an automated testing framework for a welfare system in which cases could be added and benefits run for a given month.</p>  <p>A typical scenario might be something like:</p>  <ol>   <li>Create a new case for this month. </li>    <li>Add some people, do some things. </li>    <li>Run benefits for this month. </li>    <li>Run benefits for the next month.&#160; Something should happen because the child on the case is now 19. </li> </ol>  <p>Seems pretty straightforward until you consider what happens if someone hard codes dates into the test.</p>  <p>I am sure you can imagine plenty of scenarios in a situation like this where hard coded dates would eventually cause all kinds of problems.</p>  <p>The problem is… </p>  <p><strong>If you create an API which takes in various dates, how do you ensure the dates passed in are calculated and not just hard coded?</strong></p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pigsinblanket" border="0" alt="pigsinblanket" src="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket_thumb.jpg" width="514" height="514" /></a> </p>  <h2>Why convention doesn’t work</h2>  <p>Your first response might be to create some documentation that describes the importance of making dates “float” forward with time, and not be hard coded.</p>  <p>You might clearly describe how you should not hard code July 7th 1990 to be the birth date of a 20 year old for a test case.</p>  <p>You might give some guidelines of how to properly calculate ages.</p>  <p>But, you have no way of making sure the users of your API will follow those conventions or even read your document.</p>  <p>What if we do the hard work for them?</p>  <h2>Why utilities are still not good enough</h2>  <p>The next idea you might have is to create utilities that would do date conversions and calculate ages for the user of your API, so that they just have to remember to use them and all will be good.</p>  <p>This solution is better than one relying purely on convention, but still has some major flaws.&#160; Part of the problem of utility methods is that they are not self-discoverable.&#160; I’ve <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">talked about before</a> how DateUtilities like classes can get overlooked if you don’t know the utility class is there.</p>  <p>If you are relying on your users to go out and find your utility methods to make life easier for them, you are putting a large amount of responsibility in the wrong place.&#160; In my experience, it is very unlikely that anyone but yourself will actually use the utility methods.</p>  <p>You really need a way to stop them from being able to hard code dates.</p>  <h2>How can you stop someone from hard coding dates?</h2>  <p>Don’t accept dates in your API.</p>  <p>It is simple.</p>  <p>What?&#160; What do you mean?&#160; You can’t just stop accepting dates, you need dates.&#160; Not just dates, but integers, or strings.&#160; You can’t just not accept the bad data… or can you?</p>  <p>Consider wrapping the data type in another data type which creates your desired data type, but only using the convention or rules you desire.</p>  <p>Let me show you an example with the dates:</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(DateTime applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>    DoSomethingWithTheDate(applicationDate);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(<span style="color: #0000ff">new</span> DateTime(1990, 7, 8));</pre>
<!--CRLF--></div>
</div>

<p></p>

<p>In the above example, you can see that I am directly taking a .NET DateTime object.&#160; You can also see that I am directly hard coding a date when calling this method.</p>

<p>Let’s see if we can fix that.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(CaseDate applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     DoSomethingWithTheDate(CaseDate.ToDateTime());</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(CaseDate.YearsAgo(20));</pre>
<!--CRLF--></div>
</div>

<p></p>

<h2>What happened?</h2>

<p>Here is what we did:</p>

<ol>
  <li>We created a custom type called CaseDate. </li>

  <li>We replaced all the external usages of DateTime with CaseDate. </li>

  <li>We provided methods on CaseDate which allow the creation of dates, only through the way we want to allow them to be created. </li>
</ol>

<ol>Now we can easily prevent users of the API from being able to create hard coded dates.&#160; The API only will take CaseDate objects and internally creates DateTime objects from the CaseDate objects.</ol>

<ol>We can add other methods to CaseDate to allow the creation of dates from x number of months ago or in the future, or any other valid creation method we want.</ol>

<p>By doing this, we are restricting the valid set of inputs to our methods at compile time, not throwing exceptions at run time.</p>

<p>We are achieving the same kind of valuable input constrictions that we have been able to <a href="http://elegantcode.com/2010/05/08/the-power-of-enum/">achieve with enumerations</a>, except we are adding more complex restrictions than a simple list of selections.</p>

<h2>Where can I use this?</h2>

<p>Not just dates.&#160; There are many places where restricting the input to your method or API is going to simplify logic, protect against error conditions, and enforce constraints.</p>

<p>Consider using this pattern in some of these scenarios:</p>

<ul>
  <li>You want to use an enumeration, but your list of possible choices is too large, or repetitive. </li>

  <li>Anywhere you are using a primitive type and that primitive type represents some more complex concept. </li>

  <li>Anywhere you have parameter validation or manipulation repeated in multiple methods. </li>

  <li>Anytime you process some input or repeat a series of steps to transform it before sending it as input. </li>
</ul>

<p>Every time you are about to make a primitive type a parameter to a method you should ask yourself if it makes sense to wrap the primitive type into an class.</p>

<p>Remember, especially when creating an API, any time your method takes a primitive type, you lose the ability to constrain that input, and are forced to validate it instead.</p>

<p>Should you always wrap all primitive types?&#160; No, but it is another tool you can use to provide an extra layer of indirection between the logic of your API and your callers use of it.</p>

<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Prefer Additional Methods Over Additional Overloads</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
		<comments>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 17:35:54 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/</guid>
		<description><![CDATA[If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do. Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do.</p>  <p>Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are conscious of making that code as readable and terse as possible.</p>  <p><strong>Seldom do we think about the use of our code from an API standpoint.</strong></p>  <p>There is a subtle difference between designing your code in a way that will make it easier for someone else to maintain, and designing your code in a way that will make it easier for someone else to use.</p>  <h2>Intellisenselessness</h2>  <p>How often are you working against some API and you type a method name you want to use only to have intellisense present you with 5 overloads for the method all with several different parameters choices?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginOverloads" border="0" alt="LoginOverloads" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads_thumb.png" width="600" height="151" /></a> </p>  <p>Which one do you use?&#160; It is hard to be sure, you end up having to read through the long lists of parameters to figure out what method you should call and what parameters you should pass it.</p>  <p>Wouldn’t it be better if you were presented with what the method does in the method name rather than guessing what it does in the parameter list?&#160; Something like this?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginMoreMethods" border="0" alt="LoginMoreMethods" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods_thumb.png" width="596" height="261" /></a> </p>  <h2>Perspective</h2>  <p>From the perspective of the person writing the <em>Login</em> method(s), overloads probably seem like the most efficient and correct way to implement the multiple ways the method can be called.</p>  <p>From the perspective of the person using the <em>Login</em> method(s), additional methods are much preferred, because they are easier to understand and know what you are looking for.</p>  <p><strong>Try to think from the perspective of someone using your code when writing your code.</strong></p>  <h2>Extract boolean parameter to two methods</h2>  <p>I want to take a look at a very specific example that can be of great benefit to the readability and use of your code.</p>  <p>Take a look at this code below.</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login(<span style="color: #0000ff">bool</span> rememberMe)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>
Seems like a fine overload of a <em>Login</em> method.&#160; I have written code just like this, you probably have also.&#160; <br />

<p>&#160;</p>

<p>Unfortunately, by adding this overload, we have added some complexity to our API, because now the user of that code has to see that there is an additional overload that take a bool parameter called <em>rememberMe</em>.</p>

<p>Consider this longer alternative.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginDoNotRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Instead of overloading <em>Login</em> and making the user have to decide which overload to call and pass in a parameter, we have elected to create two differently named methods which take 0 parameters and clearly state what they are going to do.</p>

<p>I’m not saying you should never write overloads, but anytime you see an overload in your code base, you should stop and think if it would be more clear to make that overloaded method into two different methods that can eliminate one or more of the parameters.</p>

<p><strong>Any time you are restricting the number of choices someone using your code has to make, you are making that code simpler to use.</strong></p>

<p>If you don’t believe me, consider why the iPhone has only one button.</p>

<h5><strong>As always, you can subscribe to this </strong><a href="http://feeds2.feedburner.com/ElegantCode"><strong>RSS feed</strong></a><strong> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at </strong><a href="http://simpleprogrammer.com"><strong>http://simpleprogrammer.com</strong></a><strong>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Say &#8220;No&#8221; to &#8220;Null&#8221;</title>
		<link>http://elegantcode.com/2010/05/01/say-no-to-null/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=say-no-to-null</link>
		<comments>http://elegantcode.com/2010/05/01/say-no-to-null/#comments</comments>
		<pubDate>Sat, 01 May 2010 19:35:05 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/05/01/say-no-to-null/</guid>
		<description><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after. What do you do if "null” [...]]]></description>
			<content:encoded><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after.
<blockquote>What do you do if "null” is passed in?</blockquote>
My answer may turn out to be a bit of a surprise.
<blockquote><span style="background-color: #f4f5f7;">Nothing, I don’t handle nulls in code that I control the use of.</span></blockquote>
“What?  What?” you say.  “You don’t handle null?  What kind of heresy is that?”  It is the kind of heresy that helps produce elegant code and I will show you why.
<h2>How well do you handle null right now?</h2>
Would you say that in most of the code you write you properly check all arguments for null?

Or, do you like most developers, handle null in certain cases when you happen to think about it, or after the application dumps a “null pointer exception” stack trace?

Be honest, look at your code if you have to.

The problem is “d00d ur d0ing it r0ng!”

<a href="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="john-mccarthy-programming-completely-wrong" src="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong_thumb.jpg" border="0" alt="john-mccarthy-programming-completely-wrong" width="349" height="452" /></a>

Unless you are some kind of anal retentive perfectionist, you are probably not handling null in every single method call.  That means there are huge potential bugs in the code that you are writing which will throw null pointer exceptions.  That is bad, I agree.

So, if you are not handling it correctly right now, then what can you do to fix that?
<h2>Avoiding null in the code you “own”</h2>
You can’t control external libraries.  And you can’t control how people will use your code, but you can control the code you write and you can, to a degree, control the code your shop writes.

The better strategy is to never pass null in the first place.

You can either focus your efforts on:
<ul>
	<li>Checking for null</li>
	<li>Not ever passing null</li>
</ul>
<ul>The more elegant solution is to focus on never passing null.  By doing this you will end up writing less code and avoid decisions about how to handle null inside of a method that doesn’t have enough context to decide what to do.</ul>
Let’s look at an example:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> TransmographyThreeStrings(<span class="kwrd">string</span> first, <span class="kwrd">string</span> second, <span class="kwrd">string</span> third)
{
     <span class="kwrd">if</span>(<span class="kwrd">string</span>.isNull(first) || <span class="kwrd">string</span>.isNull(second) || <span class="kwrd">string</span>.isNull(third))
    {
           <span class="rem">// hmm, I donno, what should I do?  Should I throw an exception?</span>
           <span class="rem">// should I return an empty string?</span>
           <span class="rem">// what if the first string wasn't null, can we still do something meaningful?</span>
           <span class="rem">// how will the caller of the method know what I will do?</span>
    }

}</pre>
You can see there that we are checking each parameter for null.  The problem is we don’t know what we should do.  We have lots of options, but none of them are obvious.

How much better is it to make sure that we never pass null into methods, rather than write this kind of code in every method?
<h2>What about accidentally passing in null?</h2>
Many of you are probably thinking at this point that the main way null gets passed into a method is because someone calls a method without knowing that it contains a null value.
<pre class="csharpcode">TransmographyThreeStrings(<span class="str">"Hello"</span>, <span class="str">"World"</span>, mysteryObject.Text);</pre>
Perhaps <em>mysteryObject.Text </em>is null.  You wouldn’t even know it.

Ah, but you can.  Or you can prevent it at least.  Somewhere <em>mysteryObject </em>gets created.  When it gets created its values either get initialized or not.  You can prevent any of its values from being null, several ways:
<ul>
	<li>Always initialize variables when they are declared.</li>
	<li>Use a <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> to ensure that objects are always fully constructed before being created.</li>
	<li>Use properties to provide default values or lazy initialize.</li>
	<li>Make your objects <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> as much as possible.</li>
</ul>
The practices that prevent null from accidentally being passed in make your code much more elegant than repeating <em>if blah == null</em> code all over the place.

<strong>In general, you should always strive to eliminate the passing of null rather than checking for null.  By doing so you reduce extra lines of code in each method, and are forced to use better design practices.</strong>
<h2>Exceptions</h2>
Yes, there are times when you need to check for null.  If you are writing a library that external developers will use, then you will probably want to check for null in all of your methods that are exposed as part of the API.  (On your internal methods, you don’t need to since you have already cleansed the input.)

Also, if your code is being used as a callback to some API and you don’t know if it can ever pass null into your code, you probably should check for null.

A bad excuse is that other developers may pass null to your method. <strong>It is much better as a software shop to put the onus of not passing null on the caller of any method rather than putting it on the writer of the method being called.</strong>

You will also reduce your exception handling code, because you will have less exceptions for invalid parameters.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/05/01/say-no-to-null/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>If Self-Documenting Code is the What, Unit Tests are the Why</title>
		<link>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-self-documenting-code-is-the-what-unit-tests-are-the-why</link>
		<comments>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:09:04 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/</guid>
		<description><![CDATA[It is not enough to just write code that is clean and self-documenting.  Eliminating comments and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it. If you recall from my original post on [...]]]></description>
			<content:encoded><![CDATA[It is not enough to just write code that is clean and self-documenting.  <a href="http://elegantcode.com/2010/04/18/eliminating-comments-the-road-to-clarity/">Eliminating comments</a> and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it.

If you recall from my <a href="http://elegantcode.com/2010/04/09/what-does-elegant-code-mean-to-me/">original post</a> on Elegant code, I stated that elegant code is:
<blockquote>Something that is simple yet effective, delivered with grace.</blockquote>
By writing self-documenting code we are hopefully able to achieve some of the aspects of simplicity and grace, but it tells us nothing about the effectiveness of the code.
<h2>Bringing the dead to life</h2>
<a href="http://elegantcode.com/wp-content/uploads/2010/04/zombies.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="zombies" src="http://elegantcode.com/wp-content/uploads/2010/04/zombies_thumb.jpg" border="0" alt="zombies" width="441" height="295" /></a>

Throwing out comments is a debatable topic.  <a href="http://www.reddit.com/r/programming/comments/bsutx/">It raises quite a bit of controversy</a>, as you can see from some of the comments on my post about the subject.  The reason, perhaps, that so many people are so staunchly opposed to the idea, is because they are worried, and rightly so, that throwing out comments will reduce the documentation of what the code is doing.

Think about that for a second.  Is documentation of what the code is doing important?  It better be.  What we are trying to accomplish by writing self-documenting code instead of comments, is to take the vessel, which is the code itself, and make that same vessel be the documentation of what the code does.  It is by doing this that we creating a living representation of the functionality of the code.  Comments are akin to a dead representation of the functionality of the code because they do not change automatically with the code.

I diverge to talk about comments so that I can draw a parallel to another form of documentation which is valuable and should be considered necessary.  That other set of documentation is requirements.  Have you ever written requirements documents?  Have you ever captured requirements from the customer and put them into UML diagrams, or perhaps plopped them into some templated Word document, which is never updated again, and no one reads, because no one trusts it is correct?  Wouldn’t it be great if we would replace that dead document or set of documents, with a living one?

The good news is we can, and some of us have.  And I fully expect this recommendation will be just as controversial, because <strong>I am suggesting that we don’t have to write low level specifications of the system at all, instead we can write good unit tests. </strong>When we do this, we are taking a dead form of document and bringing it to life.
<h2>Unit tests tell us why and how our code is effective</h2>
If
<pre class="csharpcode">i = 5;  // Widget count defaults to five.</pre>
is replaced with
<pre class="csharpcode">widgetCount = DEFAULT_WIDGET_COUNT;</pre>
<!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

then
<blockquote><span style="background-color: #ffffff;">1.1.5 When a new widget is created, the widget count should be increased by one.</span></blockquote>
is replaced with
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> When_NewWidgetIsCreated_Then_WidgetCountIsIncreasedByOne()
{
     WidgetFactory.Count = 3;
     WidgetFactory.CreateNew();
     assertEquals(4, WidgetFactory.Count);
}</pre>
The unit test is replacing the low level requirement, which is somewhat open to interpretation and untied to the code, with an absolute and completely tied-to-the-code, specific requirement.

The unit test is telling us why our code is built the way it is.  It is telling us what requirement that particular structure of code is trying to address.  <strong>It is telling us what end result that code is trying to accomplish and what the expectations are on the results of a given condition.</strong>

The unit test is telling us how the code is to be used in order to achieve its result.  It is serving as a living reference to the syntax and use of the code we built.  <strong>Instead of providing instructions on how to use our API, we are providing a living example, and proof that it will indeed work.</strong> Examples are often much more effective than instructions anyway.
<h2>What exactly are we replacing?</h2>
At this point we are not trying to replace all the documentation of the system (at this point).

With self-documenting code, we sought to eliminate comments, and replace them with good variable and method names.

With unit tests, we seek to eliminate technical documentation and requirements of the system, that is targeted at a developer or technical audience.

We are NOT trying to eliminate high level specifications of the system, or use cases. <strong>Unit tests DO NOT replace that kind of documentation! </strong>We will talk about replacing that kind of documentation when we talk about automated functional or system tests.

Simply put, any kind of documentation that you would give to a developer so they understand how the system works and how to use the code or APIs, can be easily replaced by writing good unit tests.

Our simple goal is to replace the “dead” documentation (meaning that it does not update automatically with the thing it is documenting), with “living” documentation in the form of unit tests.

One last point.  I want to be clear that I am not saying that having unit tests automatically results in the ability to replace technical documentation.  Just like having long-named methods and variables doesn’t automatically replace the need for comments.  It is a matter of the quality of the unit tests that are written, just as it is a matter of the quality of the self-documenting code.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>REST: Resources, URI&#8217;s and Representations</title>
		<link>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rest-resources-uris-and-representations</link>
		<comments>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 04:00:13 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/</guid>
		<description><![CDATA[In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions. Resources Resources are at the heart of REST.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions.</p>  <h3>Resources</h3>  <p>Resources are at the heart of REST.&#160; You are already used to resources as a web browsing consumer.&#160; A resource is not something specific to REST, instead it is the first thing you probably want to consider when architecting a RESTful application.&#160; A resource is simply the entity, item, or thing you want to expose.</p>  <p>Perhaps you have approached application architecture using one or many of several modeling and design techniques.&#160; Data First practitioners typically begin with databases and data models.&#160; DDD proponents like to begin by modeling around business entities and interactions, while their cousins in the BDD camp model around business activities.</p>  <p>When you decide to apply REST you will need to think a lot more about data entities and domain objects as resources.&#160; Your existing models may or may not closely map to resources.&#160; The shift in thinking may appear slight, but is very important.&#160; It centers around making things&#160; addressable.&#160; Each resources must by uniquely identifiable as we will see in the next section.&#160; We are used to identity with most data entities, but our domain objects may not always be as easily identifiable.&#160; Likewise, our data entites may have identity, but not map to a resource.&#160; </p>  <p>Consider the classic customer and order scenario for example.&#160; If each customer and each order can be identified then it will be easy to design RESTful systems around them.&#160; However, if the model requires a lot of context then our challenge is a little bit larger.&#160; Perhaps we must first identify a partner, then a year, then a customer, and finally the order.&#160; Yes, that is a design smell in general.&#160; It makes fetching an order very difficult.&#160; Developing RESTfuly would only further expose that difficulty.&#160; Identifying your resources up front will help you reduce the possible impedance mismatches you might end up with between what you want to expose and your data or domain models.</p>  <p>REST is about interacting with Resources!</p>  <h3>URI’s</h3>  <p>REST defines the identity of a resource via URI.&#160; Each resources has a unique address in URL form (ie. using the http protocol).&#160; Interaction with a resource will take place at its URI.&#160; As an example, my twitter status feed resource URI is <a title="http://twitter.com/optionstrict" href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; That URI is unique to my feed and that is what you expect to find at that URI.&#160; In the Twitter databases or domain models my account may be referred to by the string optionstrict, or perhaps as some random number or guid.</p>  <p>To consume my status history via a service interface twitter provides another URI at <a title="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict" href="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict">http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict</a>.&#160; I would actually prefer to have access at the same URI for html, json, and xml formats.&#160; Twitter probably has its reasons for distinguishing API access from HTML rendering, but they have actually complicated their architecture by doing so.&#160; When designing the URI’s for your resources, make them easy for your users to work with.&#160; </p>  <h3>Representation</h3>  <p>Lets continue with the twitter example to describe what is meant by Representation.&#160; Given a URI and a Resource, what will your consumers receive when they issue a GET request to the URI?&#160; Twitter chose a representation of my account and included status history and profile for the response at <a href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; They decided to put a representation of my profile photo at <a title="http://twitter.com/account/profile_image/optionstrict" href="http://twitter.com/account/profile_image/optionstrict">http://twitter.com/account/profile_image/optionstrict</a>.&#160; In your REST solutions you will need to consider how you want to represent a resource at its URI.&#160; Each representation will have a unique URI.&#160; </p>  <p>Representations are also important for manipulating resources.&#160; You must define the representation required to create and update resources.&#160; Twitter status updates require a text representation with a maximum of 140 characters.&#160; They allow additional values in the status representation, such as latitude and longitude.&#160; Your REST solutions similarly must define representations for Requests and Responses.</p>  <p>I hope that this short introduction has helped you to see that the core essence of REST is simple and fairly obvious.&#160; As you look at your current solutions what are the resources you are exposing?&#160; Could you make those resources identifiable by URI?&#160; What representation would you place at each URI?&#160; What representation would you require for manipulating a given resource?</p>  <p>Also, notice I did not mention much about data formats, Content Type, Mime, etc.&#160; Those details can cloud your design if you try to start with them. If you can’t wait for my post about how REST handles html, json, xml from the same URI, then start googling Content Negotiation, Accept header, and Content-Type header.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Driven Architecture: Publishing Events using an IOC container</title>
		<link>http://elegantcode.com/2010/05/01/say-no-to-null/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=say-no-to-null</link>
		<comments>http://elegantcode.com/2010/05/01/say-no-to-null/#comments</comments>
		<pubDate>Sat, 01 May 2010 19:35:05 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/05/01/say-no-to-null/</guid>
		<description><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after. What do you do if "null” [...]]]></description>
			<content:encoded><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after.
<blockquote>What do you do if "null” is passed in?</blockquote>
My answer may turn out to be a bit of a surprise.
<blockquote><span style="background-color: #f4f5f7;">Nothing, I don’t handle nulls in code that I control the use of.</span></blockquote>
“What?  What?” you say.  “You don’t handle null?  What kind of heresy is that?”  It is the kind of heresy that helps produce elegant code and I will show you why.
<h2>How well do you handle null right now?</h2>
Would you say that in most of the code you write you properly check all arguments for null?

Or, do you like most developers, handle null in certain cases when you happen to think about it, or after the application dumps a “null pointer exception” stack trace?

Be honest, look at your code if you have to.

The problem is “d00d ur d0ing it r0ng!”

<a href="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="john-mccarthy-programming-completely-wrong" src="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong_thumb.jpg" border="0" alt="john-mccarthy-programming-completely-wrong" width="349" height="452" /></a>

Unless you are some kind of anal retentive perfectionist, you are probably not handling null in every single method call.  That means there are huge potential bugs in the code that you are writing which will throw null pointer exceptions.  That is bad, I agree.

So, if you are not handling it correctly right now, then what can you do to fix that?
<h2>Avoiding null in the code you “own”</h2>
You can’t control external libraries.  And you can’t control how people will use your code, but you can control the code you write and you can, to a degree, control the code your shop writes.

The better strategy is to never pass null in the first place.

You can either focus your efforts on:
<ul>
	<li>Checking for null</li>
	<li>Not ever passing null</li>
</ul>
<ul>The more elegant solution is to focus on never passing null.  By doing this you will end up writing less code and avoid decisions about how to handle null inside of a method that doesn’t have enough context to decide what to do.</ul>
Let’s look at an example:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> TransmographyThreeStrings(<span class="kwrd">string</span> first, <span class="kwrd">string</span> second, <span class="kwrd">string</span> third)
{
     <span class="kwrd">if</span>(<span class="kwrd">string</span>.isNull(first) || <span class="kwrd">string</span>.isNull(second) || <span class="kwrd">string</span>.isNull(third))
    {
           <span class="rem">// hmm, I donno, what should I do?  Should I throw an exception?</span>
           <span class="rem">// should I return an empty string?</span>
           <span class="rem">// what if the first string wasn't null, can we still do something meaningful?</span>
           <span class="rem">// how will the caller of the method know what I will do?</span>
    }

}</pre>
You can see there that we are checking each parameter for null.  The problem is we don’t know what we should do.  We have lots of options, but none of them are obvious.

How much better is it to make sure that we never pass null into methods, rather than write this kind of code in every method?
<h2>What about accidentally passing in null?</h2>
Many of you are probably thinking at this point that the main way null gets passed into a method is because someone calls a method without knowing that it contains a null value.
<pre class="csharpcode">TransmographyThreeStrings(<span class="str">"Hello"</span>, <span class="str">"World"</span>, mysteryObject.Text);</pre>
Perhaps <em>mysteryObject.Text </em>is null.  You wouldn’t even know it.

Ah, but you can.  Or you can prevent it at least.  Somewhere <em>mysteryObject </em>gets created.  When it gets created its values either get initialized or not.  You can prevent any of its values from being null, several ways:
<ul>
	<li>Always initialize variables when they are declared.</li>
	<li>Use a <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> to ensure that objects are always fully constructed before being created.</li>
	<li>Use properties to provide default values or lazy initialize.</li>
	<li>Make your objects <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> as much as possible.</li>
</ul>
The practices that prevent null from accidentally being passed in make your code much more elegant than repeating <em>if blah == null</em> code all over the place.

<strong>In general, you should always strive to eliminate the passing of null rather than checking for null.  By doing so you reduce extra lines of code in each method, and are forced to use better design practices.</strong>
<h2>Exceptions</h2>
Yes, there are times when you need to check for null.  If you are writing a library that external developers will use, then you will probably want to check for null in all of your methods that are exposed as part of the API.  (On your internal methods, you don’t need to since you have already cleansed the input.)

Also, if your code is being used as a callback to some API and you don’t know if it can ever pass null into your code, you probably should check for null.

A bad excuse is that other developers may pass null to your method. <strong>It is much better as a software shop to put the onus of not passing null on the caller of any method rather than putting it on the writer of the method being called.</strong>

You will also reduce your exception handling code, because you will have less exceptions for invalid parameters.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/05/01/say-no-to-null/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Elegant Code &#187; Architecture</title>
	<atom:link href="http://elegantcode.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quinine For Sale</title>
		<link>http://elegantcode.com/2012/01/18/monitoring-an-mmo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-an-mmo</link>
		<comments>http://elegantcode.com/2012/01/18/monitoring-an-mmo/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:45:32 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MMO]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2012/01/18/monitoring-an-mmo/</guid>
		<description><![CDATA[I’ve been working on a free-to-play MMO Quinine For Sale, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I’ve been working on a free-to-play <a href="http://www.heroup.com" target="_blank">MMO</a> <b>Quinine For Sale</b>, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before they become serious and fixing problems when they inevitably do.&#160; So, there are two questions.&#160; “Is there a problem in the game?” “What is causing the problem?”&#160; </p>  <p>When trying to debug something on our development and test clusters, typically you can tail log files.&#160; We have a python script that can monitor the communication between various parts of the game and pretty-print it along with color to highlight “this is a problem!”&#160; Attaching a debugger to a running process is also not uncommon.&#160; However, looking at logs and bus traffic in realtime on a production environment gives you this neat “Matrix-y” experience.&#160; Attaching a debugger to a production process (assuming you could, which you can’t) would get you smacked with a rolled-up newspaper.&#160; “Bad Developer!&#160; No treat!”&#160; So, what can you do?</p>  <h4>Monitoring</h4>  <p>When you’ve got clusters full of machines, using <a href="http://www.nagios.org/" target="_blank">Nagios</a> to monitor things is an obvious solution.&#160; Beyond making sure the power is on and other sysadmin things, we’ve written other checks to see if the login process is working, the parts are working together, and automating typical in-game functions.&#160; For example, if nagios can’t successfully log into the game do basic game activity, then alerts happen.</p>  <h4>Metrics for EVERYTHING</h4>  <p>Anything that happens in game has metrics reporting tied to it, generating piles of data constantly.&#160; We use <a href="http://www.cacti.net/" target="_blank">Cacti</a> to visualize game activity.&#160; An example metric is concurrent users, or CCU.&#160; We graph how many people are in the game over time, which when things are healthy should be a nice smooth curve climbing to peak game hours, then descending nicely through the night.</p>  <p>We can tell by sight if the game looks healthy or not – if the CCU graph is jaggy, has a sudden drop or spike, or drops to zero then we know that something is wrong.&#160; Typically nagios alerts accompany the graphs, giving more data points on where to look.&#160; But this has also pointed out areas where a nagios check was missing or wasn’t working as intended.</p>  <h4>Log Files</h4>  <p>When a player gets an error in game, the error dialog box gives them the opportunity to submit the error details back to us.&#160; If we see a spike in user-reported errors through this or other customer service means, we know we have something of interest to look for.&#160; </p>  <p>The game server components make use of log4j and similar logging frameworks.&#160; Anything that you’d want to watch happening in game needs to be aggressively logged.&#160; All components are configured so that operations can change the log level on the fly.&#160; That’s still quite a bit of data across many machines though, so all that information is run through <a href="http://www.splunk.com/product" target="_blank">Splunk</a> to be indexed and searchable.&#160; This gives us a great tool for searching through log data, examining trends, or watching selected activity in real time.&#160; Unfortunately it is very expensive so we are selective about the data that passes through it.&#160; </p>.  Buy Quinine from mexico.  Buy Quinine no prescription.  No prescription Quinine online.  Online buying Quinine.  Quinine no prescription.  Quinine street price.  Buy no prescription Quinine online.  Quinine coupon.  Quinine over the counter.  Where can i buy Quinine online.  Quinine steet value.  Where to buy Quinine.  Order Quinine online overnight delivery no prescription.  Quinine recreational.  Quinine canada, mexico, india.  Ordering Quinine online.  Quinine without prescription.  Quinine price, coupon.  Quinine description.  Order Quinine from mexican pharmacy.  Quinine pics.  What is Quinine.  Japan, craiglist, ebay, overseas, paypal.  Order Quinine from United States pharmacy.  Order Quinine online c.o.d.  Quinine trusted pharmacy reviews.  Quinine treatment.  Buy Quinine from canada.  Quinine used for.  Discount Quinine.  Is Quinine addictive.  Quinine forum.  Buy Quinine online no prescription.  Is Quinine safe.  Purchase Quinine for sale.  Effects of Quinine.  Buy Quinine online cod.  Quinine australia, uk, us, usa.  Buy Quinine without prescription.  Quinine online cod.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4721'>Buy Flonase Without Prescription</a>. <a href='http://elegantcode.com/?p=4234'>Buy Periactin Without Prescription</a>. <a href='http://elegantcode.com/?p=4203'>Buy Armour Without Prescription</a>. <a href='http://elegantcode.com/?p=4899'>Buy Macrobid Without Prescription</a>. <a href='http://elegantcode.com/?p=4534'>Xalatan For Sale</a>. <a href='http://elegantcode.com/?p=4302'>Phenergan wiki</a>. <a href='http://elegantcode.com/?p=4268'>Soma maximum dosage</a>. <a href='http://elegantcode.com/?p=4602'>Zovirax treatment</a>. <a href='http://elegantcode.com/?p=4578'>Cialis price, coupon</a>. <a href='http://elegantcode.com/?p=4189'>Flexeril price</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.leaduganda.org/?p=514'>Quinine For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=4820'>Quinine For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2780'>Quinine For Sale</a>. <a href='http://www.thegriffonnews.com/?p=10177'>Quinine For Sale</a>. <a href='http://www.independentworldreport.com/?p=2409'>Quinine For Sale</a>. <a href='http://changecamp.ca/?p=295'>Quinine description</a>. <a href='http://social-blend.com/?p=624'>Quinine price, coupon</a>. <a href='http://blog.farmland.org/?p=3946'>Online buying Quinine hcl</a>. <a href='http://4realz.net/?p=1595'>Quinine from canada</a>. <a href='http://reversemortgagedaily.com/?p=14535'>Where to buy Quinine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2012/01/18/monitoring-an-mmo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temovate Cream For Sale</title>
		<link>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-software-development-will-never-be-engineering</link>
		<comments>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 03:37:48 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/</guid>
		<description><![CDATA[I always find it rather interesting when academics try to quantify generalized metrics about software development. Temovate Cream For Sale, Things like: per lines of code, there will be X number of bugs. Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.” These are all interesting [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I always find it rather interesting when academics try to quantify generalized metrics about software development.</p>  <p> <b>Temovate Cream For Sale</b>, Things like: per lines of code, there will be X number of bugs.</p>  <p>Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.”</p>  <p>These are all interesting thoughts, but software development will never conform to rigid engineering principles like many other engineering practices.&#160; The longer I work in the field, the more and more I realize that software development has nothing to do with engineering.&#160; We just happen to attend some of the same math classes in school.</p>  <h2>Building bridges</h2>  <p>One of the main arguments I hear people make about the current state of software development as an engineering practice is based around its relative maturity to other engineering fields.</p>  <p>There is a huge problem with this line of thinking.</p>  <p>The argument goes something like this:&#160; “<em>Engineering has been around for hundreds of years and has matured to the point where it is a measurable science, but software development has only been around in earnest for the last few decades or so, therefore it is relatively immature as an engineering discipline.”</em></p>  <p>On the surface this argument seems sounds.&#160; And certainly in 50 years software development will be different than it is now.&#160; Heck, it is much more different than it was just 10 years ago.</p>  <p>But, here is the problem.&#160; We build much more software than we do bridges.</p>  <p><img src="http://www.nps.gov/glca/historyculture/images/Navajo_Bridges_1.gif" width="589" height="442" /></p>  <h6 align="center">&#160;</h6>  <p>Let me give you an example that came to light in another area of my interest… poker.</p>  <h1></h1>  <h2>The poker quickening</h2>  <p>An interesting thing happened in the poker community in the last 10 years; poker pros with decades of experience started getting beat time and time again by 19 year old poker prodigies.</p>  <p>From an outside perspective it looks like the poker world opening up just widened the search for talent and there it was.&#160; But, a closer examination of the evidence leads to the truth.</p>  <p>Before the online poker industry was born, poker was played in card rooms and casinos in states where it was legal and occasionally at small home games throughout the US.</p>  <p>A poker pro might play poker tournaments perhaps 100 times to 150 times a year.&#160; The sum knowledge of the poker community and the meta game around it was based on this base of professional poker players playing tournaments and gaining experience at this mediocre rate.</p>  <p>Once the internet poker rooms started opening up, things changed, and they changed rapidly.&#160; Now anyone could play poker from their home PC.&#160; Not only could they play poker, they could play poker tournaments at all hours of the day.</p>  <p>Here is a list of some of the major changes that took place:</p>  <ul>   <li>Hands are dealt at 60-80 hands per hour instead of 10-30</li>    <li>Players can play in many tournaments at one time, 10 tournaments at once is not unheard of</li>    <li>Players can analyze hand histories and historical data about their play and opponents play through the use of software </li>    <li>Age requirements are out the window, technically any one of any age could be playing online</li>    <li>Players can play 24 hours a day</li>    <li>The professional online tournament player could easily play over 3000 tournaments in a year, while a brick and mortar pro would be lucky to reach 100 in a year.</li>   <img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://t1.gstatic.com/images?q=tbn:ANd9GcRj9uGNWSyqGWEneiH6xaBAyS6COwGYicdNadZu-06KWQLhIi6LMw&amp;t=1" width="316" height="270" /></ul>  <p>&#160;</p>  <p>So where am I going with all this?</p>  <p>The point is that as a whole more hands were dealt and more poker knowledge and experience was obtained in 1 year of online poker than probably the entire history of poker before that.&#160; We reached such an accelerated pace of play that all previous knowledge of poker became obsolete.&#160; </p>  <p>The strategy of tournament poker completely changed.&#160; The game evolved perhaps 500 years into the future in a matter of 5 years time.</p>  <p>The same has happened with software development.</p>  <h2>Back to the bridge building</h2>  <p>So let’s take that poker example and look at it through the lens of software development.</p>  <p>Let us compare the engineering maturity to software development to the engineering maturity of the engineering discipline of building bridges.</p>  <p>I think most people would agree that bridge building is a very mature engineering discipline but many people would argue that software development is not.</p>  <p><strong>How many bridges do you think have been built in the world?</strong></p>  <p>Well there are <a href="http://www.betterroads.com/category/bridge-inventory/erroads.randallreillycms.com/files/2009/11/BR1109_BridgeInventory.pdf">about 600,000 bridges in the United States alone</a>, so the world figure must be at least somewhere around 10 times that number perhaps 20.</p>  <p><strong>How many software programs have been written?</strong></p>  <p>This is a very hard number to estimate, but lets take a rough guess based on <a href="http://stackoverflow.com/questions/453880/how-many-developers-are-there-in-the-world">how many software developers there are in the world</a>.&#160; </p>  <p>If we say there are about 12 million software developers and each software developer has written approximately 3 programs, we can estimate that a large amount more programs have been written than bridges built.</p>  <p>My point is not to knock bridge building, we are pretty good at it as a whole, but rather to show that collectively, even though we have been building bridges for hundreds of years, we have probably devoted an equivalent amount of time to building software.</p>  <p>This line of thinking may lead you to argue back that software development and bridge building are very different.&#160; Bridge building has a fixed set of requirements that are pretty close to the the same for each bridge you build, but software development is a big open void of whims and ambiguously contradictory statements.</p>  <p>I agree with you 100%!&#160; And in essence that is my point.</p>  <h2>Software development is different</h2>  <p>And we have had enough time to realize that.&#160; Waiting for software development to gel into some kind of engineering discipline like other engineering disciplines is like waiting for water without gelatin mix to turn into Jello.&#160; </p>  <p>It’s just not going to happen!</p>  <p>In my mind it is clear that the argument that we haven’t given it enough time is just wishful thinking.&#160; The nature of software development, just like online poker, leads itself to rapid evolution.</p>  <p>Consider what direction software development is evolving.&#160; Is it even evolving in the direction of rigid engineering practices or is it evolving in the exact OPPOSITE direction?</p>  <p>Ten years ago, we tried to use UML diagrams and CASE tools to develop software.&#160; Ten years ago waterfall was all the rage.&#160; Ten years ago, we thought that ten years in the future we would have programs that would allow us to build software in the same way that CAD tools allow for building machine parts.</p>  <p>Not only did it not happen.&#160; It went completely the other way.&#160; Now we are all talking about Agile.&#160; Now people don’t even remember what CASE tools are.&#160; Now we are building software without trying to define the whole system in UML diagrams.</p>  <p><strong>The fact of the matter is software systems are unruly beasts!</strong></p>  <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://aznbadger.files.wordpress.com/2010/06/beast.jpg" /></p>  <p>In my mind it comes down to one simple distinction.&#160; Software is living, bridges aren’t.&#160; When you are done building a bridge, you are done building the bridge.&#160; </p>  <p>Sure someone, probably not you, will have to come along and do some routine maintenance on it.&#160; Sure, some small things might change about it, but for all intents and purposes the work is done.</p>  <p>In most software development scenarios, this is not the case.&#160; In most software development scenarios, releasing V1 is not even close to the end.&#160; Sometimes V1 and V2 don’t even look that same at all.&#160; Software development is about operating on a living breathing thing and all the while keeping it alive.</p>  <p>The truth is, we software developers have more in common with surgeons than with other engineers.</p>  <h6>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com/">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>.  Buy Temovate Cream without a prescription.  Temovate Cream trusted pharmacy reviews.  Temovate Cream over the counter.  Where can i order Temovate Cream without prescription.  Online buy Temovate Cream without a prescription.  Temovate Cream no rx.  Buy cheap Temovate Cream no rx.  Temovate Cream photos.  Buy Temovate Cream online no prescription.  Order Temovate Cream online c.o.d.  Herbal Temovate Cream.  About Temovate Cream.  Australia, uk, us, usa.  Cheap Temovate Cream.  Temovate Cream class.  Temovate Cream brand name.  Online Temovate Cream without a prescription.  Buy Temovate Cream without prescription.  Buy Temovate Cream from canada.  After Temovate Cream.  Order Temovate Cream from mexican pharmacy.  Temovate Cream without a prescription.  Purchase Temovate Cream.  Temovate Cream natural.  Temovate Cream overnight.  Temovate Cream online cod.  Where can i buy cheapest Temovate Cream online.  Purchase Temovate Cream for sale.  Online buying Temovate Cream.  Purchase Temovate Cream online.  Temovate Cream used for.  Temovate Cream coupon.  Temovate Cream description.  Order Temovate Cream no prescription.  Temovate Cream maximum dosage.  Cheap Temovate Cream no rx.  Temovate Cream images.  Temovate Cream blogs.  Buy Temovate Cream online cod.  Buy generic Temovate Cream.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4472'>Bactroban For Sale</a>. <a href='http://elegantcode.com/?p=4632'>Armour For Sale</a>. <a href='http://elegantcode.com/?p=4639'>Buy Estrace Vaginal Cream Without Prescription</a>. <a href='http://elegantcode.com/?p=4668'>Buy Augmentin Without Prescription</a>. <a href='http://elegantcode.com/?p=4535'>Buy Tindamax Without Prescription</a>. <a href='http://elegantcode.com/?p=4931'>Fast shipping Diclofenac</a>. <a href='http://elegantcode.com/?p=4240'>Combivent brand name</a>. <a href='http://elegantcode.com/?p=4417'>Levaquin overnight</a>. <a href='http://elegantcode.com/?p=4597'>Purchase Toradol online</a>. <a href='http://elegantcode.com/?p=4221'>Australia, uk, us, usa</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.quarterlives.com/?p=1148'>Temovate Cream For Sale</a>. <a href='http://4realz.net/?p=1972'>Temovate Cream For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=5997'>Temovate Cream For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2476'>Temovate Cream For Sale</a>. <a href='http://www.thegriffonnews.com/?p=9947'>Temovate Cream For Sale</a>. <a href='http://social-blend.com/?p=1160'>Temovate Cream brand name</a>. <a href='http://blog.farmland.org/?p=3812'>Where can i find Temovate Cream online</a>. <a href='http://reversemortgagedaily.com/?p=14136'>Generic Temovate Cream</a>. <a href='http://linuxologist.com/?p=1792'>Temovate Cream photos</a>. <a href='http://home.officesnapshots.com/?p=114'>Order Temovate Cream from mexican pharmacy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
		<item>
		<title>Christmas Light Architectures Are Not That Shiny</title>
		<link>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=christmas-light-architectures-are-not-that-shiny</link>
		<comments>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:00:00 +0000</pubDate>
		<dc:creator>Jan Van Ryswyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/</guid>
		<description><![CDATA[I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way [...]]]></description>
			<content:encoded><![CDATA[<p>I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way overdue :-).</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb1.png" width="202" height="172" /></a> </p>  <p><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a>What's the major malfunction with those old, classic Christmas lights? We've all experienced it at some point. When one goes out, all the others go out as well. This is due to the fact that these lights are wired in series. The difference compared with today's Christmas lights is that every bulb has a shunt, which basically prevents this kind of failure caused by one or more lamps. Enough about the Christmas lights for now. Where am I going with this? Back in enterprise IT, I'm seeing the same kind of failures as with those classic, old Christmas lights.</p>  <p>The diagram below shows a classic RPC style architecture, much like those classic, old Christmas lights. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb2.png" width="565" height="329" /></a> </p>  <p>This is all fine and dandy as long as every part of the chain runs without too much hassle. But what happens if for some reason the centralized back-end web service goes down (light bulb goes out). This means that every smart client, website and batch application that uses this web service gets affected by this, like some sort of chain reaction. Parts of these client applications will no longer function correctly or they might even go down entirely. Same thing happens when the database of the centralized back-end web service goes down or any other external system that it depends on. When being confronted with this kind of architecture, how would one go about preventing this doomsday scenario to happen?</p>  <p>Suppose you’re a developer that has to work on the centralized back-end web service. This is usually a complex system as it obviously has to provide features for all kinds of applications. When this centralized back-end web service also has to deal with and depend on other external systems that might expose some unexpected behavior, how could one prevent the sky from falling down when things go awry in production?</p>  <p>Well for starters, you could start building in some stabilization points. Suppose for some reason, the centralized web service needs to incorporate some functionality offered by a highly expensive, super enterprise system that for some reason behaves very unstable and unpredictably on every full moon (expensive enterprise software not behaving correctly sounds ridiculous, but bare with me ;-) ). For example, we could use a message queue as a stabilization point. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb3.png" width="570" height="157" /></a> </p>  <p>This means that we put a message on a queue that is processed by some sort of worker process or service that does the actual communication with the misbehaving system. When the external system goes down, the message is either left on the message queue or put on an error queue for later processing when the external system comes back up again. There are some other things you need to think about like idempotent messaging, consistency, message persistence when the server goes down, etc. … . But if one of these dependencies goes down, the centralized back-end web service is still up-and-running which means that the systems that depend on its functionality can also continue to serve their users as they are able to keep doing their work.</p>  <p>Earlier this week I overheard this conversation that somewhat amazed me. I changed the names of the persons involved as well as the exact words used in order to protect the guilty.</p>  <blockquote>   <p><em>George: </em><em>We want to incorporate a message queue in order to guarantee stability and&#160; integrity between several non-transactional systems that our system depends on. It will also improve performance as these systems behave very slow at times and become unstable under pressure. This also gives us the opportunity to root out some major points friction that our end-users are experiencing right now.</em></p>    <p><em>Stan: But this means that the end-users are not completely sure if their actions are indeed fully carried out by the system. </em></p>    <p><em>George: End-users can always check the current state of affairs in their applications. If something goes wrong, their request is not lost and things will get fixed automatically later on as soon as the cause of the error has been fixed. </em></p>    <p><em>Stan:&#160; I don’t think that’s a very good idea. End-users have to wait until everything is processed synchronously, even if that means that they’ll need to wait for a long time. And if one of the external systems goes down, they should stop sending in new requests. Everything should come to a halt. They just have to stop doing what they are doing.</em></p>    <p><em>George: This means that because you lose the original request, some external systems might be set up correctly while others are not. Then someone has to manually fix these issues.</em></p>    <p><em>Stan: Then so be it!</em>&#160;</p> </blockquote>  <p>For starters, I was shocked by this conversation. This is just insane. Everything should come to a halt? Think about this scenario for a while: suppose you’re finding yourself in a grocery store with a cart full of food, drinks and other stuff. You come at the cash register where the lady kindly says “Can you put everything back on the shelves please? There are some issues with the cash register software and we are instructed to stop scanning items and serve customers until these issues are fixed. Can you come back tomorrow please?”. Uhm, no! How much money do you think this is going to cost compared to the system that makes use of stabilization points? An end-user that is able to keep doing its work, whether the entire production system is down or not has tremendous business value. </p>  <p>I’m not saying that message queues are a silver bullet. I’m just using these as an example. As always, there is a time and place for using them. There are other things a developer can incorporate in order to increase the stability of the system he’s working on, like <a href="http://davybrion.com/blog/2008/05/the-circuit-breaker/" target="_blank">the circuit breaker pattern</a>. I’m also not saying that every system should be built using every stabilization point one can think of. This become a business decision depending on the kind of solution. As usual, it depends.</p>  <p>But the point that I’m trying to make here is that we should stop putting software systems into production and just hoping for the best. That’s just wishful thinking. Software systems are going to behave badly and at some point they will go down. It’s just a matter of when this is going to happen and how much damage this is going to make.</p>  <p>The first step to take is awareness. I encourage you to pick up this book titled ‘<a href="http://www.amazon.com/exec/obidos/ASIN/0978739213/elegantcode-20" target="_blank">Release It!</a>’, written by <a href="http://www.michaelnygard.com/" target="_blank">Michael Nygard</a>. This book is all about designing software that can survive this though environment called production. I can only hope that Stan picks up a copy as well along with some common sense.</p>  <p>Till next time.&#160;&#160;&#160; </p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Could sealing a class be a sign of a good design</title>
		<link>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=could-sealing-a-class-be-a-sign-of-a-good-design</link>
		<comments>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:50:15 +0000</pubDate>
		<dc:creator>Andreas Håkansson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/</guid>
		<description><![CDATA[I recently attended this years Øredev conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, Philip Laureano. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended this years <a title="Read more about the Øredev conference" href="http://oredev.com/2010" target="_blank">Øredev</a> conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, <a title="Visit the twitter profile of Philip Laureano" href="http://twitter.com/philiplaureano" target="_blank">Philip Laureano</a>. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do not know the full details of his exact opinions). Anyway, the short version is that the person suggested that classes should be sealed by default, or at least have the developer explicitly state if the class should be sealed or closed.</p>  <p>My immediate reaction was that this was a terrible idea and that I had been struck down too many times by sealed classes before. But then I started thinking that maybe it was not such a bad idea after all. Maybe it even was a sign of a well designed class and that more developers would be better of by sealing their classes.</p>  <p>Now let me inform you that I am still on the ropes about this, but I would like your thoughts on it. In fact I am hoping that the most interesting part of this post will end up being the discussion in the comment section.</p>  <p>So when you take a moment to think about the <em>S.O.L.I.D principles</em>, most specifically the <em>Open-Closed Principle</em> and <em>Dependency Inversion Principle</em>, a long with the old design principle of ‘Favor <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> over <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)">class inheritance</a>’ then maybe it is not such a bad thing after all. Throw in interfaces into the mix and program to an interface and not an implementation, and it will enables you to create different branches if needed. If your classes can flourish while being sealed, chances are that you have some pretty nice structures code in your hands.</p>  <p>There probably are some legit reasons to not seal classes at time, despite the reasoning above, so I am not going to be definitive and say that is never the case. Voice your thoughts in the comments and let us see where this ends up – who knows, I might be left standing as a fool!</p>  <p>As always, you can find me on twitter by the name of <a title="Visit me on twitter" href="http://twitter.com/thecodejunkie" target="_blank">@thecodejunkie</a></p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
		<comments>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 22:40:49 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/</guid>
		<description><![CDATA[Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended? I was working on building an automated testing framework for a welfare system in which cases could be added [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended?</p>  <p>I was working on building an automated testing framework for a welfare system in which cases could be added and benefits run for a given month.</p>  <p>A typical scenario might be something like:</p>  <ol>   <li>Create a new case for this month. </li>    <li>Add some people, do some things. </li>    <li>Run benefits for this month. </li>    <li>Run benefits for the next month.&#160; Something should happen because the child on the case is now 19. </li> </ol>  <p>Seems pretty straightforward until you consider what happens if someone hard codes dates into the test.</p>  <p>I am sure you can imagine plenty of scenarios in a situation like this where hard coded dates would eventually cause all kinds of problems.</p>  <p>The problem is… </p>  <p><strong>If you create an API which takes in various dates, how do you ensure the dates passed in are calculated and not just hard coded?</strong></p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pigsinblanket" border="0" alt="pigsinblanket" src="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket_thumb.jpg" width="514" height="514" /></a> </p>  <h2>Why convention doesn’t work</h2>  <p>Your first response might be to create some documentation that describes the importance of making dates “float” forward with time, and not be hard coded.</p>  <p>You might clearly describe how you should not hard code July 7th 1990 to be the birth date of a 20 year old for a test case.</p>  <p>You might give some guidelines of how to properly calculate ages.</p>  <p>But, you have no way of making sure the users of your API will follow those conventions or even read your document.</p>  <p>What if we do the hard work for them?</p>  <h2>Why utilities are still not good enough</h2>  <p>The next idea you might have is to create utilities that would do date conversions and calculate ages for the user of your API, so that they just have to remember to use them and all will be good.</p>  <p>This solution is better than one relying purely on convention, but still has some major flaws.&#160; Part of the problem of utility methods is that they are not self-discoverable.&#160; I’ve <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">talked about before</a> how DateUtilities like classes can get overlooked if you don’t know the utility class is there.</p>  <p>If you are relying on your users to go out and find your utility methods to make life easier for them, you are putting a large amount of responsibility in the wrong place.&#160; In my experience, it is very unlikely that anyone but yourself will actually use the utility methods.</p>  <p>You really need a way to stop them from being able to hard code dates.</p>  <h2>How can you stop someone from hard coding dates?</h2>  <p>Don’t accept dates in your API.</p>  <p>It is simple.</p>  <p>What?&#160; What do you mean?&#160; You can’t just stop accepting dates, you need dates.&#160; Not just dates, but integers, or strings.&#160; You can’t just not accept the bad data… or can you?</p>  <p>Consider wrapping the data type in another data type which creates your desired data type, but only using the convention or rules you desire.</p>  <p>Let me show you an example with the dates:</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(DateTime applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>    DoSomethingWithTheDate(applicationDate);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(<span style="color: #0000ff">new</span> DateTime(1990, 7, 8));</pre>
<!--CRLF--></div>
</div>

<p></p>

<p>In the above example, you can see that I am directly taking a .NET DateTime object.&#160; You can also see that I am directly hard coding a date when calling this method.</p>

<p>Let’s see if we can fix that.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(CaseDate applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     DoSomethingWithTheDate(CaseDate.ToDateTime());</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(CaseDate.YearsAgo(20));</pre>
<!--CRLF--></div>
</div>

<p></p>

<h2>What happened?</h2>

<p>Here is what we did:</p>

<ol>
  <li>We created a custom type called CaseDate. </li>

  <li>We replaced all the external usages of DateTime with CaseDate. </li>

  <li>We provided methods on CaseDate which allow the creation of dates, only through the way we want to allow them to be created. </li>
</ol>

<ol>Now we can easily prevent users of the API from being able to create hard coded dates.&#160; The API only will take CaseDate objects and internally creates DateTime objects from the CaseDate objects.</ol>

<ol>We can add other methods to CaseDate to allow the creation of dates from x number of months ago or in the future, or any other valid creation method we want.</ol>

<p>By doing this, we are restricting the valid set of inputs to our methods at compile time, not throwing exceptions at run time.</p>

<p>We are achieving the same kind of valuable input constrictions that we have been able to <a href="http://elegantcode.com/2010/05/08/the-power-of-enum/">achieve with enumerations</a>, except we are adding more complex restrictions than a simple list of selections.</p>

<h2>Where can I use this?</h2>

<p>Not just dates.&#160; There are many places where restricting the input to your method or API is going to simplify logic, protect against error conditions, and enforce constraints.</p>

<p>Consider using this pattern in some of these scenarios:</p>

<ul>
  <li>You want to use an enumeration, but your list of possible choices is too large, or repetitive. </li>

  <li>Anywhere you are using a primitive type and that primitive type represents some more complex concept. </li>

  <li>Anywhere you have parameter validation or manipulation repeated in multiple methods. </li>

  <li>Anytime you process some input or repeat a series of steps to transform it before sending it as input. </li>
</ul>

<p>Every time you are about to make a primitive type a parameter to a method you should ask yourself if it makes sense to wrap the primitive type into an class.</p>

<p>Remember, especially when creating an API, any time your method takes a primitive type, you lose the ability to constrain that input, and are forced to validate it instead.</p>

<p>Should you always wrap all primitive types?&#160; No, but it is another tool you can use to provide an extra layer of indirection between the logic of your API and your callers use of it.</p>

<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Prefer Additional Methods Over Additional Overloads</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
		<comments>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 17:35:54 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/</guid>
		<description><![CDATA[If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do. Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do.</p>  <p>Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are conscious of making that code as readable and terse as possible.</p>  <p><strong>Seldom do we think about the use of our code from an API standpoint.</strong></p>  <p>There is a subtle difference between designing your code in a way that will make it easier for someone else to maintain, and designing your code in a way that will make it easier for someone else to use.</p>  <h2>Intellisenselessness</h2>  <p>How often are you working against some API and you type a method name you want to use only to have intellisense present you with 5 overloads for the method all with several different parameters choices?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginOverloads" border="0" alt="LoginOverloads" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads_thumb.png" width="600" height="151" /></a> </p>  <p>Which one do you use?&#160; It is hard to be sure, you end up having to read through the long lists of parameters to figure out what method you should call and what parameters you should pass it.</p>  <p>Wouldn’t it be better if you were presented with what the method does in the method name rather than guessing what it does in the parameter list?&#160; Something like this?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginMoreMethods" border="0" alt="LoginMoreMethods" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods_thumb.png" width="596" height="261" /></a> </p>  <h2>Perspective</h2>  <p>From the perspective of the person writing the <em>Login</em> method(s), overloads probably seem like the most efficient and correct way to implement the multiple ways the method can be called.</p>  <p>From the perspective of the person using the <em>Login</em> method(s), additional methods are much preferred, because they are easier to understand and know what you are looking for.</p>  <p><strong>Try to think from the perspective of someone using your code when writing your code.</strong></p>  <h2>Extract boolean parameter to two methods</h2>  <p>I want to take a look at a very specific example that can be of great benefit to the readability and use of your code.</p>  <p>Take a look at this code below.</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login(<span style="color: #0000ff">bool</span> rememberMe)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>
Seems like a fine overload of a <em>Login</em> method.&#160; I have written code just like this, you probably have also.&#160; <br />

<p>&#160;</p>

<p>Unfortunately, by adding this overload, we have added some complexity to our API, because now the user of that code has to see that there is an additional overload that take a bool parameter called <em>rememberMe</em>.</p>

<p>Consider this longer alternative.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginDoNotRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Instead of overloading <em>Login</em> and making the user have to decide which overload to call and pass in a parameter, we have elected to create two differently named methods which take 0 parameters and clearly state what they are going to do.</p>

<p>I’m not saying you should never write overloads, but anytime you see an overload in your code base, you should stop and think if it would be more clear to make that overloaded method into two different methods that can eliminate one or more of the parameters.</p>

<p><strong>Any time you are restricting the number of choices someone using your code has to make, you are making that code simpler to use.</strong></p>

<p>If you don’t believe me, consider why the iPhone has only one button.</p>

<h5><strong>As always, you can subscribe to this </strong><a href="http://feeds2.feedburner.com/ElegantCode"><strong>RSS feed</strong></a><strong> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at </strong><a href="http://simpleprogrammer.com"><strong>http://simpleprogrammer.com</strong></a><strong>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Say &#8220;No&#8221; to &#8220;Null&#8221;</title>
		<link>http://elegantcode.com/2010/05/01/say-no-to-null/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=say-no-to-null</link>
		<comments>http://elegantcode.com/2010/05/01/say-no-to-null/#comments</comments>
		<pubDate>Sat, 01 May 2010 19:35:05 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/05/01/say-no-to-null/</guid>
		<description><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after. What do you do if "null” [...]]]></description>
			<content:encoded><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after.
<blockquote>What do you do if "null” is passed in?</blockquote>
My answer may turn out to be a bit of a surprise.
<blockquote><span style="background-color: #f4f5f7;">Nothing, I don’t handle nulls in code that I control the use of.</span></blockquote>
“What?  What?” you say.  “You don’t handle null?  What kind of heresy is that?”  It is the kind of heresy that helps produce elegant code and I will show you why.
<h2>How well do you handle null right now?</h2>
Would you say that in most of the code you write you properly check all arguments for null?

Or, do you like most developers, handle null in certain cases when you happen to think about it, or after the application dumps a “null pointer exception” stack trace?

Be honest, look at your code if you have to.

The problem is “d00d ur d0ing it r0ng!”

<a href="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="john-mccarthy-programming-completely-wrong" src="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong_thumb.jpg" border="0" alt="john-mccarthy-programming-completely-wrong" width="349" height="452" /></a>

Unless you are some kind of anal retentive perfectionist, you are probably not handling null in every single method call.  That means there are huge potential bugs in the code that you are writing which will throw null pointer exceptions.  That is bad, I agree.

So, if you are not handling it correctly right now, then what can you do to fix that?
<h2>Avoiding null in the code you “own”</h2>
You can’t control external libraries.  And you can’t control how people will use your code, but you can control the code you write and you can, to a degree, control the code your shop writes.

The better strategy is to never pass null in the first place.

You can either focus your efforts on:
<ul>
	<li>Checking for null</li>
	<li>Not ever passing null</li>
</ul>
<ul>The more elegant solution is to focus on never passing null.  By doing this you will end up writing less code and avoid decisions about how to handle null inside of a method that doesn’t have enough context to decide what to do.</ul>
Let’s look at an example:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> TransmographyThreeStrings(<span class="kwrd">string</span> first, <span class="kwrd">string</span> second, <span class="kwrd">string</span> third)
{
     <span class="kwrd">if</span>(<span class="kwrd">string</span>.isNull(first) || <span class="kwrd">string</span>.isNull(second) || <span class="kwrd">string</span>.isNull(third))
    {
           <span class="rem">// hmm, I donno, what should I do?  Should I throw an exception?</span>
           <span class="rem">// should I return an empty string?</span>
           <span class="rem">// what if the first string wasn't null, can we still do something meaningful?</span>
           <span class="rem">// how will the caller of the method know what I will do?</span>
    }

}</pre>
You can see there that we are checking each parameter for null.  The problem is we don’t know what we should do.  We have lots of options, but none of them are obvious.

How much better is it to make sure that we never pass null into methods, rather than write this kind of code in every method?
<h2>What about accidentally passing in null?</h2>
Many of you are probably thinking at this point that the main way null gets passed into a method is because someone calls a method without knowing that it contains a null value.
<pre class="csharpcode">TransmographyThreeStrings(<span class="str">"Hello"</span>, <span class="str">"World"</span>, mysteryObject.Text);</pre>
Perhaps <em>mysteryObject.Text </em>is null.  You wouldn’t even know it.

Ah, but you can.  Or you can prevent it at least.  Somewhere <em>mysteryObject </em>gets created.  When it gets created its values either get initialized or not.  You can prevent any of its values from being null, several ways:
<ul>
	<li>Always initialize variables when they are declared.</li>
	<li>Use a <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> to ensure that objects are always fully constructed before being created.</li>
	<li>Use properties to provide default values or lazy initialize.</li>
	<li>Make your objects <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> as much as possible.</li>
</ul>
The practices that prevent null from accidentally being passed in make your code much more elegant than repeating <em>if blah == null</em> code all over the place.

<strong>In general, you should always strive to eliminate the passing of null rather than checking for null.  By doing so you reduce extra lines of code in each method, and are forced to use better design practices.</strong>
<h2>Exceptions</h2>
Yes, there are times when you need to check for null.  If you are writing a library that external developers will use, then you will probably want to check for null in all of your methods that are exposed as part of the API.  (On your internal methods, you don’t need to since you have already cleansed the input.)

Also, if your code is being used as a callback to some API and you don’t know if it can ever pass null into your code, you probably should check for null.

A bad excuse is that other developers may pass null to your method. <strong>It is much better as a software shop to put the onus of not passing null on the caller of any method rather than putting it on the writer of the method being called.</strong>

You will also reduce your exception handling code, because you will have less exceptions for invalid parameters.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/05/01/say-no-to-null/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>If Self-Documenting Code is the What, Unit Tests are the Why</title>
		<link>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-self-documenting-code-is-the-what-unit-tests-are-the-why</link>
		<comments>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:09:04 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/</guid>
		<description><![CDATA[It is not enough to just write code that is clean and self-documenting.  Eliminating comments and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it. If you recall from my original post on [...]]]></description>
			<content:encoded><![CDATA[It is not enough to just write code that is clean and self-documenting.  <a href="http://elegantcode.com/2010/04/18/eliminating-comments-the-road-to-clarity/">Eliminating comments</a> and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it.

If you recall from my <a href="http://elegantcode.com/2010/04/09/what-does-elegant-code-mean-to-me/">original post</a> on Elegant code, I stated that elegant code is:
<blockquote>Something that is simple yet effective, delivered with grace.</blockquote>
By writing self-documenting code we are hopefully able to achieve some of the aspects of simplicity and grace, but it tells us nothing about the effectiveness of the code.
<h2>Bringing the dead to life</h2>
<a href="http://elegantcode.com/wp-content/uploads/2010/04/zombies.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="zombies" src="http://elegantcode.com/wp-content/uploads/2010/04/zombies_thumb.jpg" border="0" alt="zombies" width="441" height="295" /></a>

Throwing out comments is a debatable topic.  <a href="http://www.reddit.com/r/programming/comments/bsutx/">It raises quite a bit of controversy</a>, as you can see from some of the comments on my post about the subject.  The reason, perhaps, that so many people are so staunchly opposed to the idea, is because they are worried, and rightly so, that throwing out comments will reduce the documentation of what the code is doing.

Think about that for a second.  Is documentation of what the code is doing important?  It better be.  What we are trying to accomplish by writing self-documenting code instead of comments, is to take the vessel, which is the code itself, and make that same vessel be the documentation of what the code does.  It is by doing this that we creating a living representation of the functionality of the code.  Comments are akin to a dead representation of the functionality of the code because they do not change automatically with the code.

I diverge to talk about comments so that I can draw a parallel to another form of documentation which is valuable and should be considered necessary.  That other set of documentation is requirements.  Have you ever written requirements documents?  Have you ever captured requirements from the customer and put them into UML diagrams, or perhaps plopped them into some templated Word document, which is never updated again, and no one reads, because no one trusts it is correct?  Wouldn’t it be great if we would replace that dead document or set of documents, with a living one?

The good news is we can, and some of us have.  And I fully expect this recommendation will be just as controversial, because <strong>I am suggesting that we don’t have to write low level specifications of the system at all, instead we can write good unit tests. </strong>When we do this, we are taking a dead form of document and bringing it to life.
<h2>Unit tests tell us why and how our code is effective</h2>
If
<pre class="csharpcode">i = 5;  // Widget count defaults to five.</pre>
is replaced with
<pre class="csharpcode">widgetCount = DEFAULT_WIDGET_COUNT;</pre>
<!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

then
<blockquote><span style="background-color: #ffffff;">1.1.5 When a new widget is created, the widget count should be increased by one.</span></blockquote>
is replaced with
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> When_NewWidgetIsCreated_Then_WidgetCountIsIncreasedByOne()
{
     WidgetFactory.Count = 3;
     WidgetFactory.CreateNew();
     assertEquals(4, WidgetFactory.Count);
}</pre>
The unit test is replacing the low level requirement, which is somewhat open to interpretation and untied to the code, with an absolute and completely tied-to-the-code, specific requirement.

The unit test is telling us why our code is built the way it is.  It is telling us what requirement that particular structure of code is trying to address.  <strong>It is telling us what end result that code is trying to accomplish and what the expectations are on the results of a given condition.</strong>

The unit test is telling us how the code is to be used in order to achieve its result.  It is serving as a living reference to the syntax and use of the code we built.  <strong>Instead of providing instructions on how to use our API, we are providing a living example, and proof that it will indeed work.</strong> Examples are often much more effective than instructions anyway.
<h2>What exactly are we replacing?</h2>
At this point we are not trying to replace all the documentation of the system (at this point).

With self-documenting code, we sought to eliminate comments, and replace them with good variable and method names.

With unit tests, we seek to eliminate technical documentation and requirements of the system, that is targeted at a developer or technical audience.

We are NOT trying to eliminate high level specifications of the system, or use cases. <strong>Unit tests DO NOT replace that kind of documentation! </strong>We will talk about replacing that kind of documentation when we talk about automated functional or system tests.

Simply put, any kind of documentation that you would give to a developer so they understand how the system works and how to use the code or APIs, can be easily replaced by writing good unit tests.

Our simple goal is to replace the “dead” documentation (meaning that it does not update automatically with the thing it is documenting), with “living” documentation in the form of unit tests.

One last point.  I want to be clear that I am not saying that having unit tests automatically results in the ability to replace technical documentation.  Just like having long-named methods and variables doesn’t automatically replace the need for comments.  It is a matter of the quality of the unit tests that are written, just as it is a matter of the quality of the self-documenting code.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>REST: Resources, URI&#8217;s and Representations</title>
		<link>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rest-resources-uris-and-representations</link>
		<comments>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 04:00:13 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/</guid>
		<description><![CDATA[In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions. Resources Resources are at the heart of REST.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions.</p>  <h3>Resources</h3>  <p>Resources are at the heart of REST.&#160; You are already used to resources as a web browsing consumer.&#160; A resource is not something specific to REST, instead it is the first thing you probably want to consider when architecting a RESTful application.&#160; A resource is simply the entity, item, or thing you want to expose.</p>  <p>Perhaps you have approached application architecture using one or many of several modeling and design techniques.&#160; Data First practitioners typically begin with databases and data models.&#160; DDD proponents like to begin by modeling around business entities and interactions, while their cousins in the BDD camp model around business activities.</p>  <p>When you decide to apply REST you will need to think a lot more about data entities and domain objects as resources.&#160; Your existing models may or may not closely map to resources.&#160; The shift in thinking may appear slight, but is very important.&#160; It centers around making things&#160; addressable.&#160; Each resources must by uniquely identifiable as we will see in the next section.&#160; We are used to identity with most data entities, but our domain objects may not always be as easily identifiable.&#160; Likewise, our data entites may have identity, but not map to a resource.&#160; </p>  <p>Consider the classic customer and order scenario for example.&#160; If each customer and each order can be identified then it will be easy to design RESTful systems around them.&#160; However, if the model requires a lot of context then our challenge is a little bit larger.&#160; Perhaps we must first identify a partner, then a year, then a customer, and finally the order.&#160; Yes, that is a design smell in general.&#160; It makes fetching an order very difficult.&#160; Developing RESTfuly would only further expose that difficulty.&#160; Identifying your resources up front will help you reduce the possible impedance mismatches you might end up with between what you want to expose and your data or domain models.</p>  <p>REST is about interacting with Resources!</p>  <h3>URI’s</h3>  <p>REST defines the identity of a resource via URI.&#160; Each resources has a unique address in URL form (ie. using the http protocol).&#160; Interaction with a resource will take place at its URI.&#160; As an example, my twitter status feed resource URI is <a title="http://twitter.com/optionstrict" href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; That URI is unique to my feed and that is what you expect to find at that URI.&#160; In the Twitter databases or domain models my account may be referred to by the string optionstrict, or perhaps as some random number or guid.</p>  <p>To consume my status history via a service interface twitter provides another URI at <a title="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict" href="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict">http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict</a>.&#160; I would actually prefer to have access at the same URI for html, json, and xml formats.&#160; Twitter probably has its reasons for distinguishing API access from HTML rendering, but they have actually complicated their architecture by doing so.&#160; When designing the URI’s for your resources, make them easy for your users to work with.&#160; </p>  <h3>Representation</h3>  <p>Lets continue with the twitter example to describe what is meant by Representation.&#160; Given a URI and a Resource, what will your consumers receive when they issue a GET request to the URI?&#160; Twitter chose a representation of my account and included status history and profile for the response at <a href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; They decided to put a representation of my profile photo at <a title="http://twitter.com/account/profile_image/optionstrict" href="http://twitter.com/account/profile_image/optionstrict">http://twitter.com/account/profile_image/optionstrict</a>.&#160; In your REST solutions you will need to consider how you want to represent a resource at its URI.&#160; Each representation will have a unique URI.&#160; </p>  <p>Representations are also important for manipulating resources.&#160; You must define the representation required to create and update resources.&#160; Twitter status updates require a text representation with a maximum of 140 characters.&#160; They allow additional values in the status representation, such as latitude and longitude.&#160; Your REST solutions similarly must define representations for Requests and Responses.</p>  <p>I hope that this short introduction has helped you to see that the core essence of REST is simple and fairly obvious.&#160; As you look at your current solutions what are the resources you are exposing?&#160; Could you make those resources identifiable by URI?&#160; What representation would you place at each URI?&#160; What representation would you require for manipulating a given resource?</p>  <p>Also, notice I did not mention much about data formats, Content Type, Mime, etc.&#160; Those details can cloud your design if you try to start with them. If you can’t wait for my post about how REST handles html, json, xml from the same URI, then start googling Content Negotiation, Accept header, and Content-Type header.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Driven Architecture: Publishing Events using an IOC container</title>
		<link>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-self-documenting-code-is-the-what-unit-tests-are-the-why</link>
		<comments>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:09:04 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/</guid>
		<description><![CDATA[It is not enough to just write code that is clean and self-documenting.  Eliminating comments and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it. If you recall from my original post on [...]]]></description>
			<content:encoded><![CDATA[It is not enough to just write code that is clean and self-documenting.  <a href="http://elegantcode.com/2010/04/18/eliminating-comments-the-road-to-clarity/">Eliminating comments</a> and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it.

If you recall from my <a href="http://elegantcode.com/2010/04/09/what-does-elegant-code-mean-to-me/">original post</a> on Elegant code, I stated that elegant code is:
<blockquote>Something that is simple yet effective, delivered with grace.</blockquote>
By writing self-documenting code we are hopefully able to achieve some of the aspects of simplicity and grace, but it tells us nothing about the effectiveness of the code.
<h2>Bringing the dead to life</h2>
<a href="http://elegantcode.com/wp-content/uploads/2010/04/zombies.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="zombies" src="http://elegantcode.com/wp-content/uploads/2010/04/zombies_thumb.jpg" border="0" alt="zombies" width="441" height="295" /></a>

Throwing out comments is a debatable topic.  <a href="http://www.reddit.com/r/programming/comments/bsutx/">It raises quite a bit of controversy</a>, as you can see from some of the comments on my post about the subject.  The reason, perhaps, that so many people are so staunchly opposed to the idea, is because they are worried, and rightly so, that throwing out comments will reduce the documentation of what the code is doing.

Think about that for a second.  Is documentation of what the code is doing important?  It better be.  What we are trying to accomplish by writing self-documenting code instead of comments, is to take the vessel, which is the code itself, and make that same vessel be the documentation of what the code does.  It is by doing this that we creating a living representation of the functionality of the code.  Comments are akin to a dead representation of the functionality of the code because they do not change automatically with the code.

I diverge to talk about comments so that I can draw a parallel to another form of documentation which is valuable and should be considered necessary.  That other set of documentation is requirements.  Have you ever written requirements documents?  Have you ever captured requirements from the customer and put them into UML diagrams, or perhaps plopped them into some templated Word document, which is never updated again, and no one reads, because no one trusts it is correct?  Wouldn’t it be great if we would replace that dead document or set of documents, with a living one?

The good news is we can, and some of us have.  And I fully expect this recommendation will be just as controversial, because <strong>I am suggesting that we don’t have to write low level specifications of the system at all, instead we can write good unit tests. </strong>When we do this, we are taking a dead form of document and bringing it to life.
<h2>Unit tests tell us why and how our code is effective</h2>
If
<pre class="csharpcode">i = 5;  // Widget count defaults to five.</pre>
is replaced with
<pre class="csharpcode">widgetCount = DEFAULT_WIDGET_COUNT;</pre>
<!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

then
<blockquote><span style="background-color: #ffffff;">1.1.5 When a new widget is created, the widget count should be increased by one.</span></blockquote>
is replaced with
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> When_NewWidgetIsCreated_Then_WidgetCountIsIncreasedByOne()
{
     WidgetFactory.Count = 3;
     WidgetFactory.CreateNew();
     assertEquals(4, WidgetFactory.Count);
}</pre>
The unit test is replacing the low level requirement, which is somewhat open to interpretation and untied to the code, with an absolute and completely tied-to-the-code, specific requirement.

The unit test is telling us why our code is built the way it is.  It is telling us what requirement that particular structure of code is trying to address.  <strong>It is telling us what end result that code is trying to accomplish and what the expectations are on the results of a given condition.</strong>

The unit test is telling us how the code is to be used in order to achieve its result.  It is serving as a living reference to the syntax and use of the code we built.  <strong>Instead of providing instructions on how to use our API, we are providing a living example, and proof that it will indeed work.</strong> Examples are often much more effective than instructions anyway.
<h2>What exactly are we replacing?</h2>
At this point we are not trying to replace all the documentation of the system (at this point).

With self-documenting code, we sought to eliminate comments, and replace them with good variable and method names.

With unit tests, we seek to eliminate technical documentation and requirements of the system, that is targeted at a developer or technical audience.

We are NOT trying to eliminate high level specifications of the system, or use cases. <strong>Unit tests DO NOT replace that kind of documentation! </strong>We will talk about replacing that kind of documentation when we talk about automated functional or system tests.

Simply put, any kind of documentation that you would give to a developer so they understand how the system works and how to use the code or APIs, can be easily replaced by writing good unit tests.

Our simple goal is to replace the “dead” documentation (meaning that it does not update automatically with the thing it is documenting), with “living” documentation in the form of unit tests.

One last point.  I want to be clear that I am not saying that having unit tests automatically results in the ability to replace technical documentation.  Just like having long-named methods and variables doesn’t automatically replace the need for comments.  It is a matter of the quality of the unit tests that are written, just as it is a matter of the quality of the self-documenting code.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Elegant Code &#187; Architecture</title>
	<atom:link href="http://elegantcode.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quinine For Sale</title>
		<link>http://elegantcode.com/2012/01/18/monitoring-an-mmo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-an-mmo</link>
		<comments>http://elegantcode.com/2012/01/18/monitoring-an-mmo/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:45:32 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MMO]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2012/01/18/monitoring-an-mmo/</guid>
		<description><![CDATA[I’ve been working on a free-to-play MMO Quinine For Sale, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I’ve been working on a free-to-play <a href="http://www.heroup.com" target="_blank">MMO</a> <b>Quinine For Sale</b>, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before they become serious and fixing problems when they inevitably do.&#160; So, there are two questions.&#160; “Is there a problem in the game?” “What is causing the problem?”&#160; </p>  <p>When trying to debug something on our development and test clusters, typically you can tail log files.&#160; We have a python script that can monitor the communication between various parts of the game and pretty-print it along with color to highlight “this is a problem!”&#160; Attaching a debugger to a running process is also not uncommon.&#160; However, looking at logs and bus traffic in realtime on a production environment gives you this neat “Matrix-y” experience.&#160; Attaching a debugger to a production process (assuming you could, which you can’t) would get you smacked with a rolled-up newspaper.&#160; “Bad Developer!&#160; No treat!”&#160; So, what can you do?</p>  <h4>Monitoring</h4>  <p>When you’ve got clusters full of machines, using <a href="http://www.nagios.org/" target="_blank">Nagios</a> to monitor things is an obvious solution.&#160; Beyond making sure the power is on and other sysadmin things, we’ve written other checks to see if the login process is working, the parts are working together, and automating typical in-game functions.&#160; For example, if nagios can’t successfully log into the game do basic game activity, then alerts happen.</p>  <h4>Metrics for EVERYTHING</h4>  <p>Anything that happens in game has metrics reporting tied to it, generating piles of data constantly.&#160; We use <a href="http://www.cacti.net/" target="_blank">Cacti</a> to visualize game activity.&#160; An example metric is concurrent users, or CCU.&#160; We graph how many people are in the game over time, which when things are healthy should be a nice smooth curve climbing to peak game hours, then descending nicely through the night.</p>  <p>We can tell by sight if the game looks healthy or not – if the CCU graph is jaggy, has a sudden drop or spike, or drops to zero then we know that something is wrong.&#160; Typically nagios alerts accompany the graphs, giving more data points on where to look.&#160; But this has also pointed out areas where a nagios check was missing or wasn’t working as intended.</p>  <h4>Log Files</h4>  <p>When a player gets an error in game, the error dialog box gives them the opportunity to submit the error details back to us.&#160; If we see a spike in user-reported errors through this or other customer service means, we know we have something of interest to look for.&#160; </p>  <p>The game server components make use of log4j and similar logging frameworks.&#160; Anything that you’d want to watch happening in game needs to be aggressively logged.&#160; All components are configured so that operations can change the log level on the fly.&#160; That’s still quite a bit of data across many machines though, so all that information is run through <a href="http://www.splunk.com/product" target="_blank">Splunk</a> to be indexed and searchable.&#160; This gives us a great tool for searching through log data, examining trends, or watching selected activity in real time.&#160; Unfortunately it is very expensive so we are selective about the data that passes through it.&#160; </p>.  Buy Quinine from mexico.  Buy Quinine no prescription.  No prescription Quinine online.  Online buying Quinine.  Quinine no prescription.  Quinine street price.  Buy no prescription Quinine online.  Quinine coupon.  Quinine over the counter.  Where can i buy Quinine online.  Quinine steet value.  Where to buy Quinine.  Order Quinine online overnight delivery no prescription.  Quinine recreational.  Quinine canada, mexico, india.  Ordering Quinine online.  Quinine without prescription.  Quinine price, coupon.  Quinine description.  Order Quinine from mexican pharmacy.  Quinine pics.  What is Quinine.  Japan, craiglist, ebay, overseas, paypal.  Order Quinine from United States pharmacy.  Order Quinine online c.o.d.  Quinine trusted pharmacy reviews.  Quinine treatment.  Buy Quinine from canada.  Quinine used for.  Discount Quinine.  Is Quinine addictive.  Quinine forum.  Buy Quinine online no prescription.  Is Quinine safe.  Purchase Quinine for sale.  Effects of Quinine.  Buy Quinine online cod.  Quinine australia, uk, us, usa.  Buy Quinine without prescription.  Quinine online cod.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4721'>Buy Flonase Without Prescription</a>. <a href='http://elegantcode.com/?p=4234'>Buy Periactin Without Prescription</a>. <a href='http://elegantcode.com/?p=4203'>Buy Armour Without Prescription</a>. <a href='http://elegantcode.com/?p=4899'>Buy Macrobid Without Prescription</a>. <a href='http://elegantcode.com/?p=4534'>Xalatan For Sale</a>. <a href='http://elegantcode.com/?p=4302'>Phenergan wiki</a>. <a href='http://elegantcode.com/?p=4268'>Soma maximum dosage</a>. <a href='http://elegantcode.com/?p=4602'>Zovirax treatment</a>. <a href='http://elegantcode.com/?p=4578'>Cialis price, coupon</a>. <a href='http://elegantcode.com/?p=4189'>Flexeril price</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.leaduganda.org/?p=514'>Quinine For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=4820'>Quinine For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2780'>Quinine For Sale</a>. <a href='http://www.thegriffonnews.com/?p=10177'>Quinine For Sale</a>. <a href='http://www.independentworldreport.com/?p=2409'>Quinine For Sale</a>. <a href='http://changecamp.ca/?p=295'>Quinine description</a>. <a href='http://social-blend.com/?p=624'>Quinine price, coupon</a>. <a href='http://blog.farmland.org/?p=3946'>Online buying Quinine hcl</a>. <a href='http://4realz.net/?p=1595'>Quinine from canada</a>. <a href='http://reversemortgagedaily.com/?p=14535'>Where to buy Quinine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2012/01/18/monitoring-an-mmo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temovate Cream For Sale</title>
		<link>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-software-development-will-never-be-engineering</link>
		<comments>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 03:37:48 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/</guid>
		<description><![CDATA[I always find it rather interesting when academics try to quantify generalized metrics about software development. Temovate Cream For Sale, Things like: per lines of code, there will be X number of bugs. Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.” These are all interesting [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I always find it rather interesting when academics try to quantify generalized metrics about software development.</p>  <p> <b>Temovate Cream For Sale</b>, Things like: per lines of code, there will be X number of bugs.</p>  <p>Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.”</p>  <p>These are all interesting thoughts, but software development will never conform to rigid engineering principles like many other engineering practices.&#160; The longer I work in the field, the more and more I realize that software development has nothing to do with engineering.&#160; We just happen to attend some of the same math classes in school.</p>  <h2>Building bridges</h2>  <p>One of the main arguments I hear people make about the current state of software development as an engineering practice is based around its relative maturity to other engineering fields.</p>  <p>There is a huge problem with this line of thinking.</p>  <p>The argument goes something like this:&#160; “<em>Engineering has been around for hundreds of years and has matured to the point where it is a measurable science, but software development has only been around in earnest for the last few decades or so, therefore it is relatively immature as an engineering discipline.”</em></p>  <p>On the surface this argument seems sounds.&#160; And certainly in 50 years software development will be different than it is now.&#160; Heck, it is much more different than it was just 10 years ago.</p>  <p>But, here is the problem.&#160; We build much more software than we do bridges.</p>  <p><img src="http://www.nps.gov/glca/historyculture/images/Navajo_Bridges_1.gif" width="589" height="442" /></p>  <h6 align="center">&#160;</h6>  <p>Let me give you an example that came to light in another area of my interest… poker.</p>  <h1></h1>  <h2>The poker quickening</h2>  <p>An interesting thing happened in the poker community in the last 10 years; poker pros with decades of experience started getting beat time and time again by 19 year old poker prodigies.</p>  <p>From an outside perspective it looks like the poker world opening up just widened the search for talent and there it was.&#160; But, a closer examination of the evidence leads to the truth.</p>  <p>Before the online poker industry was born, poker was played in card rooms and casinos in states where it was legal and occasionally at small home games throughout the US.</p>  <p>A poker pro might play poker tournaments perhaps 100 times to 150 times a year.&#160; The sum knowledge of the poker community and the meta game around it was based on this base of professional poker players playing tournaments and gaining experience at this mediocre rate.</p>  <p>Once the internet poker rooms started opening up, things changed, and they changed rapidly.&#160; Now anyone could play poker from their home PC.&#160; Not only could they play poker, they could play poker tournaments at all hours of the day.</p>  <p>Here is a list of some of the major changes that took place:</p>  <ul>   <li>Hands are dealt at 60-80 hands per hour instead of 10-30</li>    <li>Players can play in many tournaments at one time, 10 tournaments at once is not unheard of</li>    <li>Players can analyze hand histories and historical data about their play and opponents play through the use of software </li>    <li>Age requirements are out the window, technically any one of any age could be playing online</li>    <li>Players can play 24 hours a day</li>    <li>The professional online tournament player could easily play over 3000 tournaments in a year, while a brick and mortar pro would be lucky to reach 100 in a year.</li>   <img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://t1.gstatic.com/images?q=tbn:ANd9GcRj9uGNWSyqGWEneiH6xaBAyS6COwGYicdNadZu-06KWQLhIi6LMw&amp;t=1" width="316" height="270" /></ul>  <p>&#160;</p>  <p>So where am I going with all this?</p>  <p>The point is that as a whole more hands were dealt and more poker knowledge and experience was obtained in 1 year of online poker than probably the entire history of poker before that.&#160; We reached such an accelerated pace of play that all previous knowledge of poker became obsolete.&#160; </p>  <p>The strategy of tournament poker completely changed.&#160; The game evolved perhaps 500 years into the future in a matter of 5 years time.</p>  <p>The same has happened with software development.</p>  <h2>Back to the bridge building</h2>  <p>So let’s take that poker example and look at it through the lens of software development.</p>  <p>Let us compare the engineering maturity to software development to the engineering maturity of the engineering discipline of building bridges.</p>  <p>I think most people would agree that bridge building is a very mature engineering discipline but many people would argue that software development is not.</p>  <p><strong>How many bridges do you think have been built in the world?</strong></p>  <p>Well there are <a href="http://www.betterroads.com/category/bridge-inventory/erroads.randallreillycms.com/files/2009/11/BR1109_BridgeInventory.pdf">about 600,000 bridges in the United States alone</a>, so the world figure must be at least somewhere around 10 times that number perhaps 20.</p>  <p><strong>How many software programs have been written?</strong></p>  <p>This is a very hard number to estimate, but lets take a rough guess based on <a href="http://stackoverflow.com/questions/453880/how-many-developers-are-there-in-the-world">how many software developers there are in the world</a>.&#160; </p>  <p>If we say there are about 12 million software developers and each software developer has written approximately 3 programs, we can estimate that a large amount more programs have been written than bridges built.</p>  <p>My point is not to knock bridge building, we are pretty good at it as a whole, but rather to show that collectively, even though we have been building bridges for hundreds of years, we have probably devoted an equivalent amount of time to building software.</p>  <p>This line of thinking may lead you to argue back that software development and bridge building are very different.&#160; Bridge building has a fixed set of requirements that are pretty close to the the same for each bridge you build, but software development is a big open void of whims and ambiguously contradictory statements.</p>  <p>I agree with you 100%!&#160; And in essence that is my point.</p>  <h2>Software development is different</h2>  <p>And we have had enough time to realize that.&#160; Waiting for software development to gel into some kind of engineering discipline like other engineering disciplines is like waiting for water without gelatin mix to turn into Jello.&#160; </p>  <p>It’s just not going to happen!</p>  <p>In my mind it is clear that the argument that we haven’t given it enough time is just wishful thinking.&#160; The nature of software development, just like online poker, leads itself to rapid evolution.</p>  <p>Consider what direction software development is evolving.&#160; Is it even evolving in the direction of rigid engineering practices or is it evolving in the exact OPPOSITE direction?</p>  <p>Ten years ago, we tried to use UML diagrams and CASE tools to develop software.&#160; Ten years ago waterfall was all the rage.&#160; Ten years ago, we thought that ten years in the future we would have programs that would allow us to build software in the same way that CAD tools allow for building machine parts.</p>  <p>Not only did it not happen.&#160; It went completely the other way.&#160; Now we are all talking about Agile.&#160; Now people don’t even remember what CASE tools are.&#160; Now we are building software without trying to define the whole system in UML diagrams.</p>  <p><strong>The fact of the matter is software systems are unruly beasts!</strong></p>  <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://aznbadger.files.wordpress.com/2010/06/beast.jpg" /></p>  <p>In my mind it comes down to one simple distinction.&#160; Software is living, bridges aren’t.&#160; When you are done building a bridge, you are done building the bridge.&#160; </p>  <p>Sure someone, probably not you, will have to come along and do some routine maintenance on it.&#160; Sure, some small things might change about it, but for all intents and purposes the work is done.</p>  <p>In most software development scenarios, this is not the case.&#160; In most software development scenarios, releasing V1 is not even close to the end.&#160; Sometimes V1 and V2 don’t even look that same at all.&#160; Software development is about operating on a living breathing thing and all the while keeping it alive.</p>  <p>The truth is, we software developers have more in common with surgeons than with other engineers.</p>  <h6>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com/">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>.  Buy Temovate Cream without a prescription.  Temovate Cream trusted pharmacy reviews.  Temovate Cream over the counter.  Where can i order Temovate Cream without prescription.  Online buy Temovate Cream without a prescription.  Temovate Cream no rx.  Buy cheap Temovate Cream no rx.  Temovate Cream photos.  Buy Temovate Cream online no prescription.  Order Temovate Cream online c.o.d.  Herbal Temovate Cream.  About Temovate Cream.  Australia, uk, us, usa.  Cheap Temovate Cream.  Temovate Cream class.  Temovate Cream brand name.  Online Temovate Cream without a prescription.  Buy Temovate Cream without prescription.  Buy Temovate Cream from canada.  After Temovate Cream.  Order Temovate Cream from mexican pharmacy.  Temovate Cream without a prescription.  Purchase Temovate Cream.  Temovate Cream natural.  Temovate Cream overnight.  Temovate Cream online cod.  Where can i buy cheapest Temovate Cream online.  Purchase Temovate Cream for sale.  Online buying Temovate Cream.  Purchase Temovate Cream online.  Temovate Cream used for.  Temovate Cream coupon.  Temovate Cream description.  Order Temovate Cream no prescription.  Temovate Cream maximum dosage.  Cheap Temovate Cream no rx.  Temovate Cream images.  Temovate Cream blogs.  Buy Temovate Cream online cod.  Buy generic Temovate Cream.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4472'>Bactroban For Sale</a>. <a href='http://elegantcode.com/?p=4632'>Armour For Sale</a>. <a href='http://elegantcode.com/?p=4639'>Buy Estrace Vaginal Cream Without Prescription</a>. <a href='http://elegantcode.com/?p=4668'>Buy Augmentin Without Prescription</a>. <a href='http://elegantcode.com/?p=4535'>Buy Tindamax Without Prescription</a>. <a href='http://elegantcode.com/?p=4931'>Fast shipping Diclofenac</a>. <a href='http://elegantcode.com/?p=4240'>Combivent brand name</a>. <a href='http://elegantcode.com/?p=4417'>Levaquin overnight</a>. <a href='http://elegantcode.com/?p=4597'>Purchase Toradol online</a>. <a href='http://elegantcode.com/?p=4221'>Australia, uk, us, usa</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.quarterlives.com/?p=1148'>Temovate Cream For Sale</a>. <a href='http://4realz.net/?p=1972'>Temovate Cream For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=5997'>Temovate Cream For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2476'>Temovate Cream For Sale</a>. <a href='http://www.thegriffonnews.com/?p=9947'>Temovate Cream For Sale</a>. <a href='http://social-blend.com/?p=1160'>Temovate Cream brand name</a>. <a href='http://blog.farmland.org/?p=3812'>Where can i find Temovate Cream online</a>. <a href='http://reversemortgagedaily.com/?p=14136'>Generic Temovate Cream</a>. <a href='http://linuxologist.com/?p=1792'>Temovate Cream photos</a>. <a href='http://home.officesnapshots.com/?p=114'>Order Temovate Cream from mexican pharmacy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
		<item>
		<title>Christmas Light Architectures Are Not That Shiny</title>
		<link>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=christmas-light-architectures-are-not-that-shiny</link>
		<comments>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:00:00 +0000</pubDate>
		<dc:creator>Jan Van Ryswyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/</guid>
		<description><![CDATA[I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way [...]]]></description>
			<content:encoded><![CDATA[<p>I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way overdue :-).</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb1.png" width="202" height="172" /></a> </p>  <p><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a>What's the major malfunction with those old, classic Christmas lights? We've all experienced it at some point. When one goes out, all the others go out as well. This is due to the fact that these lights are wired in series. The difference compared with today's Christmas lights is that every bulb has a shunt, which basically prevents this kind of failure caused by one or more lamps. Enough about the Christmas lights for now. Where am I going with this? Back in enterprise IT, I'm seeing the same kind of failures as with those classic, old Christmas lights.</p>  <p>The diagram below shows a classic RPC style architecture, much like those classic, old Christmas lights. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb2.png" width="565" height="329" /></a> </p>  <p>This is all fine and dandy as long as every part of the chain runs without too much hassle. But what happens if for some reason the centralized back-end web service goes down (light bulb goes out). This means that every smart client, website and batch application that uses this web service gets affected by this, like some sort of chain reaction. Parts of these client applications will no longer function correctly or they might even go down entirely. Same thing happens when the database of the centralized back-end web service goes down or any other external system that it depends on. When being confronted with this kind of architecture, how would one go about preventing this doomsday scenario to happen?</p>  <p>Suppose you’re a developer that has to work on the centralized back-end web service. This is usually a complex system as it obviously has to provide features for all kinds of applications. When this centralized back-end web service also has to deal with and depend on other external systems that might expose some unexpected behavior, how could one prevent the sky from falling down when things go awry in production?</p>  <p>Well for starters, you could start building in some stabilization points. Suppose for some reason, the centralized web service needs to incorporate some functionality offered by a highly expensive, super enterprise system that for some reason behaves very unstable and unpredictably on every full moon (expensive enterprise software not behaving correctly sounds ridiculous, but bare with me ;-) ). For example, we could use a message queue as a stabilization point. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb3.png" width="570" height="157" /></a> </p>  <p>This means that we put a message on a queue that is processed by some sort of worker process or service that does the actual communication with the misbehaving system. When the external system goes down, the message is either left on the message queue or put on an error queue for later processing when the external system comes back up again. There are some other things you need to think about like idempotent messaging, consistency, message persistence when the server goes down, etc. … . But if one of these dependencies goes down, the centralized back-end web service is still up-and-running which means that the systems that depend on its functionality can also continue to serve their users as they are able to keep doing their work.</p>  <p>Earlier this week I overheard this conversation that somewhat amazed me. I changed the names of the persons involved as well as the exact words used in order to protect the guilty.</p>  <blockquote>   <p><em>George: </em><em>We want to incorporate a message queue in order to guarantee stability and&#160; integrity between several non-transactional systems that our system depends on. It will also improve performance as these systems behave very slow at times and become unstable under pressure. This also gives us the opportunity to root out some major points friction that our end-users are experiencing right now.</em></p>    <p><em>Stan: But this means that the end-users are not completely sure if their actions are indeed fully carried out by the system. </em></p>    <p><em>George: End-users can always check the current state of affairs in their applications. If something goes wrong, their request is not lost and things will get fixed automatically later on as soon as the cause of the error has been fixed. </em></p>    <p><em>Stan:&#160; I don’t think that’s a very good idea. End-users have to wait until everything is processed synchronously, even if that means that they’ll need to wait for a long time. And if one of the external systems goes down, they should stop sending in new requests. Everything should come to a halt. They just have to stop doing what they are doing.</em></p>    <p><em>George: This means that because you lose the original request, some external systems might be set up correctly while others are not. Then someone has to manually fix these issues.</em></p>    <p><em>Stan: Then so be it!</em>&#160;</p> </blockquote>  <p>For starters, I was shocked by this conversation. This is just insane. Everything should come to a halt? Think about this scenario for a while: suppose you’re finding yourself in a grocery store with a cart full of food, drinks and other stuff. You come at the cash register where the lady kindly says “Can you put everything back on the shelves please? There are some issues with the cash register software and we are instructed to stop scanning items and serve customers until these issues are fixed. Can you come back tomorrow please?”. Uhm, no! How much money do you think this is going to cost compared to the system that makes use of stabilization points? An end-user that is able to keep doing its work, whether the entire production system is down or not has tremendous business value. </p>  <p>I’m not saying that message queues are a silver bullet. I’m just using these as an example. As always, there is a time and place for using them. There are other things a developer can incorporate in order to increase the stability of the system he’s working on, like <a href="http://davybrion.com/blog/2008/05/the-circuit-breaker/" target="_blank">the circuit breaker pattern</a>. I’m also not saying that every system should be built using every stabilization point one can think of. This become a business decision depending on the kind of solution. As usual, it depends.</p>  <p>But the point that I’m trying to make here is that we should stop putting software systems into production and just hoping for the best. That’s just wishful thinking. Software systems are going to behave badly and at some point they will go down. It’s just a matter of when this is going to happen and how much damage this is going to make.</p>  <p>The first step to take is awareness. I encourage you to pick up this book titled ‘<a href="http://www.amazon.com/exec/obidos/ASIN/0978739213/elegantcode-20" target="_blank">Release It!</a>’, written by <a href="http://www.michaelnygard.com/" target="_blank">Michael Nygard</a>. This book is all about designing software that can survive this though environment called production. I can only hope that Stan picks up a copy as well along with some common sense.</p>  <p>Till next time.&#160;&#160;&#160; </p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Could sealing a class be a sign of a good design</title>
		<link>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=could-sealing-a-class-be-a-sign-of-a-good-design</link>
		<comments>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:50:15 +0000</pubDate>
		<dc:creator>Andreas Håkansson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/</guid>
		<description><![CDATA[I recently attended this years Øredev conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, Philip Laureano. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended this years <a title="Read more about the Øredev conference" href="http://oredev.com/2010" target="_blank">Øredev</a> conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, <a title="Visit the twitter profile of Philip Laureano" href="http://twitter.com/philiplaureano" target="_blank">Philip Laureano</a>. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do not know the full details of his exact opinions). Anyway, the short version is that the person suggested that classes should be sealed by default, or at least have the developer explicitly state if the class should be sealed or closed.</p>  <p>My immediate reaction was that this was a terrible idea and that I had been struck down too many times by sealed classes before. But then I started thinking that maybe it was not such a bad idea after all. Maybe it even was a sign of a well designed class and that more developers would be better of by sealing their classes.</p>  <p>Now let me inform you that I am still on the ropes about this, but I would like your thoughts on it. In fact I am hoping that the most interesting part of this post will end up being the discussion in the comment section.</p>  <p>So when you take a moment to think about the <em>S.O.L.I.D principles</em>, most specifically the <em>Open-Closed Principle</em> and <em>Dependency Inversion Principle</em>, a long with the old design principle of ‘Favor <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> over <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)">class inheritance</a>’ then maybe it is not such a bad thing after all. Throw in interfaces into the mix and program to an interface and not an implementation, and it will enables you to create different branches if needed. If your classes can flourish while being sealed, chances are that you have some pretty nice structures code in your hands.</p>  <p>There probably are some legit reasons to not seal classes at time, despite the reasoning above, so I am not going to be definitive and say that is never the case. Voice your thoughts in the comments and let us see where this ends up – who knows, I might be left standing as a fool!</p>  <p>As always, you can find me on twitter by the name of <a title="Visit me on twitter" href="http://twitter.com/thecodejunkie" target="_blank">@thecodejunkie</a></p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
		<comments>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 22:40:49 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/</guid>
		<description><![CDATA[Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended? I was working on building an automated testing framework for a welfare system in which cases could be added [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended?</p>  <p>I was working on building an automated testing framework for a welfare system in which cases could be added and benefits run for a given month.</p>  <p>A typical scenario might be something like:</p>  <ol>   <li>Create a new case for this month. </li>    <li>Add some people, do some things. </li>    <li>Run benefits for this month. </li>    <li>Run benefits for the next month.&#160; Something should happen because the child on the case is now 19. </li> </ol>  <p>Seems pretty straightforward until you consider what happens if someone hard codes dates into the test.</p>  <p>I am sure you can imagine plenty of scenarios in a situation like this where hard coded dates would eventually cause all kinds of problems.</p>  <p>The problem is… </p>  <p><strong>If you create an API which takes in various dates, how do you ensure the dates passed in are calculated and not just hard coded?</strong></p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pigsinblanket" border="0" alt="pigsinblanket" src="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket_thumb.jpg" width="514" height="514" /></a> </p>  <h2>Why convention doesn’t work</h2>  <p>Your first response might be to create some documentation that describes the importance of making dates “float” forward with time, and not be hard coded.</p>  <p>You might clearly describe how you should not hard code July 7th 1990 to be the birth date of a 20 year old for a test case.</p>  <p>You might give some guidelines of how to properly calculate ages.</p>  <p>But, you have no way of making sure the users of your API will follow those conventions or even read your document.</p>  <p>What if we do the hard work for them?</p>  <h2>Why utilities are still not good enough</h2>  <p>The next idea you might have is to create utilities that would do date conversions and calculate ages for the user of your API, so that they just have to remember to use them and all will be good.</p>  <p>This solution is better than one relying purely on convention, but still has some major flaws.&#160; Part of the problem of utility methods is that they are not self-discoverable.&#160; I’ve <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">talked about before</a> how DateUtilities like classes can get overlooked if you don’t know the utility class is there.</p>  <p>If you are relying on your users to go out and find your utility methods to make life easier for them, you are putting a large amount of responsibility in the wrong place.&#160; In my experience, it is very unlikely that anyone but yourself will actually use the utility methods.</p>  <p>You really need a way to stop them from being able to hard code dates.</p>  <h2>How can you stop someone from hard coding dates?</h2>  <p>Don’t accept dates in your API.</p>  <p>It is simple.</p>  <p>What?&#160; What do you mean?&#160; You can’t just stop accepting dates, you need dates.&#160; Not just dates, but integers, or strings.&#160; You can’t just not accept the bad data… or can you?</p>  <p>Consider wrapping the data type in another data type which creates your desired data type, but only using the convention or rules you desire.</p>  <p>Let me show you an example with the dates:</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(DateTime applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>    DoSomethingWithTheDate(applicationDate);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(<span style="color: #0000ff">new</span> DateTime(1990, 7, 8));</pre>
<!--CRLF--></div>
</div>

<p></p>

<p>In the above example, you can see that I am directly taking a .NET DateTime object.&#160; You can also see that I am directly hard coding a date when calling this method.</p>

<p>Let’s see if we can fix that.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(CaseDate applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     DoSomethingWithTheDate(CaseDate.ToDateTime());</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(CaseDate.YearsAgo(20));</pre>
<!--CRLF--></div>
</div>

<p></p>

<h2>What happened?</h2>

<p>Here is what we did:</p>

<ol>
  <li>We created a custom type called CaseDate. </li>

  <li>We replaced all the external usages of DateTime with CaseDate. </li>

  <li>We provided methods on CaseDate which allow the creation of dates, only through the way we want to allow them to be created. </li>
</ol>

<ol>Now we can easily prevent users of the API from being able to create hard coded dates.&#160; The API only will take CaseDate objects and internally creates DateTime objects from the CaseDate objects.</ol>

<ol>We can add other methods to CaseDate to allow the creation of dates from x number of months ago or in the future, or any other valid creation method we want.</ol>

<p>By doing this, we are restricting the valid set of inputs to our methods at compile time, not throwing exceptions at run time.</p>

<p>We are achieving the same kind of valuable input constrictions that we have been able to <a href="http://elegantcode.com/2010/05/08/the-power-of-enum/">achieve with enumerations</a>, except we are adding more complex restrictions than a simple list of selections.</p>

<h2>Where can I use this?</h2>

<p>Not just dates.&#160; There are many places where restricting the input to your method or API is going to simplify logic, protect against error conditions, and enforce constraints.</p>

<p>Consider using this pattern in some of these scenarios:</p>

<ul>
  <li>You want to use an enumeration, but your list of possible choices is too large, or repetitive. </li>

  <li>Anywhere you are using a primitive type and that primitive type represents some more complex concept. </li>

  <li>Anywhere you have parameter validation or manipulation repeated in multiple methods. </li>

  <li>Anytime you process some input or repeat a series of steps to transform it before sending it as input. </li>
</ul>

<p>Every time you are about to make a primitive type a parameter to a method you should ask yourself if it makes sense to wrap the primitive type into an class.</p>

<p>Remember, especially when creating an API, any time your method takes a primitive type, you lose the ability to constrain that input, and are forced to validate it instead.</p>

<p>Should you always wrap all primitive types?&#160; No, but it is another tool you can use to provide an extra layer of indirection between the logic of your API and your callers use of it.</p>

<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Prefer Additional Methods Over Additional Overloads</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
		<comments>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 17:35:54 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/</guid>
		<description><![CDATA[If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do. Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do.</p>  <p>Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are conscious of making that code as readable and terse as possible.</p>  <p><strong>Seldom do we think about the use of our code from an API standpoint.</strong></p>  <p>There is a subtle difference between designing your code in a way that will make it easier for someone else to maintain, and designing your code in a way that will make it easier for someone else to use.</p>  <h2>Intellisenselessness</h2>  <p>How often are you working against some API and you type a method name you want to use only to have intellisense present you with 5 overloads for the method all with several different parameters choices?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginOverloads" border="0" alt="LoginOverloads" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads_thumb.png" width="600" height="151" /></a> </p>  <p>Which one do you use?&#160; It is hard to be sure, you end up having to read through the long lists of parameters to figure out what method you should call and what parameters you should pass it.</p>  <p>Wouldn’t it be better if you were presented with what the method does in the method name rather than guessing what it does in the parameter list?&#160; Something like this?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginMoreMethods" border="0" alt="LoginMoreMethods" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods_thumb.png" width="596" height="261" /></a> </p>  <h2>Perspective</h2>  <p>From the perspective of the person writing the <em>Login</em> method(s), overloads probably seem like the most efficient and correct way to implement the multiple ways the method can be called.</p>  <p>From the perspective of the person using the <em>Login</em> method(s), additional methods are much preferred, because they are easier to understand and know what you are looking for.</p>  <p><strong>Try to think from the perspective of someone using your code when writing your code.</strong></p>  <h2>Extract boolean parameter to two methods</h2>  <p>I want to take a look at a very specific example that can be of great benefit to the readability and use of your code.</p>  <p>Take a look at this code below.</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login(<span style="color: #0000ff">bool</span> rememberMe)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>
Seems like a fine overload of a <em>Login</em> method.&#160; I have written code just like this, you probably have also.&#160; <br />

<p>&#160;</p>

<p>Unfortunately, by adding this overload, we have added some complexity to our API, because now the user of that code has to see that there is an additional overload that take a bool parameter called <em>rememberMe</em>.</p>

<p>Consider this longer alternative.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginDoNotRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Instead of overloading <em>Login</em> and making the user have to decide which overload to call and pass in a parameter, we have elected to create two differently named methods which take 0 parameters and clearly state what they are going to do.</p>

<p>I’m not saying you should never write overloads, but anytime you see an overload in your code base, you should stop and think if it would be more clear to make that overloaded method into two different methods that can eliminate one or more of the parameters.</p>

<p><strong>Any time you are restricting the number of choices someone using your code has to make, you are making that code simpler to use.</strong></p>

<p>If you don’t believe me, consider why the iPhone has only one button.</p>

<h5><strong>As always, you can subscribe to this </strong><a href="http://feeds2.feedburner.com/ElegantCode"><strong>RSS feed</strong></a><strong> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at </strong><a href="http://simpleprogrammer.com"><strong>http://simpleprogrammer.com</strong></a><strong>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Say &#8220;No&#8221; to &#8220;Null&#8221;</title>
		<link>http://elegantcode.com/2010/05/01/say-no-to-null/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=say-no-to-null</link>
		<comments>http://elegantcode.com/2010/05/01/say-no-to-null/#comments</comments>
		<pubDate>Sat, 01 May 2010 19:35:05 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/05/01/say-no-to-null/</guid>
		<description><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after. What do you do if "null” [...]]]></description>
			<content:encoded><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after.
<blockquote>What do you do if "null” is passed in?</blockquote>
My answer may turn out to be a bit of a surprise.
<blockquote><span style="background-color: #f4f5f7;">Nothing, I don’t handle nulls in code that I control the use of.</span></blockquote>
“What?  What?” you say.  “You don’t handle null?  What kind of heresy is that?”  It is the kind of heresy that helps produce elegant code and I will show you why.
<h2>How well do you handle null right now?</h2>
Would you say that in most of the code you write you properly check all arguments for null?

Or, do you like most developers, handle null in certain cases when you happen to think about it, or after the application dumps a “null pointer exception” stack trace?

Be honest, look at your code if you have to.

The problem is “d00d ur d0ing it r0ng!”

<a href="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="john-mccarthy-programming-completely-wrong" src="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong_thumb.jpg" border="0" alt="john-mccarthy-programming-completely-wrong" width="349" height="452" /></a>

Unless you are some kind of anal retentive perfectionist, you are probably not handling null in every single method call.  That means there are huge potential bugs in the code that you are writing which will throw null pointer exceptions.  That is bad, I agree.

So, if you are not handling it correctly right now, then what can you do to fix that?
<h2>Avoiding null in the code you “own”</h2>
You can’t control external libraries.  And you can’t control how people will use your code, but you can control the code you write and you can, to a degree, control the code your shop writes.

The better strategy is to never pass null in the first place.

You can either focus your efforts on:
<ul>
	<li>Checking for null</li>
	<li>Not ever passing null</li>
</ul>
<ul>The more elegant solution is to focus on never passing null.  By doing this you will end up writing less code and avoid decisions about how to handle null inside of a method that doesn’t have enough context to decide what to do.</ul>
Let’s look at an example:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> TransmographyThreeStrings(<span class="kwrd">string</span> first, <span class="kwrd">string</span> second, <span class="kwrd">string</span> third)
{
     <span class="kwrd">if</span>(<span class="kwrd">string</span>.isNull(first) || <span class="kwrd">string</span>.isNull(second) || <span class="kwrd">string</span>.isNull(third))
    {
           <span class="rem">// hmm, I donno, what should I do?  Should I throw an exception?</span>
           <span class="rem">// should I return an empty string?</span>
           <span class="rem">// what if the first string wasn't null, can we still do something meaningful?</span>
           <span class="rem">// how will the caller of the method know what I will do?</span>
    }

}</pre>
You can see there that we are checking each parameter for null.  The problem is we don’t know what we should do.  We have lots of options, but none of them are obvious.

How much better is it to make sure that we never pass null into methods, rather than write this kind of code in every method?
<h2>What about accidentally passing in null?</h2>
Many of you are probably thinking at this point that the main way null gets passed into a method is because someone calls a method without knowing that it contains a null value.
<pre class="csharpcode">TransmographyThreeStrings(<span class="str">"Hello"</span>, <span class="str">"World"</span>, mysteryObject.Text);</pre>
Perhaps <em>mysteryObject.Text </em>is null.  You wouldn’t even know it.

Ah, but you can.  Or you can prevent it at least.  Somewhere <em>mysteryObject </em>gets created.  When it gets created its values either get initialized or not.  You can prevent any of its values from being null, several ways:
<ul>
	<li>Always initialize variables when they are declared.</li>
	<li>Use a <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> to ensure that objects are always fully constructed before being created.</li>
	<li>Use properties to provide default values or lazy initialize.</li>
	<li>Make your objects <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> as much as possible.</li>
</ul>
The practices that prevent null from accidentally being passed in make your code much more elegant than repeating <em>if blah == null</em> code all over the place.

<strong>In general, you should always strive to eliminate the passing of null rather than checking for null.  By doing so you reduce extra lines of code in each method, and are forced to use better design practices.</strong>
<h2>Exceptions</h2>
Yes, there are times when you need to check for null.  If you are writing a library that external developers will use, then you will probably want to check for null in all of your methods that are exposed as part of the API.  (On your internal methods, you don’t need to since you have already cleansed the input.)

Also, if your code is being used as a callback to some API and you don’t know if it can ever pass null into your code, you probably should check for null.

A bad excuse is that other developers may pass null to your method. <strong>It is much better as a software shop to put the onus of not passing null on the caller of any method rather than putting it on the writer of the method being called.</strong>

You will also reduce your exception handling code, because you will have less exceptions for invalid parameters.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/05/01/say-no-to-null/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>If Self-Documenting Code is the What, Unit Tests are the Why</title>
		<link>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-self-documenting-code-is-the-what-unit-tests-are-the-why</link>
		<comments>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:09:04 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/</guid>
		<description><![CDATA[It is not enough to just write code that is clean and self-documenting.  Eliminating comments and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it. If you recall from my original post on [...]]]></description>
			<content:encoded><![CDATA[It is not enough to just write code that is clean and self-documenting.  <a href="http://elegantcode.com/2010/04/18/eliminating-comments-the-road-to-clarity/">Eliminating comments</a> and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it.

If you recall from my <a href="http://elegantcode.com/2010/04/09/what-does-elegant-code-mean-to-me/">original post</a> on Elegant code, I stated that elegant code is:
<blockquote>Something that is simple yet effective, delivered with grace.</blockquote>
By writing self-documenting code we are hopefully able to achieve some of the aspects of simplicity and grace, but it tells us nothing about the effectiveness of the code.
<h2>Bringing the dead to life</h2>
<a href="http://elegantcode.com/wp-content/uploads/2010/04/zombies.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="zombies" src="http://elegantcode.com/wp-content/uploads/2010/04/zombies_thumb.jpg" border="0" alt="zombies" width="441" height="295" /></a>

Throwing out comments is a debatable topic.  <a href="http://www.reddit.com/r/programming/comments/bsutx/">It raises quite a bit of controversy</a>, as you can see from some of the comments on my post about the subject.  The reason, perhaps, that so many people are so staunchly opposed to the idea, is because they are worried, and rightly so, that throwing out comments will reduce the documentation of what the code is doing.

Think about that for a second.  Is documentation of what the code is doing important?  It better be.  What we are trying to accomplish by writing self-documenting code instead of comments, is to take the vessel, which is the code itself, and make that same vessel be the documentation of what the code does.  It is by doing this that we creating a living representation of the functionality of the code.  Comments are akin to a dead representation of the functionality of the code because they do not change automatically with the code.

I diverge to talk about comments so that I can draw a parallel to another form of documentation which is valuable and should be considered necessary.  That other set of documentation is requirements.  Have you ever written requirements documents?  Have you ever captured requirements from the customer and put them into UML diagrams, or perhaps plopped them into some templated Word document, which is never updated again, and no one reads, because no one trusts it is correct?  Wouldn’t it be great if we would replace that dead document or set of documents, with a living one?

The good news is we can, and some of us have.  And I fully expect this recommendation will be just as controversial, because <strong>I am suggesting that we don’t have to write low level specifications of the system at all, instead we can write good unit tests. </strong>When we do this, we are taking a dead form of document and bringing it to life.
<h2>Unit tests tell us why and how our code is effective</h2>
If
<pre class="csharpcode">i = 5;  // Widget count defaults to five.</pre>
is replaced with
<pre class="csharpcode">widgetCount = DEFAULT_WIDGET_COUNT;</pre>
<!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

then
<blockquote><span style="background-color: #ffffff;">1.1.5 When a new widget is created, the widget count should be increased by one.</span></blockquote>
is replaced with
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> When_NewWidgetIsCreated_Then_WidgetCountIsIncreasedByOne()
{
     WidgetFactory.Count = 3;
     WidgetFactory.CreateNew();
     assertEquals(4, WidgetFactory.Count);
}</pre>
The unit test is replacing the low level requirement, which is somewhat open to interpretation and untied to the code, with an absolute and completely tied-to-the-code, specific requirement.

The unit test is telling us why our code is built the way it is.  It is telling us what requirement that particular structure of code is trying to address.  <strong>It is telling us what end result that code is trying to accomplish and what the expectations are on the results of a given condition.</strong>

The unit test is telling us how the code is to be used in order to achieve its result.  It is serving as a living reference to the syntax and use of the code we built.  <strong>Instead of providing instructions on how to use our API, we are providing a living example, and proof that it will indeed work.</strong> Examples are often much more effective than instructions anyway.
<h2>What exactly are we replacing?</h2>
At this point we are not trying to replace all the documentation of the system (at this point).

With self-documenting code, we sought to eliminate comments, and replace them with good variable and method names.

With unit tests, we seek to eliminate technical documentation and requirements of the system, that is targeted at a developer or technical audience.

We are NOT trying to eliminate high level specifications of the system, or use cases. <strong>Unit tests DO NOT replace that kind of documentation! </strong>We will talk about replacing that kind of documentation when we talk about automated functional or system tests.

Simply put, any kind of documentation that you would give to a developer so they understand how the system works and how to use the code or APIs, can be easily replaced by writing good unit tests.

Our simple goal is to replace the “dead” documentation (meaning that it does not update automatically with the thing it is documenting), with “living” documentation in the form of unit tests.

One last point.  I want to be clear that I am not saying that having unit tests automatically results in the ability to replace technical documentation.  Just like having long-named methods and variables doesn’t automatically replace the need for comments.  It is a matter of the quality of the unit tests that are written, just as it is a matter of the quality of the self-documenting code.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>REST: Resources, URI&#8217;s and Representations</title>
		<link>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rest-resources-uris-and-representations</link>
		<comments>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 04:00:13 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/</guid>
		<description><![CDATA[In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions. Resources Resources are at the heart of REST.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions.</p>  <h3>Resources</h3>  <p>Resources are at the heart of REST.&#160; You are already used to resources as a web browsing consumer.&#160; A resource is not something specific to REST, instead it is the first thing you probably want to consider when architecting a RESTful application.&#160; A resource is simply the entity, item, or thing you want to expose.</p>  <p>Perhaps you have approached application architecture using one or many of several modeling and design techniques.&#160; Data First practitioners typically begin with databases and data models.&#160; DDD proponents like to begin by modeling around business entities and interactions, while their cousins in the BDD camp model around business activities.</p>  <p>When you decide to apply REST you will need to think a lot more about data entities and domain objects as resources.&#160; Your existing models may or may not closely map to resources.&#160; The shift in thinking may appear slight, but is very important.&#160; It centers around making things&#160; addressable.&#160; Each resources must by uniquely identifiable as we will see in the next section.&#160; We are used to identity with most data entities, but our domain objects may not always be as easily identifiable.&#160; Likewise, our data entites may have identity, but not map to a resource.&#160; </p>  <p>Consider the classic customer and order scenario for example.&#160; If each customer and each order can be identified then it will be easy to design RESTful systems around them.&#160; However, if the model requires a lot of context then our challenge is a little bit larger.&#160; Perhaps we must first identify a partner, then a year, then a customer, and finally the order.&#160; Yes, that is a design smell in general.&#160; It makes fetching an order very difficult.&#160; Developing RESTfuly would only further expose that difficulty.&#160; Identifying your resources up front will help you reduce the possible impedance mismatches you might end up with between what you want to expose and your data or domain models.</p>  <p>REST is about interacting with Resources!</p>  <h3>URI’s</h3>  <p>REST defines the identity of a resource via URI.&#160; Each resources has a unique address in URL form (ie. using the http protocol).&#160; Interaction with a resource will take place at its URI.&#160; As an example, my twitter status feed resource URI is <a title="http://twitter.com/optionstrict" href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; That URI is unique to my feed and that is what you expect to find at that URI.&#160; In the Twitter databases or domain models my account may be referred to by the string optionstrict, or perhaps as some random number or guid.</p>  <p>To consume my status history via a service interface twitter provides another URI at <a title="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict" href="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict">http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict</a>.&#160; I would actually prefer to have access at the same URI for html, json, and xml formats.&#160; Twitter probably has its reasons for distinguishing API access from HTML rendering, but they have actually complicated their architecture by doing so.&#160; When designing the URI’s for your resources, make them easy for your users to work with.&#160; </p>  <h3>Representation</h3>  <p>Lets continue with the twitter example to describe what is meant by Representation.&#160; Given a URI and a Resource, what will your consumers receive when they issue a GET request to the URI?&#160; Twitter chose a representation of my account and included status history and profile for the response at <a href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; They decided to put a representation of my profile photo at <a title="http://twitter.com/account/profile_image/optionstrict" href="http://twitter.com/account/profile_image/optionstrict">http://twitter.com/account/profile_image/optionstrict</a>.&#160; In your REST solutions you will need to consider how you want to represent a resource at its URI.&#160; Each representation will have a unique URI.&#160; </p>  <p>Representations are also important for manipulating resources.&#160; You must define the representation required to create and update resources.&#160; Twitter status updates require a text representation with a maximum of 140 characters.&#160; They allow additional values in the status representation, such as latitude and longitude.&#160; Your REST solutions similarly must define representations for Requests and Responses.</p>  <p>I hope that this short introduction has helped you to see that the core essence of REST is simple and fairly obvious.&#160; As you look at your current solutions what are the resources you are exposing?&#160; Could you make those resources identifiable by URI?&#160; What representation would you place at each URI?&#160; What representation would you require for manipulating a given resource?</p>  <p>Also, notice I did not mention much about data formats, Content Type, Mime, etc.&#160; Those details can cloud your design if you try to start with them. If you can’t wait for my post about how REST handles html, json, xml from the same URI, then start googling Content Negotiation, Accept header, and Content-Type header.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Driven Architecture: Publishing Events using an IOC container</title>
		<link>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rest-resources-uris-and-representations</link>
		<comments>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 04:00:13 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/</guid>
		<description><![CDATA[In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions. Resources Resources are at the heart of REST.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions.</p>  <h3>Resources</h3>  <p>Resources are at the heart of REST.&#160; You are already used to resources as a web browsing consumer.&#160; A resource is not something specific to REST, instead it is the first thing you probably want to consider when architecting a RESTful application.&#160; A resource is simply the entity, item, or thing you want to expose.</p>  <p>Perhaps you have approached application architecture using one or many of several modeling and design techniques.&#160; Data First practitioners typically begin with databases and data models.&#160; DDD proponents like to begin by modeling around business entities and interactions, while their cousins in the BDD camp model around business activities.</p>  <p>When you decide to apply REST you will need to think a lot more about data entities and domain objects as resources.&#160; Your existing models may or may not closely map to resources.&#160; The shift in thinking may appear slight, but is very important.&#160; It centers around making things&#160; addressable.&#160; Each resources must by uniquely identifiable as we will see in the next section.&#160; We are used to identity with most data entities, but our domain objects may not always be as easily identifiable.&#160; Likewise, our data entites may have identity, but not map to a resource.&#160; </p>  <p>Consider the classic customer and order scenario for example.&#160; If each customer and each order can be identified then it will be easy to design RESTful systems around them.&#160; However, if the model requires a lot of context then our challenge is a little bit larger.&#160; Perhaps we must first identify a partner, then a year, then a customer, and finally the order.&#160; Yes, that is a design smell in general.&#160; It makes fetching an order very difficult.&#160; Developing RESTfuly would only further expose that difficulty.&#160; Identifying your resources up front will help you reduce the possible impedance mismatches you might end up with between what you want to expose and your data or domain models.</p>  <p>REST is about interacting with Resources!</p>  <h3>URI’s</h3>  <p>REST defines the identity of a resource via URI.&#160; Each resources has a unique address in URL form (ie. using the http protocol).&#160; Interaction with a resource will take place at its URI.&#160; As an example, my twitter status feed resource URI is <a title="http://twitter.com/optionstrict" href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; That URI is unique to my feed and that is what you expect to find at that URI.&#160; In the Twitter databases or domain models my account may be referred to by the string optionstrict, or perhaps as some random number or guid.</p>  <p>To consume my status history via a service interface twitter provides another URI at <a title="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict" href="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict">http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict</a>.&#160; I would actually prefer to have access at the same URI for html, json, and xml formats.&#160; Twitter probably has its reasons for distinguishing API access from HTML rendering, but they have actually complicated their architecture by doing so.&#160; When designing the URI’s for your resources, make them easy for your users to work with.&#160; </p>  <h3>Representation</h3>  <p>Lets continue with the twitter example to describe what is meant by Representation.&#160; Given a URI and a Resource, what will your consumers receive when they issue a GET request to the URI?&#160; Twitter chose a representation of my account and included status history and profile for the response at <a href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; They decided to put a representation of my profile photo at <a title="http://twitter.com/account/profile_image/optionstrict" href="http://twitter.com/account/profile_image/optionstrict">http://twitter.com/account/profile_image/optionstrict</a>.&#160; In your REST solutions you will need to consider how you want to represent a resource at its URI.&#160; Each representation will have a unique URI.&#160; </p>  <p>Representations are also important for manipulating resources.&#160; You must define the representation required to create and update resources.&#160; Twitter status updates require a text representation with a maximum of 140 characters.&#160; They allow additional values in the status representation, such as latitude and longitude.&#160; Your REST solutions similarly must define representations for Requests and Responses.</p>  <p>I hope that this short introduction has helped you to see that the core essence of REST is simple and fairly obvious.&#160; As you look at your current solutions what are the resources you are exposing?&#160; Could you make those resources identifiable by URI?&#160; What representation would you place at each URI?&#160; What representation would you require for manipulating a given resource?</p>  <p>Also, notice I did not mention much about data formats, Content Type, Mime, etc.&#160; Those details can cloud your design if you try to start with them. If you can’t wait for my post about how REST handles html, json, xml from the same URI, then start googling Content Negotiation, Accept header, and Content-Type header.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Elegant Code &#187; Architecture</title>
	<atom:link href="http://elegantcode.com/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quinine For Sale</title>
		<link>http://elegantcode.com/2012/01/18/monitoring-an-mmo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-an-mmo</link>
		<comments>http://elegantcode.com/2012/01/18/monitoring-an-mmo/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:45:32 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MMO]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2012/01/18/monitoring-an-mmo/</guid>
		<description><![CDATA[I’ve been working on a free-to-play MMO Quinine For Sale, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I’ve been working on a free-to-play <a href="http://www.heroup.com" target="_blank">MMO</a> <b>Quinine For Sale</b>, which has been “officially” live since last April, and things have been going well – a steady growth of players; the game itself has been well-received, and all the important graphs are “up and to the right.”&#160; Part of my job involves detecting problems before they become serious and fixing problems when they inevitably do.&#160; So, there are two questions.&#160; “Is there a problem in the game?” “What is causing the problem?”&#160; </p>  <p>When trying to debug something on our development and test clusters, typically you can tail log files.&#160; We have a python script that can monitor the communication between various parts of the game and pretty-print it along with color to highlight “this is a problem!”&#160; Attaching a debugger to a running process is also not uncommon.&#160; However, looking at logs and bus traffic in realtime on a production environment gives you this neat “Matrix-y” experience.&#160; Attaching a debugger to a production process (assuming you could, which you can’t) would get you smacked with a rolled-up newspaper.&#160; “Bad Developer!&#160; No treat!”&#160; So, what can you do?</p>  <h4>Monitoring</h4>  <p>When you’ve got clusters full of machines, using <a href="http://www.nagios.org/" target="_blank">Nagios</a> to monitor things is an obvious solution.&#160; Beyond making sure the power is on and other sysadmin things, we’ve written other checks to see if the login process is working, the parts are working together, and automating typical in-game functions.&#160; For example, if nagios can’t successfully log into the game do basic game activity, then alerts happen.</p>  <h4>Metrics for EVERYTHING</h4>  <p>Anything that happens in game has metrics reporting tied to it, generating piles of data constantly.&#160; We use <a href="http://www.cacti.net/" target="_blank">Cacti</a> to visualize game activity.&#160; An example metric is concurrent users, or CCU.&#160; We graph how many people are in the game over time, which when things are healthy should be a nice smooth curve climbing to peak game hours, then descending nicely through the night.</p>  <p>We can tell by sight if the game looks healthy or not – if the CCU graph is jaggy, has a sudden drop or spike, or drops to zero then we know that something is wrong.&#160; Typically nagios alerts accompany the graphs, giving more data points on where to look.&#160; But this has also pointed out areas where a nagios check was missing or wasn’t working as intended.</p>  <h4>Log Files</h4>  <p>When a player gets an error in game, the error dialog box gives them the opportunity to submit the error details back to us.&#160; If we see a spike in user-reported errors through this or other customer service means, we know we have something of interest to look for.&#160; </p>  <p>The game server components make use of log4j and similar logging frameworks.&#160; Anything that you’d want to watch happening in game needs to be aggressively logged.&#160; All components are configured so that operations can change the log level on the fly.&#160; That’s still quite a bit of data across many machines though, so all that information is run through <a href="http://www.splunk.com/product" target="_blank">Splunk</a> to be indexed and searchable.&#160; This gives us a great tool for searching through log data, examining trends, or watching selected activity in real time.&#160; Unfortunately it is very expensive so we are selective about the data that passes through it.&#160; </p>.  Buy Quinine from mexico.  Buy Quinine no prescription.  No prescription Quinine online.  Online buying Quinine.  Quinine no prescription.  Quinine street price.  Buy no prescription Quinine online.  Quinine coupon.  Quinine over the counter.  Where can i buy Quinine online.  Quinine steet value.  Where to buy Quinine.  Order Quinine online overnight delivery no prescription.  Quinine recreational.  Quinine canada, mexico, india.  Ordering Quinine online.  Quinine without prescription.  Quinine price, coupon.  Quinine description.  Order Quinine from mexican pharmacy.  Quinine pics.  What is Quinine.  Japan, craiglist, ebay, overseas, paypal.  Order Quinine from United States pharmacy.  Order Quinine online c.o.d.  Quinine trusted pharmacy reviews.  Quinine treatment.  Buy Quinine from canada.  Quinine used for.  Discount Quinine.  Is Quinine addictive.  Quinine forum.  Buy Quinine online no prescription.  Is Quinine safe.  Purchase Quinine for sale.  Effects of Quinine.  Buy Quinine online cod.  Quinine australia, uk, us, usa.  Buy Quinine without prescription.  Quinine online cod.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4721'>Buy Flonase Without Prescription</a>. <a href='http://elegantcode.com/?p=4234'>Buy Periactin Without Prescription</a>. <a href='http://elegantcode.com/?p=4203'>Buy Armour Without Prescription</a>. <a href='http://elegantcode.com/?p=4899'>Buy Macrobid Without Prescription</a>. <a href='http://elegantcode.com/?p=4534'>Xalatan For Sale</a>. <a href='http://elegantcode.com/?p=4302'>Phenergan wiki</a>. <a href='http://elegantcode.com/?p=4268'>Soma maximum dosage</a>. <a href='http://elegantcode.com/?p=4602'>Zovirax treatment</a>. <a href='http://elegantcode.com/?p=4578'>Cialis price, coupon</a>. <a href='http://elegantcode.com/?p=4189'>Flexeril price</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.leaduganda.org/?p=514'>Quinine For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=4820'>Quinine For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2780'>Quinine For Sale</a>. <a href='http://www.thegriffonnews.com/?p=10177'>Quinine For Sale</a>. <a href='http://www.independentworldreport.com/?p=2409'>Quinine For Sale</a>. <a href='http://changecamp.ca/?p=295'>Quinine description</a>. <a href='http://social-blend.com/?p=624'>Quinine price, coupon</a>. <a href='http://blog.farmland.org/?p=3946'>Online buying Quinine hcl</a>. <a href='http://4realz.net/?p=1595'>Quinine from canada</a>. <a href='http://reversemortgagedaily.com/?p=14535'>Where to buy Quinine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2012/01/18/monitoring-an-mmo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Temovate Cream For Sale</title>
		<link>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-software-development-will-never-be-engineering</link>
		<comments>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 03:37:48 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/</guid>
		<description><![CDATA[I always find it rather interesting when academics try to quantify generalized metrics about software development. Temovate Cream For Sale, Things like: per lines of code, there will be X number of bugs. Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.” These are all interesting [...]]]></description>
			<content:encoded><![CDATA[<p> <p>I always find it rather interesting when academics try to quantify generalized metrics about software development.</p>  <p> <b>Temovate Cream For Sale</b>, Things like: per lines of code, there will be X number of bugs.</p>  <p>Statements like: it has been empirically proven that “blah” affects the development of software in some way “blah.”</p>  <p>These are all interesting thoughts, but software development will never conform to rigid engineering principles like many other engineering practices.&#160; The longer I work in the field, the more and more I realize that software development has nothing to do with engineering.&#160; We just happen to attend some of the same math classes in school.</p>  <h2>Building bridges</h2>  <p>One of the main arguments I hear people make about the current state of software development as an engineering practice is based around its relative maturity to other engineering fields.</p>  <p>There is a huge problem with this line of thinking.</p>  <p>The argument goes something like this:&#160; “<em>Engineering has been around for hundreds of years and has matured to the point where it is a measurable science, but software development has only been around in earnest for the last few decades or so, therefore it is relatively immature as an engineering discipline.”</em></p>  <p>On the surface this argument seems sounds.&#160; And certainly in 50 years software development will be different than it is now.&#160; Heck, it is much more different than it was just 10 years ago.</p>  <p>But, here is the problem.&#160; We build much more software than we do bridges.</p>  <p><img src="http://www.nps.gov/glca/historyculture/images/Navajo_Bridges_1.gif" width="589" height="442" /></p>  <h6 align="center">&#160;</h6>  <p>Let me give you an example that came to light in another area of my interest… poker.</p>  <h1></h1>  <h2>The poker quickening</h2>  <p>An interesting thing happened in the poker community in the last 10 years; poker pros with decades of experience started getting beat time and time again by 19 year old poker prodigies.</p>  <p>From an outside perspective it looks like the poker world opening up just widened the search for talent and there it was.&#160; But, a closer examination of the evidence leads to the truth.</p>  <p>Before the online poker industry was born, poker was played in card rooms and casinos in states where it was legal and occasionally at small home games throughout the US.</p>  <p>A poker pro might play poker tournaments perhaps 100 times to 150 times a year.&#160; The sum knowledge of the poker community and the meta game around it was based on this base of professional poker players playing tournaments and gaining experience at this mediocre rate.</p>  <p>Once the internet poker rooms started opening up, things changed, and they changed rapidly.&#160; Now anyone could play poker from their home PC.&#160; Not only could they play poker, they could play poker tournaments at all hours of the day.</p>  <p>Here is a list of some of the major changes that took place:</p>  <ul>   <li>Hands are dealt at 60-80 hands per hour instead of 10-30</li>    <li>Players can play in many tournaments at one time, 10 tournaments at once is not unheard of</li>    <li>Players can analyze hand histories and historical data about their play and opponents play through the use of software </li>    <li>Age requirements are out the window, technically any one of any age could be playing online</li>    <li>Players can play 24 hours a day</li>    <li>The professional online tournament player could easily play over 3000 tournaments in a year, while a brick and mortar pro would be lucky to reach 100 in a year.</li>   <img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://t1.gstatic.com/images?q=tbn:ANd9GcRj9uGNWSyqGWEneiH6xaBAyS6COwGYicdNadZu-06KWQLhIi6LMw&amp;t=1" width="316" height="270" /></ul>  <p>&#160;</p>  <p>So where am I going with all this?</p>  <p>The point is that as a whole more hands were dealt and more poker knowledge and experience was obtained in 1 year of online poker than probably the entire history of poker before that.&#160; We reached such an accelerated pace of play that all previous knowledge of poker became obsolete.&#160; </p>  <p>The strategy of tournament poker completely changed.&#160; The game evolved perhaps 500 years into the future in a matter of 5 years time.</p>  <p>The same has happened with software development.</p>  <h2>Back to the bridge building</h2>  <p>So let’s take that poker example and look at it through the lens of software development.</p>  <p>Let us compare the engineering maturity to software development to the engineering maturity of the engineering discipline of building bridges.</p>  <p>I think most people would agree that bridge building is a very mature engineering discipline but many people would argue that software development is not.</p>  <p><strong>How many bridges do you think have been built in the world?</strong></p>  <p>Well there are <a href="http://www.betterroads.com/category/bridge-inventory/erroads.randallreillycms.com/files/2009/11/BR1109_BridgeInventory.pdf">about 600,000 bridges in the United States alone</a>, so the world figure must be at least somewhere around 10 times that number perhaps 20.</p>  <p><strong>How many software programs have been written?</strong></p>  <p>This is a very hard number to estimate, but lets take a rough guess based on <a href="http://stackoverflow.com/questions/453880/how-many-developers-are-there-in-the-world">how many software developers there are in the world</a>.&#160; </p>  <p>If we say there are about 12 million software developers and each software developer has written approximately 3 programs, we can estimate that a large amount more programs have been written than bridges built.</p>  <p>My point is not to knock bridge building, we are pretty good at it as a whole, but rather to show that collectively, even though we have been building bridges for hundreds of years, we have probably devoted an equivalent amount of time to building software.</p>  <p>This line of thinking may lead you to argue back that software development and bridge building are very different.&#160; Bridge building has a fixed set of requirements that are pretty close to the the same for each bridge you build, but software development is a big open void of whims and ambiguously contradictory statements.</p>  <p>I agree with you 100%!&#160; And in essence that is my point.</p>  <h2>Software development is different</h2>  <p>And we have had enough time to realize that.&#160; Waiting for software development to gel into some kind of engineering discipline like other engineering disciplines is like waiting for water without gelatin mix to turn into Jello.&#160; </p>  <p>It’s just not going to happen!</p>  <p>In my mind it is clear that the argument that we haven’t given it enough time is just wishful thinking.&#160; The nature of software development, just like online poker, leads itself to rapid evolution.</p>  <p>Consider what direction software development is evolving.&#160; Is it even evolving in the direction of rigid engineering practices or is it evolving in the exact OPPOSITE direction?</p>  <p>Ten years ago, we tried to use UML diagrams and CASE tools to develop software.&#160; Ten years ago waterfall was all the rage.&#160; Ten years ago, we thought that ten years in the future we would have programs that would allow us to build software in the same way that CAD tools allow for building machine parts.</p>  <p>Not only did it not happen.&#160; It went completely the other way.&#160; Now we are all talking about Agile.&#160; Now people don’t even remember what CASE tools are.&#160; Now we are building software without trying to define the whole system in UML diagrams.</p>  <p><strong>The fact of the matter is software systems are unruly beasts!</strong></p>  <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://aznbadger.files.wordpress.com/2010/06/beast.jpg" /></p>  <p>In my mind it comes down to one simple distinction.&#160; Software is living, bridges aren’t.&#160; When you are done building a bridge, you are done building the bridge.&#160; </p>  <p>Sure someone, probably not you, will have to come along and do some routine maintenance on it.&#160; Sure, some small things might change about it, but for all intents and purposes the work is done.</p>  <p>In most software development scenarios, this is not the case.&#160; In most software development scenarios, releasing V1 is not even close to the end.&#160; Sometimes V1 and V2 don’t even look that same at all.&#160; Software development is about operating on a living breathing thing and all the while keeping it alive.</p>  <p>The truth is, we software developers have more in common with surgeons than with other engineers.</p>  <h6>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com/">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>.  Buy Temovate Cream without a prescription.  Temovate Cream trusted pharmacy reviews.  Temovate Cream over the counter.  Where can i order Temovate Cream without prescription.  Online buy Temovate Cream without a prescription.  Temovate Cream no rx.  Buy cheap Temovate Cream no rx.  Temovate Cream photos.  Buy Temovate Cream online no prescription.  Order Temovate Cream online c.o.d.  Herbal Temovate Cream.  About Temovate Cream.  Australia, uk, us, usa.  Cheap Temovate Cream.  Temovate Cream class.  Temovate Cream brand name.  Online Temovate Cream without a prescription.  Buy Temovate Cream without prescription.  Buy Temovate Cream from canada.  After Temovate Cream.  Order Temovate Cream from mexican pharmacy.  Temovate Cream without a prescription.  Purchase Temovate Cream.  Temovate Cream natural.  Temovate Cream overnight.  Temovate Cream online cod.  Where can i buy cheapest Temovate Cream online.  Purchase Temovate Cream for sale.  Online buying Temovate Cream.  Purchase Temovate Cream online.  Temovate Cream used for.  Temovate Cream coupon.  Temovate Cream description.  Order Temovate Cream no prescription.  Temovate Cream maximum dosage.  Cheap Temovate Cream no rx.  Temovate Cream images.  Temovate Cream blogs.  Buy Temovate Cream online cod.  Buy generic Temovate Cream.</p>
<p></p>
<p><b>Similar posts:</b> <a href='http://elegantcode.com/?p=4472'>Bactroban For Sale</a>. <a href='http://elegantcode.com/?p=4632'>Armour For Sale</a>. <a href='http://elegantcode.com/?p=4639'>Buy Estrace Vaginal Cream Without Prescription</a>. <a href='http://elegantcode.com/?p=4668'>Buy Augmentin Without Prescription</a>. <a href='http://elegantcode.com/?p=4535'>Buy Tindamax Without Prescription</a>. <a href='http://elegantcode.com/?p=4931'>Fast shipping Diclofenac</a>. <a href='http://elegantcode.com/?p=4240'>Combivent brand name</a>. <a href='http://elegantcode.com/?p=4417'>Levaquin overnight</a>. <a href='http://elegantcode.com/?p=4597'>Purchase Toradol online</a>. <a href='http://elegantcode.com/?p=4221'>Australia, uk, us, usa</a>.<br />
<b>Trackbacks from:</b> <a href='http://www.quarterlives.com/?p=1148'>Temovate Cream For Sale</a>. <a href='http://4realz.net/?p=1972'>Temovate Cream For Sale</a>. <a href='http://www.macneilbmx.com/blog/?p=5997'>Temovate Cream For Sale</a>. <a href='http://www.greatgreengoods.com/?p=2476'>Temovate Cream For Sale</a>. <a href='http://www.thegriffonnews.com/?p=9947'>Temovate Cream For Sale</a>. <a href='http://social-blend.com/?p=1160'>Temovate Cream brand name</a>. <a href='http://blog.farmland.org/?p=3812'>Where can i find Temovate Cream online</a>. <a href='http://reversemortgagedaily.com/?p=14136'>Generic Temovate Cream</a>. <a href='http://linuxologist.com/?p=1792'>Temovate Cream photos</a>. <a href='http://home.officesnapshots.com/?p=114'>Order Temovate Cream from mexican pharmacy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/06/22/why-software-development-will-never-be-engineering/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
		<item>
		<title>Christmas Light Architectures Are Not That Shiny</title>
		<link>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=christmas-light-architectures-are-not-that-shiny</link>
		<comments>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:00:00 +0000</pubDate>
		<dc:creator>Jan Van Ryswyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/</guid>
		<description><![CDATA[I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way [...]]]></description>
			<content:encoded><![CDATA[<p>I just want to get something of my chest that is bothering me for quite some time now. It’s not going to be a rant of some sort, but merely a couple of observations for which I couldn't find the right words to describe things up until this point. In short: this post is way overdue :-).</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb1.png" width="202" height="172" /></a> </p>  <p><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a><a href="file:///C:\Users\JanVanRyswyck\AppData\Roaming\Windows%20Live%20Writer\PostSupportingFiles8e7174-33ed-4def-8d4c-61f9b172c5e8274611.jpg"></a>What's the major malfunction with those old, classic Christmas lights? We've all experienced it at some point. When one goes out, all the others go out as well. This is due to the fact that these lights are wired in series. The difference compared with today's Christmas lights is that every bulb has a shunt, which basically prevents this kind of failure caused by one or more lamps. Enough about the Christmas lights for now. Where am I going with this? Back in enterprise IT, I'm seeing the same kind of failures as with those classic, old Christmas lights.</p>  <p>The diagram below shows a classic RPC style architecture, much like those classic, old Christmas lights. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb2.png" width="565" height="329" /></a> </p>  <p>This is all fine and dandy as long as every part of the chain runs without too much hassle. But what happens if for some reason the centralized back-end web service goes down (light bulb goes out). This means that every smart client, website and batch application that uses this web service gets affected by this, like some sort of chain reaction. Parts of these client applications will no longer function correctly or they might even go down entirely. Same thing happens when the database of the centralized back-end web service goes down or any other external system that it depends on. When being confronted with this kind of architecture, how would one go about preventing this doomsday scenario to happen?</p>  <p>Suppose you’re a developer that has to work on the centralized back-end web service. This is usually a complex system as it obviously has to provide features for all kinds of applications. When this centralized back-end web service also has to deal with and depend on other external systems that might expose some unexpected behavior, how could one prevent the sky from falling down when things go awry in production?</p>  <p>Well for starters, you could start building in some stabilization points. Suppose for some reason, the centralized web service needs to incorporate some functionality offered by a highly expensive, super enterprise system that for some reason behaves very unstable and unpredictably on every full moon (expensive enterprise software not behaving correctly sounds ridiculous, but bare with me ;-) ). For example, we could use a message queue as a stabilization point. </p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/12/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/12/image_thumb3.png" width="570" height="157" /></a> </p>  <p>This means that we put a message on a queue that is processed by some sort of worker process or service that does the actual communication with the misbehaving system. When the external system goes down, the message is either left on the message queue or put on an error queue for later processing when the external system comes back up again. There are some other things you need to think about like idempotent messaging, consistency, message persistence when the server goes down, etc. … . But if one of these dependencies goes down, the centralized back-end web service is still up-and-running which means that the systems that depend on its functionality can also continue to serve their users as they are able to keep doing their work.</p>  <p>Earlier this week I overheard this conversation that somewhat amazed me. I changed the names of the persons involved as well as the exact words used in order to protect the guilty.</p>  <blockquote>   <p><em>George: </em><em>We want to incorporate a message queue in order to guarantee stability and&#160; integrity between several non-transactional systems that our system depends on. It will also improve performance as these systems behave very slow at times and become unstable under pressure. This also gives us the opportunity to root out some major points friction that our end-users are experiencing right now.</em></p>    <p><em>Stan: But this means that the end-users are not completely sure if their actions are indeed fully carried out by the system. </em></p>    <p><em>George: End-users can always check the current state of affairs in their applications. If something goes wrong, their request is not lost and things will get fixed automatically later on as soon as the cause of the error has been fixed. </em></p>    <p><em>Stan:&#160; I don’t think that’s a very good idea. End-users have to wait until everything is processed synchronously, even if that means that they’ll need to wait for a long time. And if one of the external systems goes down, they should stop sending in new requests. Everything should come to a halt. They just have to stop doing what they are doing.</em></p>    <p><em>George: This means that because you lose the original request, some external systems might be set up correctly while others are not. Then someone has to manually fix these issues.</em></p>    <p><em>Stan: Then so be it!</em>&#160;</p> </blockquote>  <p>For starters, I was shocked by this conversation. This is just insane. Everything should come to a halt? Think about this scenario for a while: suppose you’re finding yourself in a grocery store with a cart full of food, drinks and other stuff. You come at the cash register where the lady kindly says “Can you put everything back on the shelves please? There are some issues with the cash register software and we are instructed to stop scanning items and serve customers until these issues are fixed. Can you come back tomorrow please?”. Uhm, no! How much money do you think this is going to cost compared to the system that makes use of stabilization points? An end-user that is able to keep doing its work, whether the entire production system is down or not has tremendous business value. </p>  <p>I’m not saying that message queues are a silver bullet. I’m just using these as an example. As always, there is a time and place for using them. There are other things a developer can incorporate in order to increase the stability of the system he’s working on, like <a href="http://davybrion.com/blog/2008/05/the-circuit-breaker/" target="_blank">the circuit breaker pattern</a>. I’m also not saying that every system should be built using every stabilization point one can think of. This become a business decision depending on the kind of solution. As usual, it depends.</p>  <p>But the point that I’m trying to make here is that we should stop putting software systems into production and just hoping for the best. That’s just wishful thinking. Software systems are going to behave badly and at some point they will go down. It’s just a matter of when this is going to happen and how much damage this is going to make.</p>  <p>The first step to take is awareness. I encourage you to pick up this book titled ‘<a href="http://www.amazon.com/exec/obidos/ASIN/0978739213/elegantcode-20" target="_blank">Release It!</a>’, written by <a href="http://www.michaelnygard.com/" target="_blank">Michael Nygard</a>. This book is all about designing software that can survive this though environment called production. I can only hope that Stan picks up a copy as well along with some common sense.</p>  <p>Till next time.&#160;&#160;&#160; </p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/12/17/christmas-light-architectures-are-not-that-shiny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Could sealing a class be a sign of a good design</title>
		<link>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=could-sealing-a-class-be-a-sign-of-a-good-design</link>
		<comments>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 21:50:15 +0000</pubDate>
		<dc:creator>Andreas Håkansson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/</guid>
		<description><![CDATA[I recently attended this years Øredev conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, Philip Laureano. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended this years <a title="Read more about the Øredev conference" href="http://oredev.com/2010" target="_blank">Øredev</a> conference and one of the things I had the good fortune of doing was to meet-up with a long time twitter friend, <a title="Visit the twitter profile of Philip Laureano" href="http://twitter.com/philiplaureano" target="_blank">Philip Laureano</a>. One of the days me and Philip started talking about a previous discussion he had with another attendee (whom shall remain nameless since I do not know the full details of his exact opinions). Anyway, the short version is that the person suggested that classes should be sealed by default, or at least have the developer explicitly state if the class should be sealed or closed.</p>  <p>My immediate reaction was that this was a terrible idea and that I had been struck down too many times by sealed classes before. But then I started thinking that maybe it was not such a bad idea after all. Maybe it even was a sign of a well designed class and that more developers would be better of by sealing their classes.</p>  <p>Now let me inform you that I am still on the ropes about this, but I would like your thoughts on it. In fact I am hoping that the most interesting part of this post will end up being the discussion in the comment section.</p>  <p>So when you take a moment to think about the <em>S.O.L.I.D principles</em>, most specifically the <em>Open-Closed Principle</em> and <em>Dependency Inversion Principle</em>, a long with the old design principle of ‘Favor <a href="http://en.wikipedia.org/wiki/Object_composition">object composition</a> over <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)">class inheritance</a>’ then maybe it is not such a bad thing after all. Throw in interfaces into the mix and program to an interface and not an implementation, and it will enables you to create different branches if needed. If your classes can flourish while being sealed, chances are that you have some pretty nice structures code in your hands.</p>  <p>There probably are some legit reasons to not seal classes at time, despite the reasoning above, so I am not going to be definitive and say that is never the case. Voice your thoughts in the comments and let us see where this ends up – who knows, I might be left standing as a fool!</p>  <p>As always, you can find me on twitter by the name of <a title="Visit me on twitter" href="http://twitter.com/thecodejunkie" target="_blank">@thecodejunkie</a></p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/11/13/could-sealing-a-class-be-a-sign-of-a-good-design/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
		<comments>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 22:40:49 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/</guid>
		<description><![CDATA[Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended? I was working on building an automated testing framework for a welfare system in which cases could be added [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written an API or a method and expected it to be used a certain way, but then found people doing all kinds of bad things with your precious API that you never intended?</p>  <p>I was working on building an automated testing framework for a welfare system in which cases could be added and benefits run for a given month.</p>  <p>A typical scenario might be something like:</p>  <ol>   <li>Create a new case for this month. </li>    <li>Add some people, do some things. </li>    <li>Run benefits for this month. </li>    <li>Run benefits for the next month.&#160; Something should happen because the child on the case is now 19. </li> </ol>  <p>Seems pretty straightforward until you consider what happens if someone hard codes dates into the test.</p>  <p>I am sure you can imagine plenty of scenarios in a situation like this where hard coded dates would eventually cause all kinds of problems.</p>  <p>The problem is… </p>  <p><strong>If you create an API which takes in various dates, how do you ensure the dates passed in are calculated and not just hard coded?</strong></p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pigsinblanket" border="0" alt="pigsinblanket" src="http://elegantcode.com/wp-content/uploads/2010/07/pigsinblanket_thumb.jpg" width="514" height="514" /></a> </p>  <h2>Why convention doesn’t work</h2>  <p>Your first response might be to create some documentation that describes the importance of making dates “float” forward with time, and not be hard coded.</p>  <p>You might clearly describe how you should not hard code July 7th 1990 to be the birth date of a 20 year old for a test case.</p>  <p>You might give some guidelines of how to properly calculate ages.</p>  <p>But, you have no way of making sure the users of your API will follow those conventions or even read your document.</p>  <p>What if we do the hard work for them?</p>  <h2>Why utilities are still not good enough</h2>  <p>The next idea you might have is to create utilities that would do date conversions and calculate ages for the user of your API, so that they just have to remember to use them and all will be good.</p>  <p>This solution is better than one relying purely on convention, but still has some major flaws.&#160; Part of the problem of utility methods is that they are not self-discoverable.&#160; I’ve <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">talked about before</a> how DateUtilities like classes can get overlooked if you don’t know the utility class is there.</p>  <p>If you are relying on your users to go out and find your utility methods to make life easier for them, you are putting a large amount of responsibility in the wrong place.&#160; In my experience, it is very unlikely that anyone but yourself will actually use the utility methods.</p>  <p>You really need a way to stop them from being able to hard code dates.</p>  <h2>How can you stop someone from hard coding dates?</h2>  <p>Don’t accept dates in your API.</p>  <p>It is simple.</p>  <p>What?&#160; What do you mean?&#160; You can’t just stop accepting dates, you need dates.&#160; Not just dates, but integers, or strings.&#160; You can’t just not accept the bad data… or can you?</p>  <p>Consider wrapping the data type in another data type which creates your desired data type, but only using the convention or rules you desire.</p>  <p>Let me show you an example with the dates:</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(DateTime applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>    DoSomethingWithTheDate(applicationDate);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(<span style="color: #0000ff">new</span> DateTime(1990, 7, 8));</pre>
<!--CRLF--></div>
</div>

<p></p>

<p>In the above example, you can see that I am directly taking a .NET DateTime object.&#160; You can also see that I am directly hard coding a date when calling this method.</p>

<p>Let’s see if we can fix that.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CreateCase(CaseDate applicationDate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     DoSomethingWithTheDate(CaseDate.ToDateTime());</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> CreateCase(CaseDate.YearsAgo(20));</pre>
<!--CRLF--></div>
</div>

<p></p>

<h2>What happened?</h2>

<p>Here is what we did:</p>

<ol>
  <li>We created a custom type called CaseDate. </li>

  <li>We replaced all the external usages of DateTime with CaseDate. </li>

  <li>We provided methods on CaseDate which allow the creation of dates, only through the way we want to allow them to be created. </li>
</ol>

<ol>Now we can easily prevent users of the API from being able to create hard coded dates.&#160; The API only will take CaseDate objects and internally creates DateTime objects from the CaseDate objects.</ol>

<ol>We can add other methods to CaseDate to allow the creation of dates from x number of months ago or in the future, or any other valid creation method we want.</ol>

<p>By doing this, we are restricting the valid set of inputs to our methods at compile time, not throwing exceptions at run time.</p>

<p>We are achieving the same kind of valuable input constrictions that we have been able to <a href="http://elegantcode.com/2010/05/08/the-power-of-enum/">achieve with enumerations</a>, except we are adding more complex restrictions than a simple list of selections.</p>

<h2>Where can I use this?</h2>

<p>Not just dates.&#160; There are many places where restricting the input to your method or API is going to simplify logic, protect against error conditions, and enforce constraints.</p>

<p>Consider using this pattern in some of these scenarios:</p>

<ul>
  <li>You want to use an enumeration, but your list of possible choices is too large, or repetitive. </li>

  <li>Anywhere you are using a primitive type and that primitive type represents some more complex concept. </li>

  <li>Anywhere you have parameter validation or manipulation repeated in multiple methods. </li>

  <li>Anytime you process some input or repeat a series of steps to transform it before sending it as input. </li>
</ul>

<p>Every time you are about to make a primitive type a parameter to a method you should ask yourself if it makes sense to wrap the primitive type into an class.</p>

<p>Remember, especially when creating an API, any time your method takes a primitive type, you lose the ability to constrain that input, and are forced to validate it instead.</p>

<p>Should you always wrap all primitive types?&#160; No, but it is another tool you can use to provide an extra layer of indirection between the logic of your API and your callers use of it.</p>

<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Prefer Additional Methods Over Additional Overloads</title>
		<link>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prefer-additional-methods-over-additional-overloads</link>
		<comments>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 17:35:54 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/</guid>
		<description><![CDATA[If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do. Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever written code that is going to be used as an API for other programmers, you may start to think about writing code in a different viewpoint from what you normally do.</p>  <p>Most of us write code for the purpose of achieving a goal.&#160; If we practice writing elegant code, we are conscious of making that code as readable and terse as possible.</p>  <p><strong>Seldom do we think about the use of our code from an API standpoint.</strong></p>  <p>There is a subtle difference between designing your code in a way that will make it easier for someone else to maintain, and designing your code in a way that will make it easier for someone else to use.</p>  <h2>Intellisenselessness</h2>  <p>How often are you working against some API and you type a method name you want to use only to have intellisense present you with 5 overloads for the method all with several different parameters choices?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginOverloads" border="0" alt="LoginOverloads" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginOverloads_thumb.png" width="600" height="151" /></a> </p>  <p>Which one do you use?&#160; It is hard to be sure, you end up having to read through the long lists of parameters to figure out what method you should call and what parameters you should pass it.</p>  <p>Wouldn’t it be better if you were presented with what the method does in the method name rather than guessing what it does in the parameter list?&#160; Something like this?</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoginMoreMethods" border="0" alt="LoginMoreMethods" src="http://elegantcode.com/wp-content/uploads/2010/06/LoginMoreMethods_thumb.png" width="596" height="261" /></a> </p>  <h2>Perspective</h2>  <p>From the perspective of the person writing the <em>Login</em> method(s), overloads probably seem like the most efficient and correct way to implement the multiple ways the method can be called.</p>  <p>From the perspective of the person using the <em>Login</em> method(s), additional methods are much preferred, because they are easier to understand and know what you are looking for.</p>  <p><strong>Try to think from the perspective of someone using your code when writing your code.</strong></p>  <h2>Extract boolean parameter to two methods</h2>  <p>I want to take a look at a very specific example that can be of great benefit to the readability and use of your code.</p>  <p>Take a look at this code below.</p>  <div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Login(<span style="color: #0000ff">bool</span> rememberMe)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>
Seems like a fine overload of a <em>Login</em> method.&#160; I have written code just like this, you probably have also.&#160; <br />

<p>&#160;</p>

<p>Unfortunately, by adding this overload, we have added some complexity to our API, because now the user of that code has to see that there is an additional overload that take a bool parameter called <em>rememberMe</em>.</p>

<p>Consider this longer alternative.</p>

<div id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> LoginDoNotRememberMe()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Instead of overloading <em>Login</em> and making the user have to decide which overload to call and pass in a parameter, we have elected to create two differently named methods which take 0 parameters and clearly state what they are going to do.</p>

<p>I’m not saying you should never write overloads, but anytime you see an overload in your code base, you should stop and think if it would be more clear to make that overloaded method into two different methods that can eliminate one or more of the parameters.</p>

<p><strong>Any time you are restricting the number of choices someone using your code has to make, you are making that code simpler to use.</strong></p>

<p>If you don’t believe me, consider why the iPhone has only one button.</p>

<h5><strong>As always, you can subscribe to this </strong><a href="http://feeds2.feedburner.com/ElegantCode"><strong>RSS feed</strong></a><strong> to follow my posts on elegant code.&#160; Feel free to check out my main personal blog at </strong><a href="http://simpleprogrammer.com"><strong>http://simpleprogrammer.com</strong></a><strong>, which has a wider range of posts, updated 2-3 times a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/06/20/prefer-additional-methods-over-additional-overloads/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Say &#8220;No&#8221; to &#8220;Null&#8221;</title>
		<link>http://elegantcode.com/2010/05/01/say-no-to-null/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=say-no-to-null</link>
		<comments>http://elegantcode.com/2010/05/01/say-no-to-null/#comments</comments>
		<pubDate>Sat, 01 May 2010 19:35:05 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conventions]]></category>
		<category><![CDATA[Craftsmanship]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/05/01/say-no-to-null/</guid>
		<description><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after. What do you do if "null” [...]]]></description>
			<content:encoded><![CDATA[I was recently asked to write a fairly simple piece of code.  In this simple piece of code, I didn’t handle a null input.  I was asked about what kinds of things I would consider about the input, and I pretty much knew what the asker was going after.
<blockquote>What do you do if "null” is passed in?</blockquote>
My answer may turn out to be a bit of a surprise.
<blockquote><span style="background-color: #f4f5f7;">Nothing, I don’t handle nulls in code that I control the use of.</span></blockquote>
“What?  What?” you say.  “You don’t handle null?  What kind of heresy is that?”  It is the kind of heresy that helps produce elegant code and I will show you why.
<h2>How well do you handle null right now?</h2>
Would you say that in most of the code you write you properly check all arguments for null?

Or, do you like most developers, handle null in certain cases when you happen to think about it, or after the application dumps a “null pointer exception” stack trace?

Be honest, look at your code if you have to.

The problem is “d00d ur d0ing it r0ng!”

<a href="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="john-mccarthy-programming-completely-wrong" src="http://elegantcode.com/wp-content/uploads/2010/05/johnmccarthyprogrammingcompletelywrong_thumb.jpg" border="0" alt="john-mccarthy-programming-completely-wrong" width="349" height="452" /></a>

Unless you are some kind of anal retentive perfectionist, you are probably not handling null in every single method call.  That means there are huge potential bugs in the code that you are writing which will throw null pointer exceptions.  That is bad, I agree.

So, if you are not handling it correctly right now, then what can you do to fix that?
<h2>Avoiding null in the code you “own”</h2>
You can’t control external libraries.  And you can’t control how people will use your code, but you can control the code you write and you can, to a degree, control the code your shop writes.

The better strategy is to never pass null in the first place.

You can either focus your efforts on:
<ul>
	<li>Checking for null</li>
	<li>Not ever passing null</li>
</ul>
<ul>The more elegant solution is to focus on never passing null.  By doing this you will end up writing less code and avoid decisions about how to handle null inside of a method that doesn’t have enough context to decide what to do.</ul>
Let’s look at an example:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">string</span> TransmographyThreeStrings(<span class="kwrd">string</span> first, <span class="kwrd">string</span> second, <span class="kwrd">string</span> third)
{
     <span class="kwrd">if</span>(<span class="kwrd">string</span>.isNull(first) || <span class="kwrd">string</span>.isNull(second) || <span class="kwrd">string</span>.isNull(third))
    {
           <span class="rem">// hmm, I donno, what should I do?  Should I throw an exception?</span>
           <span class="rem">// should I return an empty string?</span>
           <span class="rem">// what if the first string wasn't null, can we still do something meaningful?</span>
           <span class="rem">// how will the caller of the method know what I will do?</span>
    }

}</pre>
You can see there that we are checking each parameter for null.  The problem is we don’t know what we should do.  We have lots of options, but none of them are obvious.

How much better is it to make sure that we never pass null into methods, rather than write this kind of code in every method?
<h2>What about accidentally passing in null?</h2>
Many of you are probably thinking at this point that the main way null gets passed into a method is because someone calls a method without knowing that it contains a null value.
<pre class="csharpcode">TransmographyThreeStrings(<span class="str">"Hello"</span>, <span class="str">"World"</span>, mysteryObject.Text);</pre>
Perhaps <em>mysteryObject.Text </em>is null.  You wouldn’t even know it.

Ah, but you can.  Or you can prevent it at least.  Somewhere <em>mysteryObject </em>gets created.  When it gets created its values either get initialized or not.  You can prevent any of its values from being null, several ways:
<ul>
	<li>Always initialize variables when they are declared.</li>
	<li>Use a <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> to ensure that objects are always fully constructed before being created.</li>
	<li>Use properties to provide default values or lazy initialize.</li>
	<li>Make your objects <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> as much as possible.</li>
</ul>
The practices that prevent null from accidentally being passed in make your code much more elegant than repeating <em>if blah == null</em> code all over the place.

<strong>In general, you should always strive to eliminate the passing of null rather than checking for null.  By doing so you reduce extra lines of code in each method, and are forced to use better design practices.</strong>
<h2>Exceptions</h2>
Yes, there are times when you need to check for null.  If you are writing a library that external developers will use, then you will probably want to check for null in all of your methods that are exposed as part of the API.  (On your internal methods, you don’t need to since you have already cleansed the input.)

Also, if your code is being used as a callback to some API and you don’t know if it can ever pass null into your code, you probably should check for null.

A bad excuse is that other developers may pass null to your method. <strong>It is much better as a software shop to put the onus of not passing null on the caller of any method rather than putting it on the writer of the method being called.</strong>

You will also reduce your exception handling code, because you will have less exceptions for invalid parameters.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/05/01/say-no-to-null/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>If Self-Documenting Code is the What, Unit Tests are the Why</title>
		<link>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=if-self-documenting-code-is-the-what-unit-tests-are-the-why</link>
		<comments>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:09:04 +0000</pubDate>
		<dc:creator>John Sonmez</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/</guid>
		<description><![CDATA[It is not enough to just write code that is clean and self-documenting.  Eliminating comments and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it. If you recall from my original post on [...]]]></description>
			<content:encoded><![CDATA[It is not enough to just write code that is clean and self-documenting.  <a href="http://elegantcode.com/2010/04/18/eliminating-comments-the-road-to-clarity/">Eliminating comments</a> and replacing them with clear variable and method names, will tell the reader of your code clearly what it is doing, but it will not properly express why it is doing it.

If you recall from my <a href="http://elegantcode.com/2010/04/09/what-does-elegant-code-mean-to-me/">original post</a> on Elegant code, I stated that elegant code is:
<blockquote>Something that is simple yet effective, delivered with grace.</blockquote>
By writing self-documenting code we are hopefully able to achieve some of the aspects of simplicity and grace, but it tells us nothing about the effectiveness of the code.
<h2>Bringing the dead to life</h2>
<a href="http://elegantcode.com/wp-content/uploads/2010/04/zombies.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="zombies" src="http://elegantcode.com/wp-content/uploads/2010/04/zombies_thumb.jpg" border="0" alt="zombies" width="441" height="295" /></a>

Throwing out comments is a debatable topic.  <a href="http://www.reddit.com/r/programming/comments/bsutx/">It raises quite a bit of controversy</a>, as you can see from some of the comments on my post about the subject.  The reason, perhaps, that so many people are so staunchly opposed to the idea, is because they are worried, and rightly so, that throwing out comments will reduce the documentation of what the code is doing.

Think about that for a second.  Is documentation of what the code is doing important?  It better be.  What we are trying to accomplish by writing self-documenting code instead of comments, is to take the vessel, which is the code itself, and make that same vessel be the documentation of what the code does.  It is by doing this that we creating a living representation of the functionality of the code.  Comments are akin to a dead representation of the functionality of the code because they do not change automatically with the code.

I diverge to talk about comments so that I can draw a parallel to another form of documentation which is valuable and should be considered necessary.  That other set of documentation is requirements.  Have you ever written requirements documents?  Have you ever captured requirements from the customer and put them into UML diagrams, or perhaps plopped them into some templated Word document, which is never updated again, and no one reads, because no one trusts it is correct?  Wouldn’t it be great if we would replace that dead document or set of documents, with a living one?

The good news is we can, and some of us have.  And I fully expect this recommendation will be just as controversial, because <strong>I am suggesting that we don’t have to write low level specifications of the system at all, instead we can write good unit tests. </strong>When we do this, we are taking a dead form of document and bringing it to life.
<h2>Unit tests tell us why and how our code is effective</h2>
If
<pre class="csharpcode">i = 5;  // Widget count defaults to five.</pre>
is replaced with
<pre class="csharpcode">widgetCount = DEFAULT_WIDGET_COUNT;</pre>
<!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->

then
<blockquote><span style="background-color: #ffffff;">1.1.5 When a new widget is created, the widget count should be increased by one.</span></blockquote>
is replaced with
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> When_NewWidgetIsCreated_Then_WidgetCountIsIncreasedByOne()
{
     WidgetFactory.Count = 3;
     WidgetFactory.CreateNew();
     assertEquals(4, WidgetFactory.Count);
}</pre>
The unit test is replacing the low level requirement, which is somewhat open to interpretation and untied to the code, with an absolute and completely tied-to-the-code, specific requirement.

The unit test is telling us why our code is built the way it is.  It is telling us what requirement that particular structure of code is trying to address.  <strong>It is telling us what end result that code is trying to accomplish and what the expectations are on the results of a given condition.</strong>

The unit test is telling us how the code is to be used in order to achieve its result.  It is serving as a living reference to the syntax and use of the code we built.  <strong>Instead of providing instructions on how to use our API, we are providing a living example, and proof that it will indeed work.</strong> Examples are often much more effective than instructions anyway.
<h2>What exactly are we replacing?</h2>
At this point we are not trying to replace all the documentation of the system (at this point).

With self-documenting code, we sought to eliminate comments, and replace them with good variable and method names.

With unit tests, we seek to eliminate technical documentation and requirements of the system, that is targeted at a developer or technical audience.

We are NOT trying to eliminate high level specifications of the system, or use cases. <strong>Unit tests DO NOT replace that kind of documentation! </strong>We will talk about replacing that kind of documentation when we talk about automated functional or system tests.

Simply put, any kind of documentation that you would give to a developer so they understand how the system works and how to use the code or APIs, can be easily replaced by writing good unit tests.

Our simple goal is to replace the “dead” documentation (meaning that it does not update automatically with the thing it is documenting), with “living” documentation in the form of unit tests.

One last point.  I want to be clear that I am not saying that having unit tests automatically results in the ability to replace technical documentation.  Just like having long-named methods and variables doesn’t automatically replace the need for comments.  It is a matter of the quality of the unit tests that are written, just as it is a matter of the quality of the self-documenting code.
<h5>As always, you can subscribe to this <a href="http://feeds2.feedburner.com/ElegantCode">RSS feed</a> to follow my posts on elegant code.  Feel free to check out my main personal blog at <a href="http://simpleprogrammer.com">http://simpleprogrammer.com</a>, which has a wider range of posts, updated 2-3 times a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h5>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/04/25/if-self-documenting-code-is-the-what-unit-tests-are-the-why/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>REST: Resources, URI&#8217;s and Representations</title>
		<link>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rest-resources-uris-and-representations</link>
		<comments>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 04:00:13 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/</guid>
		<description><![CDATA[In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions. Resources Resources are at the heart of REST.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will begin introducing the architectural style known as Representational State Transfer (REST).&#160; REST is viable for both services and applications.&#160; Wrap your mind around this style and you will quickly see how straightforward it is and where it might fit in your solutions.</p>  <h3>Resources</h3>  <p>Resources are at the heart of REST.&#160; You are already used to resources as a web browsing consumer.&#160; A resource is not something specific to REST, instead it is the first thing you probably want to consider when architecting a RESTful application.&#160; A resource is simply the entity, item, or thing you want to expose.</p>  <p>Perhaps you have approached application architecture using one or many of several modeling and design techniques.&#160; Data First practitioners typically begin with databases and data models.&#160; DDD proponents like to begin by modeling around business entities and interactions, while their cousins in the BDD camp model around business activities.</p>  <p>When you decide to apply REST you will need to think a lot more about data entities and domain objects as resources.&#160; Your existing models may or may not closely map to resources.&#160; The shift in thinking may appear slight, but is very important.&#160; It centers around making things&#160; addressable.&#160; Each resources must by uniquely identifiable as we will see in the next section.&#160; We are used to identity with most data entities, but our domain objects may not always be as easily identifiable.&#160; Likewise, our data entites may have identity, but not map to a resource.&#160; </p>  <p>Consider the classic customer and order scenario for example.&#160; If each customer and each order can be identified then it will be easy to design RESTful systems around them.&#160; However, if the model requires a lot of context then our challenge is a little bit larger.&#160; Perhaps we must first identify a partner, then a year, then a customer, and finally the order.&#160; Yes, that is a design smell in general.&#160; It makes fetching an order very difficult.&#160; Developing RESTfuly would only further expose that difficulty.&#160; Identifying your resources up front will help you reduce the possible impedance mismatches you might end up with between what you want to expose and your data or domain models.</p>  <p>REST is about interacting with Resources!</p>  <h3>URI’s</h3>  <p>REST defines the identity of a resource via URI.&#160; Each resources has a unique address in URL form (ie. using the http protocol).&#160; Interaction with a resource will take place at its URI.&#160; As an example, my twitter status feed resource URI is <a title="http://twitter.com/optionstrict" href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; That URI is unique to my feed and that is what you expect to find at that URI.&#160; In the Twitter databases or domain models my account may be referred to by the string optionstrict, or perhaps as some random number or guid.</p>  <p>To consume my status history via a service interface twitter provides another URI at <a title="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict" href="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict">http://api.twitter.com/1/statuses/user_timeline.json?screen_name=optionstrict</a>.&#160; I would actually prefer to have access at the same URI for html, json, and xml formats.&#160; Twitter probably has its reasons for distinguishing API access from HTML rendering, but they have actually complicated their architecture by doing so.&#160; When designing the URI’s for your resources, make them easy for your users to work with.&#160; </p>  <h3>Representation</h3>  <p>Lets continue with the twitter example to describe what is meant by Representation.&#160; Given a URI and a Resource, what will your consumers receive when they issue a GET request to the URI?&#160; Twitter chose a representation of my account and included status history and profile for the response at <a href="http://twitter.com/optionstrict">http://twitter.com/optionstrict</a>.&#160; They decided to put a representation of my profile photo at <a title="http://twitter.com/account/profile_image/optionstrict" href="http://twitter.com/account/profile_image/optionstrict">http://twitter.com/account/profile_image/optionstrict</a>.&#160; In your REST solutions you will need to consider how you want to represent a resource at its URI.&#160; Each representation will have a unique URI.&#160; </p>  <p>Representations are also important for manipulating resources.&#160; You must define the representation required to create and update resources.&#160; Twitter status updates require a text representation with a maximum of 140 characters.&#160; They allow additional values in the status representation, such as latitude and longitude.&#160; Your REST solutions similarly must define representations for Requests and Responses.</p>  <p>I hope that this short introduction has helped you to see that the core essence of REST is simple and fairly obvious.&#160; As you look at your current solutions what are the resources you are exposing?&#160; Could you make those resources identifiable by URI?&#160; What representation would you place at each URI?&#160; What representation would you require for manipulating a given resource?</p>  <p>Also, notice I did not mention much about data formats, Content Type, Mime, etc.&#160; Those details can cloud your design if you try to start with them. If you can’t wait for my post about how REST handles html, json, xml from the same URI, then start googling Content Negotiation, Accept header, and Content-Type header.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/15/rest-resources-uris-and-representations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Driven Architecture: Publishing Events using an IOC container</title>
		<link>http://elegantcode.com/2010/01/06/event-driven-architecture-publishing-events-using-an-ioc-container/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=event-driven-architecture-publishing-events-using-an-ioc-container</link>
		<comments>http://elegantcode.com/2010/01/06/event-driven-architecture-publishing-events-using-an-ioc-container/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 00:29:27 +0000</pubDate>
		<dc:creator>Jarod Ferguson</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Event Driven Architecture]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/01/06/event-driven-architecture-publishing-events-using-an-ioc-container/</guid>
		<description><![CDATA[In my last post I talked about advanced IOC usage and how it is possible to use an IOC container to resolve an open generic from a closed implementation. This is technically cool, but it does not explain why this is important. In this post I want to show some additional code that will demonstrate [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/">my last post</a> I talked about advanced IOC usage and how it is possible to use an IOC container to resolve an open generic from a closed implementation. This is technically cool, but it does not explain why this is important. In this post I want to show some additional code that will demonstrate a basic concept of <a href="http://en.wikipedia.org/wiki/Event_Driven_Architecture">Event Driven Architecture</a>: Publishing an Event.</p>  <p>&#160;</p>  <h4>Why is Event Driven Architecture good?</h4>  <p>Event driven architecture is extremely extensible. <strong>In my mind, it the perfect solution to address the <a href="http://en.wikipedia.org/wiki/Open/closed_principle">Open Closed Principal</a> and enable <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">Single Responsibility</a> in code</strong>. </p>  <p>Consider a system that processes orders. There is a method called SubmitOrder(order) on an OrderController. It just validates and saves the new order to the database today.</p>  <p>In a following story, the product owner says “<strong>I need the system to send an email to the customer when the order is submitted</strong>”. No problem, inject the MailService into the OrderController, send the mail in the SubmitOrder(order) method. great.</p>  <p>The next story the product owner says “<strong>I need you to deduct the ordered quantities from the OnHand inventory</strong>”. Check, so we inject in the inventory service into our OrderController, and we call it from the SubmitOrder(order) method.</p>  <p>More stories…. the product owner says “<strong>We need to send a message to the warehouse fulfillment system to let them know a new order has been submitted</strong>” </p>  <p>Ugh, another service, another method. The tests for SubmitOrder become out of control. Even when extracting methods and encapsulating more logic into services, there is still violation of SRP &amp; OCP. Not to mention there could be performance degradation from performing all of these tasks synchronously while the user waits. </p>  <p><strong>Its not the job of SubmitOrder to do all of this, there has to be a better way.</strong></p>  <p>&#160;</p>  <h4>Publishing an Event Example</h4>  <p>What if I “<strong>tell</strong>” the system that an event had occurred, and anyone interested could take action? (like an old school observer right?) In the following code sample I am going to inject in an ‘EventPublisher’ into my OrderController, then use that object to notify the rest of the system by publishing an <a href="http://www.eaipatterns.com/EventMessage.html">event</a> using this line:</p>  <div>   <div class="csharpcode">     <pre class="alt">_eventPublisher.Publish(<span class="kwrd">new</span> OrderSubmittedEvent{OrderId = order.Id});</pre>
  </div>
</div>

<h6>&#160;</h6>

<h6>The OrderController</h6>

<div>
  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">public</span> <span class="kwrd">class</span> OrderController : Controller</pre>

    <pre class="alteven">{</pre>

    <pre class="alt">   <span class="kwrd">private</span> <span class="kwrd">readonly</span> IRepository&lt;Order&gt; _orderRepository;</pre>

    <pre class="alteven">   <span class="kwrd">private</span> <span class="kwrd">readonly</span> IEventPublisher _eventPublisher;</pre>

    <pre class="alt">&#160;</pre>

    <pre class="alteven">   <span class="kwrd">public</span> OrderController(IRepository&lt;Order&gt; orderRepository, </pre>

    <pre class="alt">                          IEventPublisher eventPublisher)</pre>

    <pre class="alteven">   {</pre>

    <pre class="alt">       _orderRepository = orderRepository;</pre>

    <pre class="alteven">       _eventPublisher = eventPublisher;</pre>

    <pre class="alt">   }</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">   <span class="kwrd">public</span> ActionResult SubmitOrder(OrderViewModel viewModel)</pre>

    <pre class="alteven">   {</pre>

    <pre class="alt">       <span class="kwrd">try</span></pre>

    <pre class="alteven">       {</pre>

    <pre class="alt">           <span class="kwrd">if</span> (ModelState.IsValid)</pre>

    <pre class="alteven">           {</pre>

    <pre class="alt">               var order = MapOrder(viewModel);</pre>

    <pre class="alteven">               _orderRepository.Add(order);</pre>

    <pre class="alt">               _orderRepository.SaveChanges();</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">               _eventPublisher.Publish(<span class="kwrd">new</span> OrderSubmittedEvent{OrderId = order.Id});</pre>

    <pre class="alteven">             </pre>

    <pre class="alt">               <span class="rem">//Display success message</span></pre>

    <pre class="alteven">               <span class="rem">//ViewInfo.AddSuccessMessage(Language.SubmitOrderSuccess);</span></pre>

    <pre class="alt">           }</pre>

    <pre class="alteven">       }</pre>

    <pre class="alt">       <span class="kwrd">catch</span></pre>

    <pre class="alteven">       {</pre>

    <pre class="alt">           ModelState.AddModelError(<span class="str">&quot;__Form&quot;</span>, Language.SubmitOrderError);</pre>

    <pre class="alteven">       }</pre>

    <pre class="alt">  </pre>

    <pre class="alteven">       <span class="kwrd">return</span> View(viewModel);</pre>

    <pre class="alt">   }</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">   <span class="rem">//other</span></pre>

    <pre class="alteven">}</pre>
  </div>
</div>

<p>&#160;</p>

<p>Now, using this simple <a href="http://www.eaipatterns.com/EventDrivenConsumer.html">Consumer</a> (Handler) interface:</p>

<div>
  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">public</span> <span class="kwrd">interface</span> IConsumer&lt;T&gt;</pre>

    <pre class="alteven">{</pre>

    <pre class="alt">    <span class="kwrd">void</span> Handle(T eventMessage);</pre>

    <pre class="alteven">}</pre>
  </div>
</div>

<p>&#160;</p>

<p>I can independently implement each of the system requirements, as needed:</p>

<div>
  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">public</span> <span class="kwrd">class</span> EmailOrderConfirmation : IConsumer&lt;OrderSubmittedEvent&gt;</pre>

    <pre class="alteven">{</pre>

    <pre class="alt">   <span class="kwrd">public</span> <span class="kwrd">void</span> Handle(OrderSubmittedEvent eventMessage)</pre>

    <pre class="alteven">   {</pre>

    <pre class="alt">      <span class="rem">//send email</span></pre>

    <pre class="alteven">   }</pre>

    <pre class="alt">}</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt"><span class="kwrd">public</span> <span class="kwrd">class</span> NotifyWarehouse : IConsumer&lt;OrderSubmittedEvent&gt;</pre>

    <pre class="alteven">{</pre>

    <pre class="alt">   <span class="kwrd">public</span> <span class="kwrd">void</span> Handle(OrderSubmittedEvent eventMessage)</pre>

    <pre class="alteven">   {</pre>

    <pre class="alt">       <span class="rem">//notify warehouse</span></pre>

    <pre class="alteven">   }</pre>

    <pre class="alt">}</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt"><span class="kwrd">public</span> <span class="kwrd">class</span> DeductOnHandInventory : IConsumer&lt;OrderSubmittedEvent&gt;</pre>

    <pre class="alteven">{</pre>

    <pre class="alt">   <span class="kwrd">public</span> <span class="kwrd">void</span> Handle(OrderSubmittedEvent eventMessage)</pre>

    <pre class="alteven">   {</pre>

    <pre class="alt">       <span class="rem">//deduct inventory</span></pre>

    <pre class="alteven">   }</pre>

    <pre class="alt">}</pre>
  </div>
</div>

<p>&#160;</p>

<p>One of my favorite parts about this code: <strong>the container is building up all of these event consumers, which makes it is easy to satisfy all of the dependencies using constructor injection.</strong> This makes testing each of these handlers a breeze, and everything follows the same patterns and conventions keeping the code base understandable and clean. (Services, Controllers, Consumers all work the same)</p>

<p>Just plug in the dependencies in the EmailOrderConfirmation consumer ctor* like so:</p>

<div>
  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">public</span> <span class="kwrd">class</span> EmailOrderConfirmation : IConsumer&lt;OrderSubmittedEvent&gt;</pre>

    <pre class="alteven">{</pre>

    <pre class="alt">   <span class="kwrd">private</span> <span class="kwrd">readonly</span> IRepository&lt;Order&gt; _orderRepository;</pre>

    <pre class="alteven">   <span class="kwrd">private</span> <span class="kwrd">readonly</span> ISmtpService _smtpService;</pre>

    <pre class="alt">   <span class="kwrd">private</span> <span class="kwrd">readonly</span> ILogger _logger;</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">   <span class="kwrd">public</span> EmailOrderConfirmation(IRepository&lt;Order&gt; orderRepository, </pre>

    <pre class="alteven">                                 ISmtpService smtpService,</pre>

    <pre class="alt">                                 ILogger logger)</pre>

    <pre class="alteven">   {</pre>

    <pre class="alt">       _orderRepository = orderRepository;</pre>

    <pre class="alteven">       _smtpService = smtpService;</pre>

    <pre class="alt">       _logger = logger;</pre>

    <pre class="alteven">   }</pre>

    <pre class="alt">&#160;</pre>

    <pre class="alteven">   <span class="kwrd">public</span> <span class="kwrd">void</span> Handle(OrderSubmittedEvent eventMessage)</pre>

    <pre class="alt">   {</pre>

    <pre class="alteven">       var order = _orderRepository.Single(x =&gt; x.Id == eventMessage.OrderId);</pre>

    <pre class="alt">       var message = <span class="kwrd">new</span> SmtpMessage();</pre>

    <pre class="alteven">       <span class="rem">//get customer info from order  &amp; populate message</span></pre>

    <pre class="alt">       _smtpService.SendMessage(message);</pre>

    <pre class="alteven">   }</pre>

    <pre class="alt">}</pre>
  </div>
</div>

<p><strong></strong></p>

<p><strong>* Note that you could also inject the IEventPublisher into a Consumer and publish more events. </strong></p>

<p><strong></strong></p>

<h4>&#160;</h4>

<h4>How Does it Work?</h4>

<p>Under the hood the IoC container is doing most of the work. It keeps track of the event subscriptions and also provides the consumer instantiation. </p>

<h5>Event Subscriptions</h5>

<p>Here is how the event subscriptions are added to the container. In this example I use an interface so that I can enable dependency injection into components, and then mock the GetSubscriptions&lt;T&gt; dependency for easy testing. I also use a static method for adding subscriptions since the registration process operation usually happens at bootstrapping time, which is generally all static. The IoC.Container here is thread safe. </p>

<div>
  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">public</span> <span class="kwrd">interface</span> ISubscriptionService</pre>

    <pre class="alteven">{</pre>

    <pre class="alt">   IEnumerable&lt;IConsumer&lt;T&gt;&gt; GetSubscriptions&lt;T&gt;();</pre>

    <pre class="alteven">}</pre>

    <pre class="alt">&#160;</pre>

    <pre class="alteven"><span class="kwrd">public</span> <span class="kwrd">class</span> EventSubscriptions : ISubscriptionService</pre>

    <pre class="alt">{</pre>

    <pre class="alteven">   <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> Add&lt;T&gt;()</pre>

    <pre class="alt">   {</pre>

    <pre class="alteven">       var consumerType = <span class="kwrd">typeof</span>(T);</pre>

    <pre class="alt">&#160;</pre>

    <pre class="alteven">       consumerType.GetInterfaces()</pre>

    <pre class="alt">                   .Where(x =&gt; x.IsGenericType)</pre>

    <pre class="alteven">                   .Where(x =&gt; x.GetGenericTypeDefinition() == <span class="kwrd">typeof</span>(IConsumer&lt;&gt;))</pre>

    <pre class="alt">                   .ToList()</pre>

    <pre class="alteven">                   .ForEach(x =&gt; IoC.Container.RegisterType(x, </pre>

    <pre class="alt">                                                            consumerType, </pre>

    <pre class="alteven">                                                            consumerType.FullName));</pre>

    <pre class="alt">   }</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">   <span class="kwrd">public</span> IEnumerable&lt;IConsumer&lt;T&gt;&gt; GetSubscriptions&lt;T&gt;()</pre>

    <pre class="alteven">   {</pre>

    <pre class="alt">       var consumers =  IoC.Container.ResolveAll(<span class="kwrd">typeof</span>(IConsumer&lt;T&gt;));</pre>

    <pre class="alteven">       <span class="kwrd">return</span> consumers.Cast&lt;IConsumer&lt;T&gt;&gt;();</pre>

    <pre class="alt">   }</pre>

    <pre class="alteven">}</pre>
  </div>
</div>

<p>&#160;</p>

<h5>Event Publishing</h5>

<p>Now that the subscriptions are setup, the publisher can read those subscriptions, get the consumers from the container, and pass the event message instance to each of them. Again I am using an Interface so I can enable dependency injection (and mocking capabilities) for the components which need to do publishing (controllers, services)</p>

<div>
  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">public</span> <span class="kwrd">interface</span> IEventPublisher</pre>

    <pre class="alteven">{</pre>

    <pre class="alt">   <span class="kwrd">void</span> Publish&lt;T&gt;(T eventMessage);</pre>

    <pre class="alteven">}</pre>

    <pre class="alt">&#160;</pre>

    <pre class="alteven"><span class="kwrd">public</span> <span class="kwrd">class</span> EventPublisher : IEventPublisher</pre>

    <pre class="alt">{</pre>

    <pre class="alteven">   <span class="kwrd">private</span> <span class="kwrd">readonly</span> ISubscriptionService _subscriptionService;</pre>

    <pre class="alt">&#160;</pre>

    <pre class="alteven">   <span class="kwrd">public</span> EventPublisher(ISubscriptionService subscriptionService)</pre>

    <pre class="alt">   {</pre>

    <pre class="alteven">       _subscriptionService = subscriptionService;</pre>

    <pre class="alt">   }</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">   <span class="kwrd">public</span> <span class="kwrd">void</span> Publish&lt;T&gt;(T eventMessage)</pre>

    <pre class="alteven">   {</pre>

    <pre class="alt">       var subscriptions = _subscriptionService.GetSubscriptions&lt;T&gt;();</pre>

    <pre class="alteven">       subscriptions.ToList().ForEach(x =&gt; PublishToConsumer(x, eventMessage));</pre>

    <pre class="alt">   }</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">   <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> PublishToConsumer&lt;T&gt;(IConsumer&lt;T&gt; x, T eventMessage)</pre>

    <pre class="alteven">   {</pre>

    <pre class="alt">       <span class="kwrd">try</span></pre>

    <pre class="alteven">       {</pre>

    <pre class="alt">           x.Handle(eventMessage);</pre>

    <pre class="alteven">       }</pre>

    <pre class="alt">       <span class="kwrd">catch</span>(Exception e)</pre>

    <pre class="alteven">       {</pre>

    <pre class="alt">           <span class="rem">//log and handle internally</span></pre>

    <pre class="alteven">       }</pre>

    <pre class="alt">       <span class="kwrd">finally</span></pre>

    <pre class="alteven">       {</pre>

    <pre class="alt">           var instance = x <span class="kwrd">as</span> IDisposable;</pre>

    <pre class="alteven">           <span class="kwrd">if</span> (instance != <span class="kwrd">null</span>)</pre>

    <pre class="alt">           {</pre>

    <pre class="alteven">               instance.Dispose();</pre>

    <pre class="alt">           }</pre>

    <pre class="alteven">       }</pre>

    <pre class="alt">   }</pre>

    <pre class="alteven">}</pre>
  </div>
</div>

<p>&#160;</p>

<p>- <strong>Keep in mind in this example is all running on the same thread, therefore even though semantically we are handling events as if they are asynchronous, it is a blocking operation</strong></p>

<p>&#160;</p>

<h4>Additional Benefits of this Architecture</h4>

<p>- Events are in messages, which can be serialized and processed on different threads, or even different nodes in a cluster. In a web environment, this might mean offloading the workload out of your IIS processes freeing web-server threads for performance &amp; scalability (see Service Bus section)</p>

<p>- Get multicast delegate observer like functionality without having to deal with static events, event registration &amp; deregistration (the whole += –= biz)</p>

<p>- Each event handler has its own class, each having 1 responsibility</p>

<p>- Very extensible, very maintainable (wait, I said that already?)</p>

<p>&#160;</p>

<h5></h5>

<h5></h5>

<h5></h5>

<h4>This is not a Service Bus</h4>

<p>This code above could work great in a simple MVC.NET application for implementing clean separation and structuring your code base into events. Though it gets a lot of influence from the OSS services busses, it is greatly simplified and merely demonstrates a simple concept of publishing &amp; consuming domain events using an IoC container.</p>

<p>A service bus does quite a bit more than just publishing local messages on single thread. If you find yourself enjoying this posts and want to take it to the next level, check out <a href="http://code.google.com/p/masstransit/">MassTransit</a> (Chris Patterson &amp; Dru Sellers) &amp; <a href="http://www.nservicebus.com/">nServiceBus</a> (Udi Dahan). I would also recommend the <a href="http://www.eaipatterns.com/eaipatterns.html">EAI patterns</a> books by Gregor Hohpe and recognize the <a href="http://www.eaipatterns.com/toc.html">reference patterns</a>. (one of these days Ill make it through it instead of using it for reference!)</p>

<p>Some additional concepts and common patterns you might find: </p>

<ul>
  <li><a href="http://en.wikipedia.org/wiki/Publish/subscribe">Publish-Subscribe</a> </li>

  <li><a href="http://en.wikipedia.org/wiki/Request-response">Request-Response</a> </li>

  <li><a href="http://www.udidahan.com/2009/04/20/saga-persistence-and-event-driven-architectures/">Sagas (Workflow)</a> </li>

  <li><a href="http://masstransit.pbworks.com/MessageCorrelation">Correlation</a> </li>

  <li><a href="http://www.eaipatterns.com/CompetingConsumers.html">Competing Consumers</a> </li>

  <li><a href="http://artofbabel.com/specials/73-distributed-processing-with-nservicebus.html">Distributed Load</a> (processing across many nodes in cluster) </li>

  <li>Transport (Http, MSMQ, ActiveMq, WCF TCP) </li>

  <li>Serialization (Binary, XML, JSON) </li>

  <li>Threadpooling </li>
</ul>

<ul></ul>

<h4>The Specification</h4>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p>Normally I don't make a habit of testing the container, but in this case its so close to the container I feel its appropriate vs mocking out the subscriptions. Plus since this is a blog post demonstrating advanced IOC usage, I want explicitly show all of the dependencies required at bootstrap time.</p>

<p>Please note the LoggerSpy for assertions. In this spec we are really only concerned whether or not they get called. Because of the nature of eventing, using a <a href="http://xunitpatterns.com/Test%20Spy.html">Test Spy</a> is really the only good way I have found to assert whether or not your handlers get invoked. (<em>If your processing on multiple threads you will have to make sure they are all done before you check assertions, perhaps a future blog post)</em></p>

<div>
  <div class="csharpcode">
    <pre class="alt">[TestFixture]</pre>

    <pre class="alteven"><span class="kwrd">public</span> <span class="kwrd">class</span> When_An_Order_Is_Submitted : Specification_Context</pre>

    <pre class="alt">{</pre>

    <pre class="alteven">   <span class="kwrd">private</span> LoggerSpy _loggerSpy;</pre>

    <pre class="alt">   <span class="kwrd">private</span> Mock&lt;IRepository&lt;Order&gt;&gt; _orderRepositoryMock;</pre>

    <pre class="alteven">   <span class="kwrd">readonly</span> IUnityContainer _container = IoC.Container;</pre>

    <pre class="alt">&#160;</pre>

    <pre class="alteven">   <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Context()</pre>

    <pre class="alt">   {</pre>

    <pre class="alteven">       <span class="rem">//setup EF repository mock</span></pre>

    <pre class="alt">       _orderRepositoryMock = <span class="kwrd">new</span> Mock&lt;IRepository&lt;Order&gt;&gt;();</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">       <span class="rem">//logger spy to capture handler messages</span></pre>

    <pre class="alteven">       _loggerSpy = <span class="kwrd">new</span> LoggerSpy();</pre>

    <pre class="alt">&#160;</pre>

    <pre class="alteven">       <span class="rem">//register with container</span></pre>

    <pre class="alt">       _container.RegisterInstance&lt;ILogger&gt;(_loggerSpy);</pre>

    <pre class="alteven">       _container.RegisterInstance(_orderRepositoryMock.Object);</pre>

    <pre class="alt">       _container.RegisterType&lt;IEventPublisher, EventPublisher&gt;();</pre>

    <pre class="alteven">       _container.RegisterType&lt;ISubscriptionService, EventSubscriptions&gt;();</pre>

    <pre class="alt">       _container.RegisterType&lt;OrderController&gt;();</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">       <span class="rem">//add event subscriptions</span></pre>

    <pre class="alteven">       EventSubscriptions.Add&lt;EmailOrderConfirmation&gt;();</pre>

    <pre class="alt">       EventSubscriptions.Add&lt;NotifyWarehouse&gt;();</pre>

    <pre class="alteven">       EventSubscriptions.Add&lt;DeductOnHandInventory&gt;();</pre>

    <pre class="alt">   }</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">   <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Because()</pre>

    <pre class="alteven">   {</pre>

    <pre class="alt">       _container.Resolve&lt;OrderController&gt;().SubmitOrder(<span class="kwrd">new</span> OrderViewModel());</pre>

    <pre class="alteven">   }</pre>

    <pre class="alt">&#160;</pre>

    <pre class="alteven">   [Test]</pre>

    <pre class="alt">   <span class="kwrd">public</span> <span class="kwrd">void</span> Order_Should_Be_Persisted()</pre>

    <pre class="alteven">   {</pre>

    <pre class="alt">       _orderRepositoryMock.Verify(x =&gt; x.Add(It.IsAny&lt;Order&gt;()));</pre>

    <pre class="alteven">       _orderRepositoryMock.Verify(x =&gt; x.SaveChanges());</pre>

    <pre class="alt">   }</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">   [Test]</pre>

    <pre class="alteven">   <span class="kwrd">public</span> <span class="kwrd">void</span> Email_Notification_Should_Be_Sent_To_Customer()</pre>

    <pre class="alt">   {</pre>

    <pre class="alteven">       _loggerSpy.LoggedMessages.ShouldContain(Language.OrderConfirmationEmailSuccess);</pre>

    <pre class="alt">   }</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">   [Test]</pre>

    <pre class="alteven">   <span class="kwrd">public</span> <span class="kwrd">void</span> On_Hand_Inventory_Should_Be_Reduced()</pre>

    <pre class="alt">   {</pre>

    <pre class="alteven">       _loggerSpy.LoggedMessages.ShouldContain(Language.DeductOnHandInventorySuccess);</pre>

    <pre class="alt">   }</pre>

    <pre class="alteven">&#160;</pre>

    <pre class="alt">   [Test]</pre>

    <pre class="alteven">   <span class="kwrd">public</span> <span class="kwrd">void</span> Warehouse_Should_Be_Notified()</pre>

    <pre class="alt">   {</pre>

    <pre class="alteven">       _loggerSpy.LoggedMessages.ShouldContain(Language.NotifyWarehouseSuccess);</pre>

    <pre class="alt">   }</pre>

    <pre class="alteven">}</pre>
  </div>
</div>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/01/06/event-driven-architecture-publishing-events-using-an-ioc-container/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
	</channel>
</rss>

