<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blog.alecl.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Alec Lazarescu's Blog : Refactoring</title><link>http://blog.alecl.com/archive/tags/Refactoring/default.aspx</link><description>Tags: Refactoring</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.2)</generator><item><title>Assigning Responsibilities</title><link>http://blog.alecl.com/archive/2008/01/14/assigning-responsibilities.aspx</link><pubDate>Mon, 14 Jan 2008 15:04:00 GMT</pubDate><guid isPermaLink="false">022ae8cf-15ca-4180-8062-b150ad1660bf:6</guid><dc:creator>alecl</dc:creator><slash:comments>1</slash:comments><comments>http://blog.alecl.com/comments/6.aspx</comments><wfw:commentRss>http://blog.alecl.com/commentrss.aspx?PostID=6</wfw:commentRss><description>&lt;P&gt;&lt;A class="" href="http://codebetter.com/blogs/jeremy.miller/articles/131726.aspx" target=_blank&gt;It’s All about Assigning Responsibilities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This example really hit home for me.&amp;nbsp; I am faced with a very similar legacy code design where some processing takes place and an e-mail is sent out.&amp;nbsp; My current&amp;nbsp;tests consist of integration tests that outright send me an e-mail that I have to confirm manually.&amp;nbsp; Having these tests was far better than nothing at all, but their design never sat well with me.&amp;nbsp;&amp;nbsp;They&amp;nbsp;were from an earlier attempt at writing tests before I truly understood or had time to delve into IoC, mocks or refactoring for testability.&lt;/P&gt;
&lt;P&gt;Now&amp;nbsp;half a&amp;nbsp;year&amp;nbsp;after having written the tests, I understood that I could use a mock to determine if an e-mail was sent without sending an actual e-mail.&amp;nbsp; But how would that help me determine if the contents of the e-mail were correct.&amp;nbsp; After reading Jeremy's article it became clear that my code design itself was flawed and I need to simply separate the generation of the e-mail text from sending the e-mail.&amp;nbsp; It's such a simple idea and makes so much sense.&lt;/P&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Assigning+Responsibilities" href = "mailto:?body=Thought you might like this: http://blog.alecl.com/archive/2008/01/14/assigning-responsibilities.aspx&amp;subject=Assigning+Responsibilities"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://blog.alecl.com/archive/2008/01/14/assigning-responsibilities.aspx&amp;title=Assigning+Responsibilities" title="Submit Assigning+Responsibilities to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://blog.alecl.com/archive/2008/01/14/assigning-responsibilities.aspx&amp;phase=2" title="Submit Assigning+Responsibilities to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://blog.alecl.com/archive/2008/01/14/assigning-responsibilities.aspx&amp;title=Assigning+Responsibilities" title="Submit Assigning+Responsibilities to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blog.alecl.com/aggbug.aspx?PostID=6" width="1" height="1"&gt;</description><category domain="http://blog.alecl.com/archive/tags/Refactoring/default.aspx">Refactoring</category><category domain="http://blog.alecl.com/archive/tags/Unit+Testing/default.aspx">Unit Testing</category></item><item><title>Promises and Paradigms</title><link>http://blog.alecl.com/archive/2007/02/25/promises-and-paradigms.aspx</link><pubDate>Sun, 25 Feb 2007 22:37:00 GMT</pubDate><guid isPermaLink="false">022ae8cf-15ca-4180-8062-b150ad1660bf:2</guid><dc:creator>alecl</dc:creator><slash:comments>0</slash:comments><comments>http://blog.alecl.com/comments/2.aspx</comments><wfw:commentRss>http://blog.alecl.com/commentrss.aspx?PostID=2</wfw:commentRss><description>&lt;p&gt;I've always tried to make it a point to read a lot about the industry and constantly shifting and improving methods and best practices.&amp;nbsp; Sometimes the buzz dies down after a bit -- I was particularly amused to find people tired of the lofty promises of &lt;a href="http://en.wikipedia.org/wiki/Enterprise_JavaBeans" target="_blank"&gt;EJB&lt;/a&gt; and going back to basics with &lt;a href="http://en.wikipedia.org/wiki/Plain_Old_Java_Object" target="_blank"&gt;POJO&lt;/a&gt;.&amp;nbsp; Other times it grows to a roar.&lt;br&gt;&lt;br&gt;The promises of unit testing and refactoring were being extolled for a while, but I must admit it took some time and much reading for it to sink in.&amp;nbsp; If you're smart enough to make tests to exercise your code cases properly and didn't miss anything, you probably would have handled all those cases properly when you were coding anyway, right?&amp;nbsp; Perhaps, but what about changing that code 6 months from now?&amp;nbsp; What about someone else changing that code?&amp;nbsp; I must admit I find a certain comfortable simplicity in writing unit tests to exercise the boundaries and coverage of a piece of code.&amp;nbsp; After doing a few, it starts to become automatic and not take as much time as you would think.&amp;nbsp; It keeps you honest.&amp;nbsp; Even the best programmers can be burned when making just a quick last minute change that wasn't expected to change another area of code, but invariably does and most people are terrible at methodically manually testing their code countless times.&amp;nbsp; Too many habits of doing things the same way every time leads very often to surprised cries of "But it worked for me.".&amp;nbsp; Unit tests also add a margin of comfort to refactoring.&amp;nbsp; Too often we let bad code persist and create maintenance headaches for years because it's not well suited for automatic or manual testing.&lt;/p&gt;&lt;p&gt;So I'm starting to believe now and writing my unit tests where I can going forward with new code and adding them to existing code when making changes.&amp;nbsp; As time goes on, existing code will be retrofitted for testing and testing code coverage will increase.&amp;nbsp; I'm definitely still learning and experimenting on testing methods and will occasionally post snippets or ideas I'm working on.&lt;br&gt;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Promises+and+Paradigms" href = "mailto:?body=Thought you might like this: http://blog.alecl.com/archive/2007/02/25/promises-and-paradigms.aspx&amp;subject=Promises+and+Paradigms"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://blog.alecl.com/archive/2007/02/25/promises-and-paradigms.aspx&amp;title=Promises+and+Paradigms" title="Submit Promises+and+Paradigms to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://blog.alecl.com/archive/2007/02/25/promises-and-paradigms.aspx&amp;phase=2" title="Submit Promises+and+Paradigms to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://blog.alecl.com/archive/2007/02/25/promises-and-paradigms.aspx&amp;title=Promises+and+Paradigms" title="Submit Promises+and+Paradigms to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blog.alecl.com/aggbug.aspx?PostID=2" width="1" height="1"&gt;</description><category domain="http://blog.alecl.com/archive/tags/Refactoring/default.aspx">Refactoring</category><category domain="http://blog.alecl.com/archive/tags/Unit+Testing/default.aspx">Unit Testing</category></item></channel></rss>