<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>KakimotOnline</title>
	<atom:link href="http://nandokakimoto.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://nandokakimoto.wordpress.com</link>
	<description>Software development information and IT news</description>
	<lastBuildDate>Fri, 27 Jan 2012 04:33:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='nandokakimoto.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>KakimotOnline</title>
		<link>http://nandokakimoto.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://nandokakimoto.wordpress.com/osd.xml" title="KakimotOnline" />
	<atom:link rel='hub' href='http://nandokakimoto.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Lessons Learned From My First ThoughtWorks Project</title>
		<link>http://nandokakimoto.wordpress.com/2012/01/15/lessons-learned-from-my-first-thoughtworks-project/</link>
		<comments>http://nandokakimoto.wordpress.com/2012/01/15/lessons-learned-from-my-first-thoughtworks-project/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 15:16:57 +0000</pubDate>
		<dc:creator>nandokakimoto</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[thoughtworks]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[lessons learned]]></category>

		<guid isPermaLink="false">http://nandokakimoto.wordpress.com/?p=646</guid>
		<description><![CDATA[Hey Guys, It has been a while since my last post here. Lots of things changed in 2011. The big change happend in March when I joined ThoughtWorks Brazil and moved to Porto Alegre. From March to November (8 months) I worked in a distributed team between Brazil and EUA. During the project, we as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=646&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hey Guys,</p>
<p>It has been a while since my last post here. Lots of things changed in 2011. The big change happend in March when I joined ThoughtWorks Brazil and moved to Porto Alegre. From March to November (8 months) I worked in a distributed team between Brazil and EUA. During the project, we as a team had the opportunity to learn lots of good practices together and this post has the objective to share them with the community. All the topics below came up in team retrospective at the end of the project and correspond to team&#8217;s lessons learn from that time.</p>
<p>P.S.: Because I didn&#8217;t write down the whole discussion at the time of the retrospective, some arguments may not represent team&#8217;s opinion, but my personal one.</p>
<p><strong>1. Visit your client</strong></p>
<p>Because our team were distributed, people were frequently flying back and forth between our office and the client. Some people may think this strategy to expensive to afford (flights, hotels, meals) and it is in fact. However, the success of a project is tightly  related to team members relationship. In co-located teams it is easier to build trust relationships between team members because they see each other all the time, go lunch together, hang out in the weekends. That is not true in a distributed team. It&#8217;s crucial that team members had some face-to-face meetings in a while, preferably at the beginning of the project. Believe me, this approach will actually same some money. So every distributed project must have a budget intended for members travel.</p>
<p><strong>2. Remote pairing is hard</strong></p>
<p>ThoughtWorkers love pairing. I would say that our team in Brazil paired in 90% of the tasks. We do pairing to share knowledge between team members, rump up new team members, write better code. We had a strategy of dedicating two brazilian developers to pair with two devs in the US through Skype and LogMeIn. The idea behind that was to balance expertise between both locations. For example, we had specific parts of the application that only on side of the team knew about and we want to eliminate such risk. Unfortunately, we found out that remote pairing is hard. The main reason? It slows development down. In our experience, the challenges in remote pairing were (1) the connection dropped frequently breaking development flow (2) typing in a remote box is slow which resulted in devs having to express their solution through conversations instead of code (3) explain how to code a solution is much harder than implement it yourself. Due to all these challenges we decided to do remote pairing only in very specific scenarios.</p>
<p><strong>3. Use real data/users before going live</strong></p>
<p>During eight months we had four main releases. The frist one was a success which translates to happy users, client and team. Unfortunately, over time users started complaining about application slowness, unpredictable results and data security faults. So what we did wrong? Just after the release the system had almost no data so pages loaded fast, bad data didn&#8217;t exist, users didn&#8217;t have time to break the system yet. After 2 months we had tons of data inserted and as a consequence application&#8217;s report started to take a while to load. In addition, users posted all kinds of data and found out new flows that were never tested. The problem: we didn&#8217;t stress the application with real data/users. To solve these problems we basically scheduled user sessions meetings frequently so we could learn how they use the system and dumped production like data in our staging environment. After that we could find problems before they appear in production and solve it as part of our normal process flow.</p>
<p><strong>4. Write acceptance tests</strong></p>
<p>I use to write lots of unit tests before joining ThoughtWorks (I already had TDD mentality). However, I&#8217;ve never written acceptance tests. So every release was painful: manual testing took too long and team didn&#8217;t know for sure what could break. In my first ThoughtWorks project a user story is only Dev Done after all acceptance scenarios were implemented. Basically, before the story is Ready to Dev, a business analyst sits down with PO and QAs to write scenarios in a Given/When/Then format. That would drive our development so all scenarios were implemented. After that, we were sure that the story was really done. In addition, those scenarios were added to our build pipeline, working as a safety net for developers and preventing us to run tons of manual testing when realeasing. With good acceptance tests coverage, we were able to release fast and with confidence.</p>
<p><strong>5. Keep your build green</strong></p>
<p>In our team we had a continuous integration server responsible for checking-out the source code, compiling the solution, running static code analysis, running automated tests and building deployment artifacts. All these tasks were triggered after every check-in. The continuous integration server helped us by integrating devs work into the final solution and checking for possible errors. A clear example is when someone forgets to check-in source code files or breaks existing automate tests. When that happens the build becomes red indicating the application is in a bad state. We as a team defined a rule that whenever the build is red, a pair would stop whatever they were doing to fix it. Meanwhile no other dev should check-in. Because our team was quite big if others keep checking-in code into the repository, fixing the build becomes harder. This rule helped us keeping our build green as much time as possible which means the application were most of time in a good state, ready to be deployed to staging for example.</p>
<p><strong>6. Insert data for each test</strong></p>
<p>Although acceptance tests are important when developing large software applications, they introduce a big problem: maintenance. Our team learned how expensive is maintaining acceptance test due to their non-determinism. One of the reasons for that was lack of isolation. Right in the beginning, the acceptance test suite was built to insert all necessary data before running all tests and new test data was added to a SQL script file as needed. After a while tests started to share data like users, users group and other sensitive information. If any other test modifies them, other tests that rely on that data would fail unexpectedly. One solution we found was inserting data before each test. Instead of having a single script with all test data, we programmatically added only the necessary data for a single test to run. Although it increased test running time, this change brought more confidence in the build: when the build failed the team knew that some feature was broken.</p>
<p><strong>7. Group communication channel</strong></p>
<p>I have already said that we were a distributed team and communication was a big challenge. One strategy that really helped our team communication was the creation of an open communication channel were all team members were connected all the time. In our case, we had a Skype group conversation for that and we used it with no restrictions to inform what is going on in the project. Instead of privates and parallels conversations we really recommended using the chat to inform when a user story is ready for QA or blocked, the build broke, the meeting was cancelled and even discuss technical issues. In that sense all team members were in the same page about project&#8217;s event.</p>
<p><strong>Conclusion</strong></p>
<p>I am pretty sure that we as team learned a bunch of other lessons. However, those were the ones that we highlighted in our retrospective. I hope that this list will be useful to you someday. If you have any other topic to add in that list, please fell free to do it as a comment.</p>
<p>Cheers,<br />
Fernando</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nandokakimoto.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nandokakimoto.wordpress.com/646/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nandokakimoto.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nandokakimoto.wordpress.com/646/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nandokakimoto.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nandokakimoto.wordpress.com/646/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nandokakimoto.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nandokakimoto.wordpress.com/646/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nandokakimoto.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nandokakimoto.wordpress.com/646/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nandokakimoto.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nandokakimoto.wordpress.com/646/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nandokakimoto.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nandokakimoto.wordpress.com/646/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=646&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nandokakimoto.wordpress.com/2012/01/15/lessons-learned-from-my-first-thoughtworks-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">nandokakimoto</media:title>
		</media:content>
	</item>
		<item>
		<title>LINQ for JavaScript</title>
		<link>http://nandokakimoto.wordpress.com/2011/06/07/linq-for-javascript/</link>
		<comments>http://nandokakimoto.wordpress.com/2011/06/07/linq-for-javascript/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 01:46:00 +0000</pubDate>
		<dc:creator>nandokakimoto</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[javascript linq js]]></category>

		<guid isPermaLink="false">https://nandokakimoto.wordpress.com/?p=639</guid>
		<description><![CDATA[LINQ is one of my favorite features in the C# language so far. There is no such a thing as filtering, ordering and grouping data using an easy and fluent API. In the last weeks I found myself writing lot of JavaScript code. More than just ajax calls, DOM manipulation and fancy animations, my team [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=639&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>LINQ is one of my favorite features in the C# language so far. There is no such a thing as filtering, ordering and grouping data using an easy and fluent API. In the last weeks I found myself writing lot of JavaScript code. More than just ajax calls, DOM manipulation and fancy animations, my team and I maintain a huge js model which includes entities, controllers and repositories. Because of that, many of the operations that we regularly implement in server-side are implemented in client-side as well such as finding, sorting and grouping elements in data collections. On the server we use LINQ to perform such operations, but how to implement them in JavaScript?</p>
<p>Luckly, there is a JavaScript library that provides all LINQ operations with a very similar sintaxe. Just as C#, LINQ for JavaScript operates under IEnumerable objects. Therefore, the first thing to do is create an IEnumarable object with the <span style="text-decoration:underline;"><strong>FROM</strong> </span>function. To illustrate the library usage, I will start with an array of people. The code below includes the Person object definition and the creation of an enumerable of people from an array. Very straightforward.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/06/init-person.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="init-person" src="http://nandokakimoto.files.wordpress.com/2011/06/init-person_thumb.png?w=580&#038;h=357" alt="init-person" width="580" height="357" border="0" /></a></p>
<p>Since the enumerable is created, we are free to perform all LINQ operation on it. Let’s start with a simple search: I want to find the person whose name is ‘Fernando’. The code below illustrates that. Notice the sintaxt used by the library. While in C# we write lambda expressions (x =&gt; x.Name), here we use the symbol <strong>$.</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/06/first.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="first" src="http://nandokakimoto.files.wordpress.com/2011/06/first_thumb.png?w=602&#038;h=137" alt="first" width="602" height="137" border="0" /></a></p>
<p>Next, we filter the collection with the people with age greater then 25 and select their names.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/06/where.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="where" src="http://nandokakimoto.files.wordpress.com/2011/06/where_thumb.png?w=588&#038;h=145" alt="where" width="588" height="145" border="0" /></a></p>
<p>Next, we order the collection by age and select their names.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/06/order.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="order" src="http://nandokakimoto.files.wordpress.com/2011/06/order_thumb.png?w=590&#038;h=143" alt="order" width="590" height="143" border="0" /></a></p>
<p>Finally, we group the collection by sex. In addition, each group is ordered by name.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/06/groupby.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="groupBy" src="http://nandokakimoto.files.wordpress.com/2011/06/groupby_thumb.png?w=892&#038;h=227" alt="groupBy" width="892" height="227" border="0" /></a></p>
<p>As you can see, there is no secret. The sintaxe is really really similiar. I could show others the operations here, but they are all avaible in the library’s documentation. So, if you got interested by LINQ for JavaScript, take a look in the <a title="LINQ for JavaScript" href="http://linqjs.codeplex.com/" target="_blank">project page on codeplex</a>. It helped me a lot and hope it can bu useful for you as well.</p>
<p>See you,<br />
Fernando</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nandokakimoto.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nandokakimoto.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nandokakimoto.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nandokakimoto.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nandokakimoto.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nandokakimoto.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nandokakimoto.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nandokakimoto.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nandokakimoto.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nandokakimoto.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nandokakimoto.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nandokakimoto.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nandokakimoto.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nandokakimoto.wordpress.com/639/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=639&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nandokakimoto.wordpress.com/2011/06/07/linq-for-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">nandokakimoto</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/06/init-person_thumb.png" medium="image">
			<media:title type="html">init-person</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/06/first_thumb.png" medium="image">
			<media:title type="html">first</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/06/where_thumb.png" medium="image">
			<media:title type="html">where</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/06/order_thumb.png" medium="image">
			<media:title type="html">order</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/06/groupby_thumb.png" medium="image">
			<media:title type="html">groupBy</media:title>
		</media:content>
	</item>
		<item>
		<title>JavaScript Immetiate Object Initialization</title>
		<link>http://nandokakimoto.wordpress.com/2011/05/17/javascript-immetiate-object-initialization/</link>
		<comments>http://nandokakimoto.wordpress.com/2011/05/17/javascript-immetiate-object-initialization/#comments</comments>
		<pubDate>Tue, 17 May 2011 02:59:46 +0000</pubDate>
		<dc:creator>nandokakimoto</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[extensible]]></category>
		<category><![CDATA[maintainable]]></category>
		<category><![CDATA[object-oriented]]></category>

		<guid isPermaLink="false">https://nandokakimoto.wordpress.com/?p=597</guid>
		<description><![CDATA[Hello everyone, During this weekend I watched a couple of sessions in channel 9 recorded during the MIX 11 event. I really liked Elijah Manor’s talk whose title is Good JavaScript Habits for C# Developers. In addition to simple tips on JavaScript programming, such as False-y Values and Comparison Operators, Elijah showed some techniques that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=597&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hello everyone, </p>
<p>During this weekend I watched a couple of <a href="http://channel9.msdn.com/events/ch9live/mix11" target="_blank">sessions in channel 9</a> recorded during the MIX 11 event. I really liked Elijah Manor’s talk whose title is <a href="http://channel9.msdn.com/Events/MIX/MIX11/OPN08" target="_blank">Good JavaScript Habits for C# Developers</a>. In addition to simple tips on JavaScript programming, such as False-y Values and Comparison Operators, Elijah showed some techniques that not every JavaScript programmer is aware of. One of them is using Immediate Functions for creating objects in modularized applications. Today, I will share how to do that.</p>
<p>First of all, let’s understand what the term Immediate Function refers to. It is a sintax that enables you to execute a function as soon as it is defined. This pattern is used to wrap an amount of work without leaving any global variables behind. Here is an example:</p>
<p><strong>example1.js</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/05/example1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="example1" border="0" alt="example1" src="http://nandokakimoto.files.wordpress.com/2011/05/example1_thumb.png?w=415&#038;h=180" width="415" height="180" /></a></p>
<p>Using this pattern we are able to instantiate JavaScript objects without polluting global space with temporary variables. Moreover, the pattern supports the creation of modularized apps by extending existing objects on demand. Let me illustrate it with an example. Imagine we are creating a bookstore. For now, we just need <em><u>add</u></em>, <u><em>remove</em> </u>and <em><u>getAll</u></em> operations. Here is the first version of the bookstore object:</p>
<p><strong>bookstore.js</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/05/bookstore.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="bookstore" border="0" alt="bookstore" src="http://nandokakimoto.files.wordpress.com/2011/05/bookstore_thumb.png?w=866&#038;h=407" width="866" height="407" /></a></p>
<p>Notice the <u><em>bookstore</em></u> parameter in line 1. We use this variable thoughout the Immediate Function to append new operations to it. In line 25 we pass a new object to the <em><u>bookstore</u></em> and keep it in a global variable <em><u>window.bookstore</u></em>, which enables us to<strong> </strong>access <em><u>bookstore</u> </em>anytime in our application. In addition, after the function is executed the variable <em><u>books</u></em> is discarted maintaining the global space clear. </p>
<p>Now, imagine later on the project we need additional operations such as <em><u>sortByTitle</u></em> and <em><u>filterByAuhtor</u></em>. This can be easily done by creating a new file and appending new operations to the <em><u>bookstore</u><strong> </strong></em>object, such as the example below:</p>
<p><strong>bookstore-extensions.js</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/05/bookstore-extensions1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="bookstore-extensions" border="0" alt="bookstore-extensions" src="http://nandokakimoto.files.wordpress.com/2011/05/bookstore-extensions_thumb1.png?w=508&#038;h=179" width="508" height="179" /></a></p>
<p>This piece of code is similiar to the last one, except by the parameter passed to the Immediate Function in line 11, which uses the existing <em><u>bookstore</u></em> instance. That way, new operations are added to the <em><u>bookstore</u></em> object and all temporary variables are discarted after the function is executed. Later, we can combine all the JavaScript files and deploy it as a single bookstore.</p>
<p>This pattern is also useful to avoid variable overlapping between different libraries. A very common example is the dollar sign ($) which is used by different existing JavaScript libraries. To make sure the sign refes to jQuery library, for example, we make it a parameter in the Immediate Function and pass the jQuery instance in the initizalization. See the example below:</p>
<p><strong>bookstore-ajax.js</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/05/bookstore-ajax1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="bookstore-ajax" border="0" alt="bookstore-ajax" src="http://nandokakimoto.files.wordpress.com/2011/05/bookstore-ajax_thumb1.png?w=381&#038;h=196" width="381" height="196" /></a></p>
<p>That’s it guys.    <br />For more tips on JavaScript programming, take a look at <a href="http://channel9.msdn.com/Events/MIX/MIX11/OPN08" target="_blank">Elijah Manor’s talk</a>, there are lots of others stuff there. Also, if you are looking for a good JavaScript reference, I strongly recommend the <a href="http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752" target="_blank">JavaScript Patterns</a> book by Stoyan Stefanov which includes lots of samples of how to create JavaScript code for large ans scalable applications.</p>
<p>See you,    <br />Fernando</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nandokakimoto.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nandokakimoto.wordpress.com/597/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nandokakimoto.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nandokakimoto.wordpress.com/597/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nandokakimoto.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nandokakimoto.wordpress.com/597/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nandokakimoto.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nandokakimoto.wordpress.com/597/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nandokakimoto.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nandokakimoto.wordpress.com/597/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nandokakimoto.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nandokakimoto.wordpress.com/597/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nandokakimoto.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nandokakimoto.wordpress.com/597/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=597&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nandokakimoto.wordpress.com/2011/05/17/javascript-immetiate-object-initialization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">nandokakimoto</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/05/example1_thumb.png" medium="image">
			<media:title type="html">example1</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/05/bookstore_thumb.png" medium="image">
			<media:title type="html">bookstore</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/05/bookstore-extensions_thumb1.png" medium="image">
			<media:title type="html">bookstore-extensions</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/05/bookstore-ajax_thumb1.png" medium="image">
			<media:title type="html">bookstore-ajax</media:title>
		</media:content>
	</item>
		<item>
		<title>Binding JS array to C# list in ASP.NET MVC</title>
		<link>http://nandokakimoto.wordpress.com/2011/04/21/binding-js-array-to-c-list-in-asp-net-mvc/</link>
		<comments>http://nandokakimoto.wordpress.com/2011/04/21/binding-js-array-to-c-list-in-asp-net-mvc/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 14:59:06 +0000</pubDate>
		<dc:creator>nandokakimoto</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://nandokakimoto.wordpress.com/2011/04/21/binding-js-array-to-c-list-in-asp-net-mvc/</guid>
		<description><![CDATA[Hey guys, This will be a very short post about a problem that I faced this week while writing some JavaScript code. At first sight, the acticity should be a very simple one: send an array of data from client to server via AJAX. My pair and I tried a simple POST request similiar to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=596&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hey guys, </p>
<p>This will be a very short post about a problem that I faced this week while writing some JavaScript code.</p>
<p>At first sight, the acticity should be a very simple one: send an array of data from client to server via AJAX. My pair and I tried a simple POST request similiar to the code below:</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/04/image1.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image1" border="0" alt="image1" src="http://nandokakimoto.files.wordpress.com/2011/04/image1_thumb.png?w=285&#038;h=210" width="285" height="210" /></a></p>
<p>Unfortunately, the parameter is always <font color="#0000ff">null </font><font color="#000000">in the server</font>.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/04/image2.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image2" border="0" alt="image2" src="http://nandokakimoto.files.wordpress.com/2011/04/image2_thumb.png?w=430&#038;h=103" width="430" height="103" /></a></p>
<p>After some time wasted reading the code looking for erros, we decided to verify the post data sent by the browser. That is what Firebug showed to us:</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/04/image3.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image3" border="0" alt="image3" src="http://nandokakimoto.files.wordpress.com/2011/04/image3_thumb.png?w=466&#038;h=235" width="466" height="235" /></a></p>
<p>We then realized that the serialization of the array is wrong. But why? Let’s take a look at jQuery’s documentation, more specifically about jquery.Ajax() data setting. </p>
<p><em>data: Data to be sent to the server. It is converted to a query string, if not already a string. It&#8217;s appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. <strong>If value is an Array, jQuery serializes multiple values with same key based on the value of the traditional setting</strong>.</em></p>
<p>Traditional option regards the parameter serialization style. That is a clue. Going a little deeper in our search we found this:</p>
<p><em>“As of jQuery 1.4, the <code>$.param()</code> method serializes deep objects recursively to accommodate modern scripting languages and frameworks such as PHP and Ruby on Rails. You can disable this functionality globally by setting <code>jQuery.ajaxSettings.traditional = true;</code>.”</em></p>
<p>Now, we know the reason. Due to the way other web frameworks handle JSON parameters, jQuery serialization changed the way arrays are serialized. Therefore, we as .NET developers need to use the <em>traditional = true </em>setting.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/04/image4.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image4" border="0" alt="image4" src="http://nandokakimoto.files.wordpress.com/2011/04/image4_thumb.png?w=279&#038;h=230" width="279" height="230" /></a></p>
<p>And Boommmm… it works perfectly. Let’s take a look at the request’s paremeters.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/04/image5.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image5" border="0" alt="image5" src="http://nandokakimoto.files.wordpress.com/2011/04/image5_thumb.png?w=531&#038;h=237" width="531" height="237" /></a></p>
<p>That is what ASP.NET MVC needs <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Alegre" src="http://nandokakimoto.files.wordpress.com/2011/04/wlemoticon-smile.png" /></p>
<p>That’s it guys.</p>
<p>See you,   <br />Fernando </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nandokakimoto.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nandokakimoto.wordpress.com/596/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nandokakimoto.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nandokakimoto.wordpress.com/596/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nandokakimoto.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nandokakimoto.wordpress.com/596/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nandokakimoto.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nandokakimoto.wordpress.com/596/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nandokakimoto.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nandokakimoto.wordpress.com/596/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nandokakimoto.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nandokakimoto.wordpress.com/596/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nandokakimoto.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nandokakimoto.wordpress.com/596/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=596&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nandokakimoto.wordpress.com/2011/04/21/binding-js-array-to-c-list-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">nandokakimoto</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/04/image1_thumb.png" medium="image">
			<media:title type="html">image1</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/04/image2_thumb.png" medium="image">
			<media:title type="html">image2</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/04/image3_thumb.png" medium="image">
			<media:title type="html">image3</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/04/image4_thumb.png" medium="image">
			<media:title type="html">image4</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/04/image5_thumb.png" medium="image">
			<media:title type="html">image5</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/04/wlemoticon-smile.png" medium="image">
			<media:title type="html">Alegre</media:title>
		</media:content>
	</item>
		<item>
		<title>Extending ASP.NET MVC Model Binding Mechanism</title>
		<link>http://nandokakimoto.wordpress.com/2011/03/26/extending-asp-net-mvc-model-binding-mechanism/</link>
		<comments>http://nandokakimoto.wordpress.com/2011/03/26/extending-asp-net-mvc-model-binding-mechanism/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 22:30:57 +0000</pubDate>
		<dc:creator>nandokakimoto</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://nandokakimoto.wordpress.com/?p=575</guid>
		<description><![CDATA[Hey guys, In the last posts I’ve talked about the use of Moq framework when writing ASP.NET MVC unit tests. Today, I will be talking about ASP.NET MVC Model Binding mechanism and how to extend it to make your life easier when writing testable web applications. [I have written a similar post on SharpShooters blog, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=575&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hey guys, </p>
<p>In the last posts I’ve talked about the use of Moq framework when writing ASP.NET MVC unit tests. Today, I will be talking about ASP.NET MVC Model Binding mechanism and how to extend it to make your life easier when writing testable web applications. [I have written a similar post on <a href="http://www.sharpshooters.com.br/blog/2011/02/09/asp-net-mvc-model-binding/" target="_blank">SharpShooters blog</a>, but it is in portuguese]</p>
<p>Basically, Model Binding is the mechanism that ASP.NET MVC framework uses for mapping HTTP Request variables into Actions’ parameters. In other words, every time you submit a form to a Controller, the Model Binding mechanism passes through all variables submitted trying to match them with Actions’ parameters using a very specific standard. The standard is “<strong>parameterName</strong>.<strong>PropertyName</strong>”. To illustrate how things happen, let’s use a small example. Imagine that we want to implement a blog platform which allows the creation of posts with title and content. Model, View and Controller for creating it are illustrated below:</p>
<p><strong>Post.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/postwithoutuser.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="PostWithoutUser" border="0" alt="PostWithoutUser" src="http://nandokakimoto.files.wordpress.com/2011/03/postwithoutuser_thumb.png?w=397&#038;h=189" width="397" height="189" /></a></p>
<p><strong>Create.aspx</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/createview.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="CreateView" border="0" alt="CreateView" src="http://nandokakimoto.files.wordpress.com/2011/03/createview_thumb.png?w=486&#038;h=405" width="486" height="405" /></a></p>
<p><strong>PostController.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/createcontrollerwithoutuser.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="CreateControllerWithoutUser" border="0" alt="CreateControllerWithoutUser" src="http://nandokakimoto.files.wordpress.com/2011/03/createcontrollerwithoutuser_thumb.png?w=360&#038;h=194" width="360" height="194" /></a></p>
<p>As you already know, the Create Action receives newPost parameter with all the information submitted in the form. However, if the ASP.NET MVC Team hadn’t implemented Model Binding, we would need to type something like this:</p>
<p><strong>Create.aspx</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/requestcreateview.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="RequestCreateView" border="0" alt="RequestCreateView" src="http://nandokakimoto.files.wordpress.com/2011/03/requestcreateview_thumb.png?w=475&#038;h=389" width="475" height="389" /></a></p>
<p><strong>PostController.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/requestcreatecontroller.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="RequestCreateController" border="0" alt="RequestCreateController" src="http://nandokakimoto.files.wordpress.com/2011/03/requestcreatecontroller_thumb.png?w=386&#038;h=194" width="386" height="194" /></a></p>
<p>In short, Model Binding is responsible for binding values passed in HTTP Requests to Actions’ parameters. </p>
<p>Now that we already know what Model Binding is about, we can extend it to bind any parameter we want. Imagine that we want to add a User to a Post. Class and Controller would have to change to something similar to this:</p>
<p><strong>Post.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/postwithuser.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="PostWithUser" border="0" alt="PostWithUser" src="http://nandokakimoto.files.wordpress.com/2011/03/postwithuser_thumb.png?w=473&#038;h=213" width="473" height="213" /></a></p>
<p><strong>Controller.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollerwithuser.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="PostControllerWithUser" border="0" alt="PostControllerWithUser" src="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollerwithuser_thumb.png?w=364&#038;h=269" width="364" height="269" /></a></p>
<p>Although this code works, it is very difficult to test since I need to mock <strong>User.Identity.Name</strong>. I can mock it using a technique presented by Michael Feathers in his excellent book <a href="http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052" target="_blank">Working Effectively With Legacy Code</a> which basically involves two steps:</p>
<p>1. Extract the piece of code in a protected virtual function;</p>
<p>2. Create a mock which inherit from PostController and overrides the protected function by returning a specific username;</p>
<p>PostController class would result in the code below.</p>
<p><strong>PostController.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollerprotected.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="PostControllerProtected" border="0" alt="PostControllerProtected" src="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollerprotected_thumb.png?w=401&#038;h=338" width="401" height="338" /></a></p>
<p>And here is the test for the controller class.</p>
<p><strong>MockPostController.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/mockpostcontroller.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="MockPostController" border="0" alt="MockPostController" src="http://nandokakimoto.files.wordpress.com/2011/03/mockpostcontroller_thumb.png?w=669&#038;h=212" width="669" height="212" /></a></p>
<p><strong>MockControllerTest.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollertestprotected.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="PostControllerTestProtected" border="0" alt="PostControllerTestProtected" src="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollertestprotected_thumb.png?w=720&#038;h=338" width="720" height="338" /></a></p>
<p>Now, the test pass <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>However, every time that a User is referenced by other class, this approach is needed. Imagine we have another entity, for example Comments, which has a reference to User as well. The same solution would be used to test CommentsController class. It would be great if we could pass the User as a parameter in PostController.Create action, wouldn’t be? Something like this:</p>
<p><strong>PostController.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollerwithtwoparameters.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="PostControllerWithTwoParameters" border="0" alt="PostControllerWithTwoParameters" src="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollerwithtwoparameters_thumb.png?w=383&#038;h=230" width="383" height="230" /></a></p>
<p>To do that, we need to extend ModelBinding mechanism so it can bind the value of a User type. This is really simple. All we have to do is implement <strong>IModelBinder </strong>interface and register it in the Global.asax. The code below shows the extension.</p>
<p><strong>UserModelBinder.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/usermodelbinder.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="UserModelBinder" border="0" alt="UserModelBinder" src="http://nandokakimoto.files.wordpress.com/2011/03/usermodelbinder_thumb.png?w=717&#038;h=273" width="717" height="273" /></a></p>
<p><strong>Global.asax</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/global.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="Global" border="0" alt="Global" src="http://nandokakimoto.files.wordpress.com/2011/03/global_thumb.png?w=479&#038;h=147" width="479" height="147" /></a></p>
<p>Everything is now configured and we don’t need to worry about retrieving the logged user anymore. </p>
<p>In adittion to that, it’s much more easy to test PostController class. We can create a new user and pass it as parameter, as shown below.</p>
<p><strong>PostControllerTest.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollertestwithtwoparameters.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="PostControllerTestWithTwoParameters" border="0" alt="PostControllerTestWithTwoParameters" src="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollertestwithtwoparameters_thumb.png?w=694&#038;h=317" width="694" height="317" /></a></p>
<p>To conclude, Model Binding is a very importante feature of ASP.NET MVC framework, saving us a lot of work. It is also extensible and allows us to create our own bindings and testable applications.</p>
<p>Hope it’s usefull for you someday <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>See you,    <br />Fernando</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nandokakimoto.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nandokakimoto.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nandokakimoto.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nandokakimoto.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nandokakimoto.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nandokakimoto.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nandokakimoto.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nandokakimoto.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nandokakimoto.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nandokakimoto.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nandokakimoto.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nandokakimoto.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nandokakimoto.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nandokakimoto.wordpress.com/575/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=575&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nandokakimoto.wordpress.com/2011/03/26/extending-asp-net-mvc-model-binding-mechanism/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">nandokakimoto</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/postwithoutuser_thumb.png" medium="image">
			<media:title type="html">PostWithoutUser</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/createview_thumb.png" medium="image">
			<media:title type="html">CreateView</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/createcontrollerwithoutuser_thumb.png" medium="image">
			<media:title type="html">CreateControllerWithoutUser</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/requestcreateview_thumb.png" medium="image">
			<media:title type="html">RequestCreateView</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/requestcreatecontroller_thumb.png" medium="image">
			<media:title type="html">RequestCreateController</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/postwithuser_thumb.png" medium="image">
			<media:title type="html">PostWithUser</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollerwithuser_thumb.png" medium="image">
			<media:title type="html">PostControllerWithUser</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollerprotected_thumb.png" medium="image">
			<media:title type="html">PostControllerProtected</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/mockpostcontroller_thumb.png" medium="image">
			<media:title type="html">MockPostController</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollertestprotected_thumb.png" medium="image">
			<media:title type="html">PostControllerTestProtected</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollerwithtwoparameters_thumb.png" medium="image">
			<media:title type="html">PostControllerWithTwoParameters</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/usermodelbinder_thumb.png" medium="image">
			<media:title type="html">UserModelBinder</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/global_thumb.png" medium="image">
			<media:title type="html">Global</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/03/postcontrollertestwithtwoparameters_thumb.png" medium="image">
			<media:title type="html">PostControllerTestWithTwoParameters</media:title>
		</media:content>
	</item>
		<item>
		<title>TDD in ASP.NET MVC Applications with Moq Framework</title>
		<link>http://nandokakimoto.wordpress.com/2011/02/13/tdd-in-asp-net-mvc-applications-with-moq-framework/</link>
		<comments>http://nandokakimoto.wordpress.com/2011/02/13/tdd-in-asp-net-mvc-applications-with-moq-framework/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 16:32:29 +0000</pubDate>
		<dc:creator>nandokakimoto</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://nandokakimoto.wordpress.com/?p=545</guid>
		<description><![CDATA[Last post, I introduced the use of Moq framework to code unit tests in .NET applications. Today, I’ll use Moq to test my ASP.NET MVC controllers. One of the key benefits of ASP.NET MVC is the facility to set up automated tests and use methodologies such as TDD (Test-Driven Development). Using the Red-Green-Refactor mantra, we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=545&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Last post, I introduced the use of Moq framework to code unit tests in .NET applications. Today, I’ll use Moq to test my ASP.NET MVC controllers.</p>
<p>One of the key benefits of ASP.NET MVC is the facility to set up automated tests and use methodologies such as <a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank">TDD (Test-Driven Development)</a>. Using the <a href="http://geekswithblogs.net/WillSmith/archive/2008/03/18/red-green-refactor.aspx" target="_blank">Red-Green-Refactor mantra</a>, we can create testable ASP.NET MVC controllers and <a href="http://blog.jtimothyking.com/2006/07/11/twelve-benefits-of-writing-unit-tests-first" target="_blank">benefit from the use of TDD</a>. So, let’s start.</p>
<p>In this post, we will develop part of a sport store web site responsible for managing products through CRUD operations. First of all, I will create a new ASP.NET MVC Empty Application and a Test Project in Visual Studio 2010. Next, I will create <strong>ProductController.cs</strong>, responsible for handling requests from all CRUD operations that we are going to provide. Right now, our controller looks like the code below.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/02/image-1.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image-1" border="0" alt="image-1" src="http://nandokakimoto.files.wordpress.com/2011/02/image-1_thumb.png?w=329&#038;h=201" width="329" height="201" /></a></p>
<p>The first thing we nedd is a <em>List</em> view where adminitrators can see all existing products, manage products from the list and add new products to the application. For now, we know that we need to pass all products to the view. It is time to write our first test case which demonstrates that behaviour. After some work, here is my test for <em>List</em> operation.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/02/image-2.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image-2" border="0" alt="image-2" src="http://nandokakimoto.files.wordpress.com/2011/02/image-2_thumb.png?w=587&#038;h=486" width="587" height="486" /></a></p>
<p>Notice that after writing my test, two new classes appeared: <strong>Product</strong> and <strong>IProductRepository</strong>. In addition to that, we added a dependency between <strong>ProductController</strong> and <strong>IProductRepository</strong>. What we are doing here is designing our code while writing tests, which means that we are creating <a href="http://haacked.com/archive/2007/11/14/writing-testable-code-is-about-managing-complexity.aspx" target="_blank">testable code</a>. In the test above, we are saying that <em>FindAll</em> method will <em>Returns </em>the list we’ve created with four products and verifying the those products where passed to the view. That simple!</p>
<p>Now that we have a test, let’s run it to see if it pass. Unfortunately, it failed because we did not wrote the implementation for it yet. That is how our controller looks like until now.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/02/image-3.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image-3" border="0" alt="image-3" src="http://nandokakimoto.files.wordpress.com/2011/02/image-3_thumb.png?w=489&#038;h=246" width="489" height="246" /></a></p>
<p>After coding the right <em>List</em> method behavior, shown below, our test pass successfully. Notice that we didn’t write any data access layer code for <strong>Product</strong> yet. By using the Moq framework, we could fake repository’s behaviour and forget about those boring database scripts and mapping files.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/02/image-4.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image-4" border="0" alt="image-4" src="http://nandokakimoto.files.wordpress.com/2011/02/image-4_thumb.png?w=489&#038;h=249" width="489" height="249" /></a></p>
<p>The next step is create the <em>Save</em> operation. Let’s use the same approach, starting with a test case. The test implementation is shown below.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/02/image-5.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image-5" border="0" alt="image-5" src="http://nandokakimoto.files.wordpress.com/2011/02/image-5_thumb.png?w=507&#038;h=361" width="507" height="361" /></a></p>
<p>The test above says that when saving a product, the method <em>SaveOrUpdate</em> from <strong>IProductRepository </strong>is called once and the user is redirected to <em>List</em> action. Again, this test fail because we haven’t implemented that behaviour in <strong>ProductController</strong>. After writing the code below, our test pass with success.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/02/image-6.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image-6" border="0" alt="image-6" src="http://nandokakimoto.files.wordpress.com/2011/02/image-6_thumb.png?w=489&#038;h=347" width="489" height="347" /></a></p>
<p>We are going just fine. However, our tests are starting to present some code duplications. Now, it’s clear that we need to refactor it (Red-Green-Refactor, rememeber?). After some work on it, our test class look like that:</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/02/image-7.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image-7" border="0" alt="image-7" src="http://nandokakimoto.files.wordpress.com/2011/02/image-7_thumb.png?w=586&#038;h=907" width="586" height="907" /></a></p>
<p>Until now, we tested just the base case. What happens if a user tries to save an invalid model? We have to deal with that in our controller. Let’s write a new test case for it.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/02/image-8.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image-8" border="0" alt="image-8" src="http://nandokakimoto.files.wordpress.com/2011/02/image-8_thumb.png?w=584&#038;h=324" width="584" height="324" /></a></p>
<p>This time, we verify that <em>SaveOrUpdate</em> method is never called and the user continues in the same view. Again, the test fail. Here is the new <em>Save</em> implementation that makes the above test pass.</p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/02/image-9.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image-9" border="0" alt="image-9" src="http://nandokakimoto.files.wordpress.com/2011/02/image-9_thumb.png?w=488&#038;h=522" width="488" height="522" /></a></p>
<p>To complete our task of creating a full CRUD for our controller, we still need to implement Delete and Update. However, I will leave it for you as homework <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Alegre" src="http://nandokakimoto.files.wordpress.com/2011/02/wlemoticon-smile.png" /></p>
<p>In short, I have shown how to use TDD while creating an ASP.NET MVC application and Moq Framework to isolate presentation layer tests from any other layer of the system.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nandokakimoto.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nandokakimoto.wordpress.com/545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nandokakimoto.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nandokakimoto.wordpress.com/545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nandokakimoto.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nandokakimoto.wordpress.com/545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nandokakimoto.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nandokakimoto.wordpress.com/545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nandokakimoto.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nandokakimoto.wordpress.com/545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nandokakimoto.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nandokakimoto.wordpress.com/545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nandokakimoto.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nandokakimoto.wordpress.com/545/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=545&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nandokakimoto.wordpress.com/2011/02/13/tdd-in-asp-net-mvc-applications-with-moq-framework/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">nandokakimoto</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/02/image-1_thumb.png" medium="image">
			<media:title type="html">image-1</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/02/image-2_thumb.png" medium="image">
			<media:title type="html">image-2</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/02/image-3_thumb.png" medium="image">
			<media:title type="html">image-3</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/02/image-4_thumb.png" medium="image">
			<media:title type="html">image-4</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/02/image-5_thumb.png" medium="image">
			<media:title type="html">image-5</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/02/image-6_thumb.png" medium="image">
			<media:title type="html">image-6</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/02/image-7_thumb.png" medium="image">
			<media:title type="html">image-7</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/02/image-8_thumb.png" medium="image">
			<media:title type="html">image-8</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/02/image-9_thumb.png" medium="image">
			<media:title type="html">image-9</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/02/wlemoticon-smile.png" medium="image">
			<media:title type="html">Alegre</media:title>
		</media:content>
	</item>
		<item>
		<title>Unit Testing .NET Application with Moq Framework</title>
		<link>http://nandokakimoto.wordpress.com/2011/01/02/unit-testing-net-application-with-moq-framework/</link>
		<comments>http://nandokakimoto.wordpress.com/2011/01/02/unit-testing-net-application-with-moq-framework/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 16:43:11 +0000</pubDate>
		<dc:creator>nandokakimoto</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[moq]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://nandokakimoto.wordpress.com/?p=516</guid>
		<description><![CDATA[Hi guys, It&#8217;s been a while since my last post here. In 2011 however I will try to come back to my routine of posting something new at least once a month. Today, I will share with you the way I&#8217;ve been writing tests for my ASP.NET applications using Moq framework. So let&#8217;s start. Firstly, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=516&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi guys,</p>
<p>It&#8217;s been a while since my last post here. In 2011 however I will try to come back to my routine of posting something new at least once a month. Today, I will share with you the way I&#8217;ve been writing tests for my ASP.NET applications using Moq framework.</p>
<p>So let&#8217;s start.</p>
<p>Firstly, it&#8217;s important to know a little about mocking objects. As the name already suggest, unit tests should verify the behavior of a single unit of your code. For that reason, the code been tested must be isolated from any other dependencies that it has. The simplest example is a business logic test with database manipulation. See the code below</p>
<p><strong>ProductBusiness.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/01/productbusiness.png"><img class="alignnone size-full wp-image-517" title="ProductBusiness" src="http://nandokakimoto.files.wordpress.com/2011/01/productbusiness.png" alt="" width="564" height="388" /></a></p>
<p><strong>ProductBusinessTest.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/01/businesstest.png"><img class="alignnone size-full wp-image-518" title="BusinessTest" src="http://nandokakimoto.files.wordpress.com/2011/01/businesstest.png" alt="" width="570" height="681" /></a></p>
<p>When testing business validation, the programmer does not have to access the database for that. In other words, your code should be isolated from the data layer. To do that while testing, you must create mock object (simulated objects that mimic the behavior of real objects in controlled ways). One way of doing that is using Moq framework. See the code below, now using the Moq framework.</p>
<p><strong>ProductBusinessWithMoqTest.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2011/01/productbusinesswithmock.png"><img class="alignnone size-full wp-image-519" title="ProductBusinessWithMock" src="http://nandokakimoto.files.wordpress.com/2011/01/productbusinesswithmock.png" alt="" width="571" height="786" /></a></p>
<p>As you can see, now I am able to determine the behavior of my data layer by creating a mock object with a specific behavior. Therefore, I isolated my test from any dependency it had. To know more about Moq framework, you can look at http://code.google.com/p/moq/wiki/QuickStart</p>
<p>In the next post, I will show how I use Moq to test my controller in ASP.NET MVC application.</p>
<p>See you,<br />
Fernando</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nandokakimoto.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nandokakimoto.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nandokakimoto.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nandokakimoto.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nandokakimoto.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nandokakimoto.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nandokakimoto.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nandokakimoto.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nandokakimoto.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nandokakimoto.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nandokakimoto.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nandokakimoto.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nandokakimoto.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nandokakimoto.wordpress.com/516/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=516&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nandokakimoto.wordpress.com/2011/01/02/unit-testing-net-application-with-moq-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">nandokakimoto</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/01/productbusiness.png" medium="image">
			<media:title type="html">ProductBusiness</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/01/businesstest.png" medium="image">
			<media:title type="html">BusinessTest</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2011/01/productbusinesswithmock.png" medium="image">
			<media:title type="html">ProductBusinessWithMock</media:title>
		</media:content>
	</item>
		<item>
		<title>.NetArchitects Coding Dojo &#8211; Converting Roman Numerals to Decimal</title>
		<link>http://nandokakimoto.wordpress.com/2010/05/16/coding-dojo-converting-roman-numerals-to-decimal/</link>
		<comments>http://nandokakimoto.wordpress.com/2010/05/16/coding-dojo-converting-roman-numerals-to-decimal/#comments</comments>
		<pubDate>Sun, 16 May 2010 18:10:23 +0000</pubDate>
		<dc:creator>nandokakimoto</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[codingdojo]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.netarchitects]]></category>
		<category><![CDATA[convert roman numeral]]></category>
		<category><![CDATA[dojo]]></category>

		<guid isPermaLink="false">http://nandokakimoto.wordpress.com/?p=492</guid>
		<description><![CDATA[Hi guys, As some of you who follow me at @nandokakimoto already know, last week I participated in the first Coding Dojo from Recife’s .NetArchitects group and it was really great. There, I met some friendly faces and after a short conversation about the Coding Dojo practice, @WaldyrFelix brought the problem of adding Roman numerals. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=492&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi guys,</p>
<p>As some of you who follow me at <a href="http://twitter.com/nandokakimoto">@nandokakimoto</a> already know, last week I participated in the first Coding Dojo from Recife’s .NetArchitects group and it was really great. There, I met some friendly faces and after a short conversation about the Coding Dojo practice, <a href="http://twitter.com/WaldyrFelix">@WaldyrFelix</a> brought the problem of adding Roman numerals.</p>
<p>After some discussion about the alternatives, we decided to accomplish the challenge by converting both numbers to decimal, add them and later convert the result back to a Roman representation. In that moment, I didn’t know if it was a clever decision, but we got stuck in some part of the algorithm of adding Romans. Since them, our mission changed to just convert Roman numerals to Decimal.</p>
<p>In that occasion, we didn’t complete the solution due to some problems of our paring rotation: every time a different member takes the keyboard, a new solution was created. It happened basically because of our inexperience in the Coding Dojo practice and we discussed it a lot in the end of the event.</p>
<p>Do I need to say that I went home with the problem in mind and, of course, thinking in writing the solution for it? I just started writing it today and, I don’t know, 20 minutes later it was done. So I’m here to share my solution with the community and to know the different solutions that each of you guys would write.</p>
<p>That is my piece of code written in C#.</p>
<p><strong>RomanSymbol.cs</strong></p>
<p><a href="http://nandokakimoto.files.wordpress.com/2010/05/symbol.png"><img class="alignnone size-full wp-image-507" title="symbol" src="http://nandokakimoto.files.wordpress.com/2010/05/symbol.png" alt="" width="385" height="221" /></a></p>
<p><strong>RomanConverter.cs</strong></p>
<p><strong><a href="http://nandokakimoto.files.wordpress.com/2010/05/romanconverter.png"><img class="alignnone size-full wp-image-508" title="romanconverter" src="http://nandokakimoto.files.wordpress.com/2010/05/romanconverter.png" alt="" width="795" height="781" /></a></strong></p>
<p><strong><br />
</strong></p>
<p><span style="font-family:monospace;line-height:24px;font-size:15px;color:#444444;"> </span></p>
<p>So, that is the result of the first meeting and I am quite anxious for the next one. I’ll try to write down here all the events and problems given to us. If you want to know what kind of problems we are trying to solve at Coding Dojo events here in Recife, just come back here later in the next days.</p>
<p>See you.</p>
<p>&#8211;<br />
Fernando</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nandokakimoto.wordpress.com/492/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nandokakimoto.wordpress.com/492/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nandokakimoto.wordpress.com/492/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nandokakimoto.wordpress.com/492/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nandokakimoto.wordpress.com/492/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nandokakimoto.wordpress.com/492/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nandokakimoto.wordpress.com/492/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nandokakimoto.wordpress.com/492/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nandokakimoto.wordpress.com/492/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nandokakimoto.wordpress.com/492/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nandokakimoto.wordpress.com/492/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nandokakimoto.wordpress.com/492/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nandokakimoto.wordpress.com/492/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nandokakimoto.wordpress.com/492/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=492&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nandokakimoto.wordpress.com/2010/05/16/coding-dojo-converting-roman-numerals-to-decimal/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">nandokakimoto</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2010/05/symbol.png" medium="image">
			<media:title type="html">symbol</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2010/05/romanconverter.png" medium="image">
			<media:title type="html">romanconverter</media:title>
		</media:content>
	</item>
		<item>
		<title>Community Launch PE/DEV</title>
		<link>http://nandokakimoto.wordpress.com/2010/04/13/community-launch-pedev/</link>
		<comments>http://nandokakimoto.wordpress.com/2010/04/13/community-launch-pedev/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 02:36:32 +0000</pubDate>
		<dc:creator>nandokakimoto</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[software design]]></category>

		<guid isPermaLink="false">http://nandokakimoto.wordpress.com/?p=488</guid>
		<description><![CDATA[Hello guys, it has been a long time since my last post, but I&#8217;m back to announce a really nice event here in my city (Recife, Brazil) in which I will be speaking about Design Patterns with C#. Because the topic is very well known, I will try to bring others topics to my talk, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=488&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://nandokakimoto.files.wordpress.com/2010/04/logo-community-launch.png"><img class="alignnone size-full wp-image-489" title="logo-community-launch" src="http://nandokakimoto.files.wordpress.com/2010/04/logo-community-launch.png" alt="" width="740" height="271" /></a></p>
<p>Hello guys,</p>
<p>it has been a long time since my last post, but I&#8217;m back to announce a really nice event here in my city (Recife, Brazil) in which I will be speaking about Design Patterns with C#. Because the topic is very well known, I will try to bring others topics to my talk, such as Anti-patterns and SOLID Principles.</p>
<p>In addition to my presentation, lots of other interesting talks will be given by some friends:</p>
<ul>
<li>News in Visual Studio 2010</li>
<li>Entity Framework 4.0</li>
<li>.NET 4.0</li>
<li>Silverlight 4</li>
<li>ASP.NET 4</li>
<li>Sharepoint 2010</li>
<li>TDD in Visual Studio 2010</li>
<li>WCF 4</li>
<li>ASP.NET MVC 2.0</li>
</ul>
<p>The event will take place at FIR in April 17th and it&#8217;s free of charge. However, seats are limited so <a href="https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032447823&amp;Culture=pt-BR">register now</a> to guarantee yours.</p>
<p>More information on <a href="http://pe.dotnetarchitects.net/">http://pe.dotnetarchitects.net/</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nandokakimoto.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nandokakimoto.wordpress.com/488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nandokakimoto.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nandokakimoto.wordpress.com/488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nandokakimoto.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nandokakimoto.wordpress.com/488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nandokakimoto.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nandokakimoto.wordpress.com/488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nandokakimoto.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nandokakimoto.wordpress.com/488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nandokakimoto.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nandokakimoto.wordpress.com/488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nandokakimoto.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nandokakimoto.wordpress.com/488/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=488&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nandokakimoto.wordpress.com/2010/04/13/community-launch-pedev/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">nandokakimoto</media:title>
		</media:content>

		<media:content url="http://nandokakimoto.files.wordpress.com/2010/04/logo-community-launch.png" medium="image">
			<media:title type="html">logo-community-launch</media:title>
		</media:content>
	</item>
		<item>
		<title>Code performance</title>
		<link>http://nandokakimoto.wordpress.com/2009/08/11/code-performance/</link>
		<comments>http://nandokakimoto.wordpress.com/2009/08/11/code-performance/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 02:32:33 +0000</pubDate>
		<dc:creator>nandokakimoto</dc:creator>
				<category><![CDATA[performance]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[code performance]]></category>
		<category><![CDATA[optimize code]]></category>

		<guid isPermaLink="false">http://nandokakimoto.wordpress.com/?p=481</guid>
		<description><![CDATA[Code performance is one of the most polemics topics in software development process, addressing a lot of issues, for example: When to improve code performance? Should I prioritize legibility or response time? What part of my code should be improved? There is a lot of discussion about code performance and one reason for that is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=481&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Code performance is one of the most polemics topics in software development process, addressing a lot of issues, for example:</p>
<ul>
<li>When to improve code performance?</li>
<li>Should I prioritize legibility or response time?</li>
<li>What part of my code should be improved?</li>
</ul>
<p style="text-align:justify;">There is a lot of discussion about code performance and one reason for that is due to <strong>fast code isn’t the best code</strong>. Code optimization generally affects code legibility, which affects code readability, which affects code maintenance, and so on. So, when you realize that is time to look a bit deeper to your code execution time, you must be aware of some trick aspects.</p>
<p style="text-align:justify;">The first one is the <a href="http://en.wikipedia.org/wiki/Pareto_principle">Pareto Principle</a> (also known as the 80-20 rule) which states that, for many events, roughly 80% of the effects come from 20% of the causes. This is exactly what happens in code optimization: 20% of the routines are responsible for 80% of program’s execution time. Sometimes you take the whole afternoon optimizing a loop which seems to be the cause of the slowness of your program. And after using all your optimization skills, the program looks like the old one. To avoid this kind of situations you should first measure your program’s bottleneck using a profiler tool: remember the 80-20 rule. After finding it and re-writing it using some basic optimizations techniques, you will notice that your code will be 80% faster.</p>
<p style="text-align:justify;">Another tip is not relying on what everyone says about code optimization (me included). Have you ever heard about reducing lines of code, optimizing while coding, or this operation should be faster the other? Well, they are all suspicious.</p>
<p style="text-align:justify;">Lot of programmers thinks that writing routines using just one or two lines of code makes a faster program. Take a look at the code below taken from <a href="http://www.cc2e.com/">Code Complete</a> book.</p>
<p>For i = 1 to 10<br />
a[i] = i<br />
end</p>
<p>a[1] = 1; a[2] = 2; a[3] = 3;<br />
a[4] = 4; a[5] = 5; a[6] = 6;<br />
a[7] = 7; a[8] = 8; a[9] = 9;<br />
a[10] = 10;</p>
<p style="text-align:justify;">Both programs do the same thing. Which one do you think is faster? These programs were compared in the book and here is the result:</p>
<p>For loop<br />
- Visual Basic: 8,47s<br />
- Java: 12,6s</p>
<p>Linear code<br />
- Visual Basic: 3,16s<br />
- Java: 3,23s</p>
<p style="text-align:justify;">In this case, the linear code was more than 60% faster than the “for loop”. Does it prove that as longer as your code, faster it will be? No! This proves that numbers of line and code performance does not have any predictable relationship.</p>
<p style="text-align:justify;">Another very common mistake is optimizing your code while writing it. It is almost impossible to find bottlenecks without any specific tool. Without a profiler, you will probably lose time trying to optimize code that really doesn’t matter for your program performance. In addition, optimizing code while programming take you away from the main focus of it, for example user interaction and legibility. Premature code optimization is generally a bad choice.</p>
<p style="text-align:justify;">So, when optimize code? First, concentrate efforts in creating modular, maintainable program, always aware of making things easy for future changes. When it’s done, measure its performance and optimize if necessary, but only if necessary. As small parts of code consumes a considerable percentage of the whole program’s execution time, measure your code before the modifications and just after them, so you can keep track if your changes are really effectives. Just to illustrate the difference between a readable code and an optimized code, see both examples below:</p>
<p style="text-align:justify;">
<p><pre class="brush: cpp;">
sum = 0;
 for (row = 0; row &lt; rowCount; row++) {
    for ( column = 0; column &lt; columnCount; column++) {
         sum = sum + matrix[row][column];
    }
 }
</pre></p>
<p><pre class="brush: cpp;">
 sum = 0;
 elementPointer = matrix;
 lastElementPointer = matrix[rowCount-1][columnCount-1];
 while (elementPointer &lt; lastElementPointer) {
    sum = sum + *(elementPointer++);
 }
</pre></p>
<p style="text-align:justify;">Both loops calculate the sum of matrix’s elements. However, the second one uses just sum operations when calculating memory address dislocation, while the first loop uses multiplication, much more expensive (don’t rely on me, go ahead and prove it by yourself). Although slower, the first code is much easier to read and modify. So, which code to use? Remember, write readable code first, measure it and, if necessary, optimize it.</p>
<p style="text-align:justify;"><a href="http://www.cc2e.com/">Code complete</a> also comes with an entire chapter dedicated just to code optimization techniques. Next posts I’ll talk about some of them. Hope you like.</p>
<p>See you,</p>
<p>&#8211;<br />
Fernando</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nandokakimoto.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nandokakimoto.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nandokakimoto.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nandokakimoto.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nandokakimoto.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nandokakimoto.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nandokakimoto.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nandokakimoto.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nandokakimoto.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nandokakimoto.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nandokakimoto.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nandokakimoto.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nandokakimoto.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nandokakimoto.wordpress.com/481/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nandokakimoto.wordpress.com&amp;blog=2881717&amp;post=481&amp;subd=nandokakimoto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nandokakimoto.wordpress.com/2009/08/11/code-performance/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">nandokakimoto</media:title>
		</media:content>
	</item>
	</channel>
</rss>
