CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jean-Paul S. Boodhoo

Develop With Passion

May 2007 - Posts

  • ReSharper 3.0 Beta - Get it while its hot

    I’ve been using ReSharper 3.0 EAP for quite some time now, and I’m loving it. The beta just released (yesterday I think), so what are you waiting for:

    • Solution Wide Error Analysis
    • C# Code Analysis
    • Unit Test Explorer
    • XAML Support
    • More…

    Download it right now and start developing with pleasure!!

    Posted May 31 2007, 08:23 AM by bitwisejp with no comments
    Filed under:
  • One Step Closer To Mouseless Computing

    Being that I have been experiencing a bit of discomfort when I type as of late. I thought I would take drastic measures to prevent RSI from becoming an issue. After reading Carl’s post about the DataHand I decided to spend some time online researching the product. After pouring through testimonials, user guides and PDF’s I decided to call the sales department.

    I asked to speak to someone who actually used the datahand. It just so happened that the person I was talking to had been using the product since 1998. I grilled her about  the mechanics and how friendly it is towards programmers. She even took the time to describe to me how I could perform my refactorings in ReSharper. She also mentioned that she has not used a mouse since adopting the product.

    Well that was it. A way to decrease the stress of typing on my arms and wrists while also achieving mouseless computing (physical mouse that is); I was sold.

    My DataHand should ship by the 15th of June. At which point I am sure that I am going to be going through a massive un-learning/re-learning of how to type with this, what looks to be, phenomenal device.

    Posted May 25 2007, 12:24 PM by bitwisejp with 6 comment(s)
    Filed under:
  • Amendment to DNRTV Episode Part 3

    After I finished up recording part 3. I realized that I was not showing off as many ReSharper shortcuts as I could have. That will definitely change over the course of the next set of episodes. For the remainder of the series I will be recording the entire series “sans mouse”. Hopefully this will give people an idea of how productive you can actually be without using the keyboard mouse. As soon as I had finished recording the session I thought to myself “yikes, I made that list enumerable way more complicated that it should have been”. Instead of this:

     

    public class ListEnumerable<T> : IEnumerable<T> { private IList<T> itemsToEnumerate; public ListEnumerable(IList<T> itemsToEnumerate) { this.itemsToEnumerate = itemsToEnumerate; } public IEnumerator<T> GetEnumerator() { return new ListEnumerator<T>(itemsToEnumerate); } IEnumerator IEnumerable.GetEnumerator() { return new ListEnumerator<T>(itemsToEnumerate); } }

    I could have simply done this:

    public class ListEnumerable<T> : IEnumerable<T> { private IList<T> itemsToEnumerate; public ListEnumerable(IList<T> itemsToEnumerate) { this.itemsToEnumerate = itemsToEnumerate; } public IEnumerator<T> GetEnumerator() { return itemsToEnumerate.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return itemsToEnumerate.GetEnumerator(); } }

    And of course, an even easier way (if you have .Net 2.0) is to just leverage the yield keyword inside of a method returning IEnumerable. Which is how I started off the discussion on iterators.

  • Becoming Extreme - From the inside out

    This is a hot topic for me right now, as I talk with lots of people who are working through trying to make their teams more “Agile”. That word is a little overloaded and overused lately, so I am going to focus on how you can make your team more Extreme through use of practices and strategies that live in the world of the development team.

    I am going to point everyone to James Carrs great post today about A Tale of Two Teams. It is a great post that helps me start of by making a big bold statement (reiterating what James said).

    • Stop blaming other people for your inability to introduce practices and strategies that will make your team more effective.

    As a consultant, I get the great joy of being “that guy”. The one who comes in to shake things up and challenge peoples assumptions about the way they build software and the software development process in general. Having a deep love for the practices associated with Extreme programming, I have crafted a set of strategies that I feel have helped infect every team/developer I have interacted with on the benefits of this “new” style of development. I want to share these strategies in the hope that they will inspire other developers who are in positions of influence (that is all of us) to encourage their development team to strive for something better.

    Develop With Passion

    This title is not a joke. My companies tagline is “Develop With Passion”. This is a crucial, but often overlooked element of introducing a team to a set of new practices. Whether people share the same values or not, people respect people who stand up with conviction for their beliefs. If you love what you do, other people will notice and (most) will want to share that passion you have for your work. If I come in completely fired up about the benefits of agile, yet am lukewarm in my delivery, the message will get lost.

    Invest In Building Solid Team Relationships

    Before you can hope to reach people at a technical level, and try to encourage them to improve their development practices, they have to know you are authentic. This is especially important for consultants, who are often viewed as the ninja paratroopers of the software development world. We swoop in, do a bunch of “magic”, then we leave!! This view has to be dispelled as quickly as possible. If a team that I engage does not believe that I truly care about them on a personal and professional level, they are not going to be able to listen to ideas that I bring to the table. My first couple of weeks on a new contract are spent building a level of trust between myself and the other developers that I am going to be working with. What does this investment look like:

    • Lunches/Coffee breaks getting to know developers outside of the workspace
    • Pair Programming Sessions where I can get an idea for each individuals skill level, providing me information I can use to focus future mentoring sessions
    • Encouraging open communication within the workspace, which helps identify each developers comfort levels, boundaries etc.

    Focus On Small Victories

    After that first couple of weeks of building relationships, I should have a great idea of how much work needs to be done to get the developers thinking and practicing in a more agile fashion. For the majority of teams out in the wild, the practices that are second nature to most agile developers are almost completely alien. There is a limit to how much an individual can assimilate at one time. This means that if I come in and throw TDD,BDD, DDD, Interface Based Programming, Automated Builds, Continuous Integration etc.. at them all at once, it will be too much information. Based on the level of the team I have to focus on individuals and practices in a piecemeal fashion. Think of running it like you own mini agile project, with the end result being having your development team completely immersed in an agile environment. My set of small wins is usually introduced incrementally using the following steps:

    1. Introduce the concept of an automated deployment script. If nothing else, to decrease the amount of manual time that is probably being spent on deploying applications that are going out to production. Some good tools for this are NAnt, MSBuild, or (my fave for deployments) FinalBuilder. The amount of individual time saved on decreasing the amount of human intervention required for deployment will allow your development team to focus on other tasks to ramp themselves up.
    2. Start leveraging an automated build script to compile your application. This will inevitably lead to some codebase structure refactoring that will make it more malleable to an automated build script.
    3. Introduce the concepts and practices of automated unit testing using an framework such as MBUnit.
    4. Bring a continuous integration server into the mix. My current fave for this is CruiseControl .Net.
    5. With the foundations in place, switch into a mode of pair programming with the client developers.

    Once in a place where I can pair with developers that is where I choose to introduce the following concepts:

    1. The benefits of trying to achieve mouseless computing
    2. Real Object Oriented Programming
    3. Interface based programming
    4. Test Driven Development
    5. Domain Driven Design
    6. Object Relational mapping and all the other great tools that exist out there to facilitate rapid,testable development.

    As you can imagine. It takes a bit of time to have this knowledge flow and be completely understood by each developer on a team. When it happens, amazing things start happening. Other teams start to notice, management starts to notice. Teams will be coming to your team asking you the secret to your success. And then the cycle starts again.

    This is a way that teams, independent of management can start to achieve some gains associated with becoming more agile. I might be a little bit cavalier about my approach to team engagement/improvement, but I have always tried to follow this simple principle:

    • It is easier to ask for forgiveness than permission.

    More people need to start taking chances. Every single developer on a team , regardless of years of experience or title, is in a position to initiate change. Do you see room for improvement, introduce it. Be the catalyst for change that inspires other people. Don’t hide behind excuses that shield the fact that, more often than not, the problem lies with developers who are content to whine and do nothing, vs doing something and “maybe” receiving some heat.

    Wanna be more extreme? Do what it takes to make it happen. It’s that simple.

  • TDD is like paying using cash!!

    I just had an awesome comment made on my unit testing post by Tom Opgenorth. It was so good that I though it deserves a post in its own right!! Here it is:

    In trying to explain the "why" of TDD, I like the example of paying cash vs borrowing money.

    Using TDD is paying cash.  You shell out the time (money) now, and all is good.  Your account is clear.

    Without TDD it is like borrowing money to buy something.  You get what you want but there will come a time when you have to settle your debt, usually with interest.  

    From a code perspective, this interest is usurious:  wasted time spent digging through a debugger, hoping that a breakpoint was set a the right place in code so you can see the error happen.

    Awesome!! Thanks Tom.

    Posted May 23 2007, 10:53 AM by bitwisejp with 8 comment(s)
    Filed under:
  • And here's a number you can take to the bank!!

    In reference to the article on unit testing, here is an interesting excerpt from the following article written by one of my former colleagues Paul Julius:

    “ The reason I was there was simple. Earlier that year, those same IT managers had performed a series of calculations to estimate how much it cost the department each time a bug made its way out of development, into SIT, into User Acceptance Testing, or all the way into production. For this IT shop, one bug into SIT cost them $12,605 (and you can imagine how much a bug into production would cost.) So, I did some quick math. The burn rate for the developer who introduced the bug was $70 per hour. Since the developer had already fixed the bug and committed the change, I deducted the $70 from the total and ended up with $12,535. Now, it cost them $70 (or less) to fix that one bug, instead of $12,605.”

    So I’ll ask you again. Would you rather spend $12000 to fix a bug or $70?

    Posted May 23 2007, 10:39 AM by bitwisejp with 2 comment(s)
    Filed under:
  • How can I convince my management/other developers of the value of unit testing?

    The amount of times I am asked this question is fairly astounding. It seems that lots of people are struggling with getting their management (at this level I will talk about the Project Management level) to believe in the value of automated unit testing.

    I am not even talking about Test/Behavior Driven Development, I am talking about simple state based unit testing. There seems to be a great misconception floating around out there that the act of unit testing is going to negatively impact individual/team velocity. Let me ask all of the developers out there another question. How can I convince a developer that refactoring is a good practice? This seems like a ridiculous question, but it actually points to the same principle. The reason that most developers will laugh at the statement about refactoring is that most good developers naturally learn to evolve their basic refactoring skills even with the absence of fancy design patterns etc. Going through a series of steps such as:

    • This method is too long… I’ll break it up
    • This class is too big…. I’ll separate responsibilities
    • This behavior does not belong on this object…. I’ll move it
    • This functionality does not belong in this layer of the application…. I’ll move it

    That is a dramatic simplification of refactoring. Nonetheless, a good developer who has not been exposed to a refactoring catalog will inherently develop a habit of “natural” refactoring, for nothing less than to keep the quality of the code at a certain level.

    One more question. When you are sitting there making estimates on how long a particular unit of work will take, do you estimate in time for how long it will take you to refactor code that you are writing? Ridiculous, if we are talking about a developer who has developed a natural habit of refactoring, it is just that “A Natural Habit”. This developer no longer needs to think about factoring in time for refactoring, because it has been factored into their very core as a development practice.

    In my opinion, unit testing is the exact same problem. Not enough developers have developed a natural habit of unit testing their codebases. Content to jump into debuggers at the first sign of an issue, most developers spend an order of magnitude time greater manual fixing and verifying their codebases, when they could bit the bullet, write some automated tests, and have a computer do as much grunt work for them as possible.

    Here is a question I would like to throw at developers (and management alike). Where do you want to spend the time? Would you prefer to spend the time flying through delivering untested features that are potentially going to come back with bug items that need to be manually debugged and fixed piecemeal. Or, write unit tests around as much code as you can, so that in the event a bug comes in you can:

    • Write a failing unit test that captures the bug
    • Update the code to make the failing unit test pass
    • Keep the test in place to serve as a way to prevent the bug from reintroducing itself

    Developers and managers alike are kidding themselves if they think that they are going to save themselves time by not having some form of automated testing in place. A very simple way to convince people of the value of unit testing is to record actual metrics that document the amount of time it takes to fix a bug in a system that has a suite of automated unit tests in place vs. a system that has no automated unit tests in place. Once you can convert that figure to a dollar amount in developer time wasted on bug fixing; it becomes very apparent to developers and management that there is an actual real cost saving that can be realized.

    Above and beyond convincing management is the fact that, at a developer level, it is time for more developers to form some new natural habits in their development process. I am a personal fan of test driven development because while you are simultaneously flushing out the design for your system, you are left with a safety net of tests.

    If you are not practicing TDD, you need to get yourself into a habit of at least unit testing critical objects/behaviors in your system. For projects that are well underway/deployed and have no unit tests in place, it is unrealistic to revisit them and retrofit the entire codebase with unit tests. A better strategy for these projects is to identify pain points in the application (areas with the highest level of bug activity/ areas with the most volatility) and get some unit tests around these “points of high visibility”. Going forward you can encourage developers to get unit tests around new methods/classes etc, and start to integrate some new habits into your developers.

    Posted May 23 2007, 09:39 AM by bitwisejp with 4 comment(s)
    Filed under:
  • DNRTv Series - Demystifying Design Patterns (Source code and information)

    I have just concluded part 3 of a dnrTV series trying to demonstrate the usage of common design patterns in the context of building a simple employee contact book application.

    So far I have been able to cover the following design patterns:

    • Singleton
    • Monostate
    • Strategy
    • Factory
    • Gateway
    • Iterator

    I plan to conclude the series by talking about the following remaining design patterns:

    • Command
    • Proxy
    • Decorator
    • Specification

    I thought now would be a good time to release the source so far so that people can follow along with the examples/refactorings going forward from this point on.

    You can download the source code from here. You can also watch the first 2 episodes at these links:

    The example is being kept simple enough so that people can hopefully grok the application of the design patterns. For any people who are already watching the series, your feedback is greatly appreciated.

  • DevTeach, what a fantastic event!!

    I’ve been to a lot of conferences. Last week I got the opportunity to both speak and attend DevTeach 2007, in Montreal. I spoke on both refactoring and applying patterns of enterprise application architecture.

    Along with presenting, I got to attend and watch awesome content presented by other speakers in the Agile track of the conference. I have to applaud JR and Scott for implementing the addition of an agile track to the conference. Every single one of the sessions was packed, an indication that the topics that were presented are obviously relevant and meaningful to lots of the people attending.

    As cool as some of the presentations were, it was the networking that made this event absolutely stellar. Getting to hang out with Roy, Oren, Jeremy, Scott, Udi, Wendy, Oksana, RodDonald, Dave, Adam, Greg, Matthew and a whole host of others!! The conversation, arguments, debates, and just mindless chatter was the most fun I have had at a conference, ever!!

    There was one evening in particular where the general concensus was that we had all been hit by a bus and were lounging in what must have been programmer heaven (complete with Carl Franklin and company in the background providing the ambient music)!!

    Seeing as how the links to the presentation material are not currently working here is the rar file (download WinRar to extract) that contains the material for both of the presentations. I did not get a chance to finish getting through either presentation in both of the sessions, so the code you see is where I left off. I am hoping to screencast both presentations in their entirety so that people can see the end goal for both sessions.

    Looking forward to DevTeach Vancouver…that right, its coming!!

     

     

  • ThoughtWorks Studios Is Busy!!

    Looks like TW Studios just released a new offering to the general consumer public.

    CruiseContol Enterprise is an interesting offering from TW that looks to add interesting support and consulting features as well as some interesting additions to the actual tool itself.

    I could duplicate information and screenshots, but you are better off just taking a look at it!!

    Posted May 17 2007, 09:46 AM by bitwisejp with no comments
    Filed under:
  • The Bible's Take On Separation Of Responsibility

    Got a great email this morning from Brian Di Croce that I thought I would share with everyone.

    In Exodus 18 we read how Moses overextended himself in caring for the people.  His father-in-law, Jethro, asked him why he sat alone from morning until night with the people standing around him.  He responded  that the people came to him to inquire of the Lord and that he judged between them that they might know God's laws and statues.

    Here comes the principle of separation of responsibilities...

    Jethro told him that he (Moses) would wear himself out, as well as the people he was trying to help.  He told him that the responsibility was too heavy , and warned him that he could not continue to bear it alone.  Then he proceeded to give his son-in-law some wise advice.  He explained how to delegate responsibility.

    For any of you interested; here is the actual story taken directly from Exodus 18: 23–23 (NIV version):

    The next day Moses took his seat to server as judge for the people, and they stood around him from morning till evening. When his father-in-law saw all that Moses was doing for the people, he said, “What is this you are doing for the people? Why do you alone sit as judge, while all these people stand around you from morning till evening?”

    Moses answered him, “Because the people come to me to seek God’s will. Whenever they have a dispute, it is brought to me, and I decide between the parties and inform them of God’s decrees and laws.”

    Moses father-in-law replied, “What you are doing is not good. You and these people who come to you will only wear yourselves out. The work is too heavy for you; you cannot handle it alone. Listen now to me and I will give you some advice, and may God be with you. You must be the people’s representative before God and bring their disputes to him. Teach them the decrees and laws, and show them the way to live and the duties they are to perform. But select capable men from all the people– men who fear God, trustworthy men who hate dishonest gain – and appoint them as officials over thousands, hundreds, fifties and tens. Have them serve as judges for the people at all times, but have them bring every difficult case to you; the simple cases they can decide themselves. That will make your load lighter, because the will share it with you. If you do this and God so commands, you will be able to stand the strain, and all these people will go home satisfied.”

     

    Interesting thought to start the week out with!!

     

    God Bless.

  • It's comments like this that just make your day!!

    I have been having a bit of a hectic week. In the midst of the insanity, I just opened up a message in my inbox that was received from a student of a course I just taught in Regina.

    As a mentor, there is no greater feeling that when you feel you have truly impacted another person with the knowledge you have shared. Here is what he had to say in the closing comments of the course feedback form:

    Nothin But Dot Net was the best rock concert ever. No fancy light shows, dancing girls, pyro or over paid aging rockers. Just gigs of Dot Net agiled in soothing keys of ReSharper.

    Too many encores to count! Nothin But Dot Net played longer. And then longer. And then even longer. Guitars were smashed, fans passed out, speakers blew up, the police came and the band even bought the audience pizza.

    After sixty hours with only a few spared for sleep, the cover songs started. It was like we were hearing for the very first time what the original artists were trying to say. At times the crowd sang along, other times we stood in humbled awe through blistering solos and soaring ballads. Then the guitar was handed out to each of us and we got to jam with the IAxeMan himself.

    Nothin But Dot Net left me fully refactored, wanting more and armed with a clear vision of what to do next. My only disappointment is that I didn't get into this music sooner.

    Wade, thanks so much for taking the time to craft a very touching (to me anyway!!) comment about how this course impacted you.

    God Bless.

    Posted May 09 2007, 08:30 PM by bitwisejp with no comments
    Filed under:
  • Raising events (from a mock) using Rhino Mocks

    I was just asked a question that I thought I would share with everyone in the event that it actually might help anyone else out.

    The question was in regards to how (in a unit test) I can have a mock object raise an event when using Rhino Mocks. The particular case in question is to verify that a presenter actually consumes and handles an event published and broadcasted by a view.

    Let’s write a test to first encapsulate the requirement that a presenter should subscribe to a particular event of the view interface in the presenters constructor. I have a ReSharper file template that sets me up a MockTestFixture with the following structure: 

    using MbUnit.Framework; using Rhino.Mocks; namespace NothinButDotNetStore.Test.Presentation { [TestFixture] public class EmployeeBrowserPresenterTest { private MockRepository mockery; [SetUp] public void Setup() { mockery = new MockRepository(); } [TearDown] public void TearDown() { mockery.VerifyAll(); } } }

    I am making use of MbUnit and Rhino Mocks. MbUnit for unit testing and Rhino Mocks as my mock object framework. You’ll notice that I create a MockRepository in the SetUp method and I call VerifyAll in the teardown method. This ensures that I never forget to make the call to VerifyAll as I never need to explicitly call it in any of my test methods.

    Let’s get to that first test:

    [Test] public void Construction_ShouldSubscribeToEventsOnView() { IEmployeeBrowserView mockView = mockery.CreateMock<IEmployeeBrowserView>(); mockView.Initialize += null; LastCall.Constraints(Is.NotNull()); mockery.ReplayAll(); new EmployeeBrowserPresenter(mockView); }

    The 2 most important lines in this test are the following: 

    mockView.Initialize += null; LastCall.Constraints(Is.NotNull());

    These two lines make up the requirement that:

    • At some point in running this test, the object under test better subscribe to the Initialize event on the view with a Non-Null event handler.

    Here is the initial code for the EmployeeBrowserPresenter: 

    public class EmployeeBrowserPresenter : IEmployeeBrowserPresenter { private IEmployeeBrowserView view; public EmployeeBrowserPresenter(IEmployeeBrowserView view) { } }

    The view interface looks as follows: 

    public interface IEmployeeBrowserView { event EventHandler Initialize; }

    If I were to run this test right now it would fail, because there is nowhere in the constructor of the presenter that it is subscribing to the events exposed by the view. To get the test running and passing I’ll have to add the following code:

     

    public class EmployeeBrowserPresenter : IEmployeeBrowserPresenter { private IEmployeeBrowserView view; public EmployeeBrowserPresenter(IEmployeeBrowserView view) { this.view = view; HookupEventHandlersTo(view); } private void HookupEventHandlersTo(IEmployeeBrowserView view) { view.Initialize += delegate { }; } }

    You can see that in the constructor, the presenter now subscribes to the Initialize method with a non null event handler (in this case an empty anonymous method). This gets my test passing. Now I need to write a separate test to verify that the presenter actually does something when the event is raised. Because I will be creating the presenter for each test, each test would need to setup the expecation for the event subscription. I don’t want to duplicate my efforts so I will move some code to the setup method. This will cause my test class to look as follows:

     

    [TestFixture] public class EmployeeBrowserPresenterTest { private MockRepository mockery; private IEmployeeBrowserView mockView; [SetUp] public void Setup() { mockery = new MockRepository(); mockView = mockery.CreateMock<IEmployeeBrowserView>(); mockView.Initialize += null; LastCall.Constraints(Is.NotNull()); } [TearDown] public void TearDown() { mockery.VerifyAll(); } [Test] public void Construction_ShouldSubscribeToEventsOnView() { mockery.ReplayAll(); new EmployeeBrowserPresenter(this.mockView); } }

    Now I can write the test to ensure that the presenter does something when the view raises its Initialized event. For arguments sake, let’s have the presenter Invoke a method on the view in response to handling the Initialize event:

    [Test] public void ViewInitializationHandler_PresenterShouldPushMessageToView() { mockView.DisplayMessage(null); LastCall.Constraints(Is.NotNull()); mockery.ReplayAll(); IEmployeeBrowserPresenter presenter = new EmployeeBrowserPresenter(mockView); IEventRaiser eventRaiser = new EventRaiser((IMockedObject) mockView, "Initialize"); eventRaiser.Raise(null,null); }

    Notice how I am leveraging the EventRaiser class to simulate the mock object raising an event. Unfortunately, using this approach defeats the purpose for using Rhino over NMock2 in the sense that you have to resort to providing the name of the event as a string. No good. Let’s refactor this to eliminate the need for the string. I’ll make a change to the Setup method as follows:

    private IEventRaiser initializeEventRaiser; [SetUp] public void Setup() { mockery = new MockRepository(); mockView = mockery.CreateMock<IEmployeeBrowserView>(); mockView.Initialize += null; LastCall.Constraints(Is.NotNull()); initializeEventRaiser = LastCall.GetEventRaiser(); }

    Using LastCall.GetEventRaiser provides me a way to get access to an event raiser bound to a particular event on a mock object. The caveat is that you have to ensure that the previous mock object expectation (in this call mockView.Initialize += null) was an expectation on an event exposed by the interface. With this IEventRaiser in hand I can refactor my test as follows:

     

    [Test] public void ViewInitializationHandler_PresenterShouldPushMessageToView() { mockView.DisplayMessage(null); LastCall.Constraints(Is.NotNull()); mockery.ReplayAll(); IEmployeeBrowserPresenter presenter = new EmployeeBrowserPresenter(mockView); initializeEventRaiser.Raise(null,null); }

    The Raise method expects a set of parameters that match up with the signature for the delegate type of the event. In this case the Initialize event on the view interface is an EventHandler delegate type. The EventHandler delegate is the basic event handler signature in the framework that takes a sender and an EventArgs. In this scenario, because my presenter does not care about either, I pass null for both. To get this test to pass I can write the following code on my presenter:

     

    private void HookupEventHandlersTo(IEmployeeBrowserView view) { view.Initialize += delegate { view.DisplayMessage(DateTime.Now.ToString());}; }

    In the anonymous event handler, I have the presenter invoke the DisplayMessage method on the view, passing it the current time as a string. This satisfies the new requirement in the test:

    mockView.DisplayMessage(null); LastCall.Constraints(Is.NotNull());

    Now you know how to raise events in a refactorable way using Rhino Mocks.

     

    Develop with passion!!

  • Nothin But .Net - The destination is the journey

    The title of this post may sound like the catchphrase from a really cheesy movie, but I think it sums up quite nicely the plan that I had in my mind for where I wanted this course offering to go. In a development world where we seem to be caught up in learning tools vs solid practices, Nothin But .Net is about getting back to basics, building a solid core, and having the foundation with which to be able to evaluate and leverage new technologies, toolset, practices very quickly. Helping devs to chart the course for the rest of their dev career, and not feel so overwhelmed at the rate of change that is currently prevalent in the industry.

    Let me state clearly that I am first and foremost a developer, honing my craft daily by working on projects using pragmatic agile practices that I have morphed to work best to my development style. I don’t post a public schedule for this class, and have been blessed to have received a lot of interest over the last couple of months that has allowed us (my family and I) to travel once a week each month for the last several months to deliver this targeted training session. My plan is to do 3 weeks of regular consulting, and 1 week of the course, for the next couple of months.

    It would better be described as a week of heads down, crazy mentoring. I show up with no powerpoint, the skeleton of a web UI done (which serves as our stories generator) with no code behind. Over the course of the week, I teach people how to apply domain driven design, behaviour driven development, solid OO principles and design patterns to incrementally build up the functionality of the web application.

    The reason the class is called Nothin But .Net, is that I feel the need to help people understand at a fundamentally core level, the patterns and practices underpinning a lot of the frameworks that they may choose to utilize in the future. By giving them the knowledge to use these frameworks will intelligence, they are much better prepared to know how to fix/work around the frameworks when they do not work for them. More importantly, they get to see how tdd plays out over the course of the week to build the application under question. They also get to see how building an app in a loosely coupled way allows easy transition if they decide to suddenly move the mapping layer to something like NHibernate, or the dependency container to something like Castle.

    Having delivered this course 3 times this year so far, each iteration of the course has been a wildly different experience. And the code that comes out of each iteration is remarkably different from the prior iteration. I have to say that I think I have as much fun , if not more, than the people that attend. The days can be pretty long though, this last iteration consisted of 1 10 hour day followed by 4 14 hour days!!

    I had promised my attendees that I would be posting to my website, the comments (good or bad) that I have received from each iteration of the course. I am currently working on revamping my web site to include all of the feedback from each iteration of the course. In the meantime, I thought I would post some of the (good) comments that I have received from attendees so far:

    Edmonton,AB - February 2007

    • I really got a lot out of the course.  The course was one of a kind and I would definitely recommend it to anyone who wishes to take his/her architectural/development skills to the next level.  The course was a paradigm shift for me and it exposed all of the bad programming habits that I had picked up over the last few years.  The paradigm shift for me was mainly that I was thinking that I was doing previously was object oriented programming but realized that I was actually only doing precedural programming.  I am definitely leaving with a sence that attending this course was definitely the best thing I have done for my career and I will look back and remember this as a turning point for me.  Thanks JP !!

    • Prerequisites for this course should include experience with .Net 2.0 along with familiarity with Unit testing.  I think some familiarity with design patterns would also benefit the student.

      I realize that I this course was a little beyond my current skill level and so don’t think that I could say anything that would be constructive to help better plan this course in the future.  But I definitely think there is benefit in seeing tdd in action and think that you should keep some element of this in the course (seeing how elegant solutions were composed and how they evolved definitely helped with the comprehension of the material).

    • I enjoyed the course and would recommend it to anyone who has already started down the path of agile development.  This course is not for beginners or the faint of heart.

    • This is most certainly a training course for experienced .NET developers who are looking to expand their skills and knowledge in design and development techniques.  Although intense and draining, the concepts are presented in a fashion that allows for the students to progressively apply the teachings as the course moves forward.

      If you are expecting to hone your basic software development skills, this is not the course for you.  If you’re looking to extend and enhance your current skillset, you will be in for a mental treat.

    • You can tell JP has a lot of real world developing experience, he is constantly referencing it and that is important for less experienced people to understand that this stuff will help you when you get back to your job.  Some teachers loose their touch with real world situations if they spend all their time in a classroom, it is nice to hear real examples.

    • I thought the course was quite good. The course filled in quickly a lot of the things I had heard about but never got a chance to use or did not want to go through the grief of learning them without mentoring. It was great to learn so much from someone in the field that works with this stuff everyday. It was also great that we never used anything pre-canned so that we got to be involved with a ground up build and see how easy things were when doing an application from a TDD perspective.  

      I found that the pace of the course fluctuated too much. The first two days were quite fast paced and a bit overwhelming. The last three days seemed to drag out a bit and it felt like not many new concepts were being introduced. This was due the disparate level of developers in the class though.

      I felt that the course has really put me ahead of the curve.  The course has shown me the tools, methodologies, and practices that I can use right away to make my applications better, more testable, and less complex.

    • The course was a fantastic experience, and a great opportunity to get some in depth exposure to a well thought out and understood development process. The instructor was more than happy to share his knowledge, however, sometimes that was a bit of a drawback just because of how how much he had to share.

      I would definitely recommend this course to anyone who is comfortable working in C# 2.0, and doesn't need Visual Studio to walk them through every step (I wasn't quite there when I started, but am a lot better now).

    • This is the BEST course that I have been on. JP was an excellent instructor, learned a lot in the five days. Design patterns, domain driven design, application layering, etc… Covered it all! If there was another opportunity for me to take this course I would definitely do it again.

    • This is the first computer course in which I’ve learned from a knowledgeable instructor. Showing how to use abstract patterns for solving real problems is refreshing compared to books and articles I’ve read that deal with only the concept or give examples that do not use patterns and is applicable to more than just the DotNet framework. I liked the varied manner in which the class was taught through overview of design principles, talking out problems, personal coding, and review of some potential alternatives and consequences of those alternatives. While one afternoon was painful due to so many concepts being introduced that I was personally not familiar with, I still feel I improved a great deal in at least gaining a basic understanding of those concepts and how they could be applied.

    • Personally I received alot of value from this course.  I have a much better understanding of what I know and more importantly what I don't know.  I've learnt numerous techniques that will help me in my daily job as a software developer.  I expect to be much more proficient and efficient.  I also am really excited about taking what I have learnt and using it to learn more stuff on my own.  I've put in place a plan with my wife to allow me personal time to expand my personal skill level. 

       

      The one negative thing I would point out is that you have a tendency to talk without providing space for people to get a word in.  In fact at one point you asked us all to answer a question but never gave us a chance to answer it. 

    • This course was good because I have been trying to do proper design and testing on a new project at work. I also think that having seen some of your presentations I was able to pick up on the concepts easier because I had tried them on apps at home and at work.

      I liked being able to try the exercises/labs after learning the theory and having to think on my feet. After trying the lab it was very valuable to see ways that code could be further refactored using small steps if it was warranted.

      I think having read some of the book refactoring to patterns I was able to understand concepts like chaining constructors, introducing factories to create objects and decorating new functionality on top of existing objects without modifying them.

    Richmond, VA – March 2007

    • I think I probably said everything I had to say under some area or another.  Perhaps on a personal note, JP had to go through a lot of logistical difficulties to make this course happen, and I think a lot of trainers in his position would have either pushed the training further out or just called it quits and given a refund.  He showed a lot of heart even getting the training off the ground, took personal ownership of whatever difficulties there were, and was clearly committed to the students and making the class successful for everyone.

       

      I was an IT trainer for four years, and to be honest with you, I think the fact that JP is not a “professional trainer” contributed a lot to the overall success of the training in general.

    • What an awesome week of hardcore OO, Patterns and .NET madness.  Every MS, data-centric developer should take this course to truly understand better ways of building software. From some of the things I learned this week (technical and non-technical), I see attending this class as the biggest turning point in my career as a software developer/consultant since I got test-infected a few years ago.

    • Perhaps some exercises on some of the “review” topics or OOAD/DP examples to work through before the class to get folks ready for what is to come.  Would also be a way to gauge skill level before someone signs up/shows up.

      Overall this was a GREAT experience for me.  I learned so much and also have a path on where to expand that knowledge.   I am taking pieces of what I’ve learned and trying to implement them on current projects as well as trying to put into place some of the process and principles.

      Had a great time.  Learned tons.  Money well spent (by my employer lol).  Looking forward to future courses and/or presentations.

    • I really learned a lot. I don’t think I have even begun to digest everything I learned. It was even difficult to begin to talk about it when some of my developer friends asked. I am really glad I will have the recording so I can go back and rewind again and again. My learning style is very tasked based (I find out what I need to solve the problem at hand) and I often remember where to look up information more than trying to remember the information itself, so I think having the screen casts of the class will be extremely valuable to me. I already mentioned the concept of a more communal boot camp idea. I think also a more 2-4 hour/week traditional class structure might work well also. On the concept of getting off track, I really liked the idea in day one that we would be working with an online shopping cart. I thought this would allow us to walk through all the layers and see almost a complete cycle, however we were really racing on the last day to get the list of items on the screen.

      It will take a few months I think until I completely “grok” everything so I can sit down with a blank solution and make my next killer app. ;-)

      You mentioned this whole concept of training trainers as part of a long term vision and I would be interested in learning more about that. As a lone developer in my company its hard to keep on top of things and get important outside experience and ideas . A part time training/teaching project might really help me keep my sword sharp!

    •  This course exceeded my expectations in every way. It's given me a good understanding of how I need to improve my skillset so I can become significantly more productive in a reasonable timeframe. JP is totally outrageous and one of the best developers that I've had an opportunity to learn from.

    Regina, SK – March 2007

    • JP – you are a phenomenal teacher.  It was awesome to be in a class where things were actually taught, and not in a class that consisted of PowerPoint slides and a droning voice putting everyone to sleep.

    • This was an outstanding course.  Not the traditional classroom style of instruction, but far more effective in my opinion.  I learned so much from watching how JP attacks a problem and works through to the solution using TDD.  One of the most important things I personally gained out of the course was the reminder of how truly important it is to have a solid understanding of OO Analysis and Design techniques before jumping into any of the multitude of frameworks that are out in the market today.

      Although this course was outside of my comfort zone, I believe this is one of the reasons that I learned as much as I did.  Thanks JP – great course!

     

    Comments are still coming in from the Regina course (it just finished last week). As soon as my site work is finished; I am going to be posting the comments in their entirety (good and bad) so that anyone who may be interested in contacting me to deliver the course in their area (yes I do travel to run the course) can have a better idea of what to expect.

     

     

     

     

     

     

  • Nothin But .Net - One Developers Scratchpad

    Just got back last Friday from another week of “Nothin But .Net”. This proved to be the most intense iteration of the course yet. One of the developers who attended provided me with his “scratchpad” of personal take aways from the course. It is a raw account, but I appreciated him taking the time to share it with me. I am posting it here as a means to give people an idea of what sort of topics are actually covered over the course of the week. It is interesting to see/hear what different ideas he took directly from the course, and others that he formulated over the course of the week:

    Day 5

    Unit Of Work
    -

    Aggregate Roots
    - good for boundaries, protects the leaf items from rest of domain, that is its responsibility
    - some add persistence coordination to aggregate roots, not JP's prefered strategy

    Tests document code, should read like a book
    - refactoring tests too much can hurt readability, show reader

    UI Strategies for security etc
    - Realize what the higher level of abstraction.
    - Make some ui pieces role aware
    - Ask how can I test this without running the app

    Threading
    - don't use method implementations [MethodImpl(MethodImplOptions.Syncronized)], not good, see clr via c# for more
    - proxies around your classes is better for threading 
    - delegates

    Top down or bottom up
    - higher level components should be driving contracts/interfaces for lower level
    components, advantageous to flush out a better design
    - so go ui to db
    - still, other approaches work too, go from db up to ui, domain layer and out etc.
    - with traditional state based TDD, it is easier to start at the bottom layer and then work up

    Interfaces that Differ only by the types their methods call
    - good candidate for generics

    Marker Interfaces/ Layer Supertype
    - no member definitions
    - can encompass the plumbing for persistence

    public interface ICartItemMapper : IDomainItemMapper...
    - good trick for readability, ICartItemMapper doesn't have any methods defined

    AA analogy for how much we all still have to learn
    - first step is admiting you have a prob
    - then you are on your way to getting better :)

    Test Setup/Teardowns
    - tempting to create setup bases, favour composition over inheritance, decorate with attributes to get the same effect

    Inheritance
    - favour comp over inheritance
    - avoid starting out using inheritance as the first approach, prefer refactoring towards inheritance & only if it really makes sense

    TableDefinitions class for all db types and column names
    - as it get's bigger, it could be changed to a namespace quite easily
    - shoppingCart.RequiredFields could be one strategy

    Insert vs Saves
    - Generic Saves that insert/update are a dangerous path to go down, wrong place to put this responsibility

    Constructors & Exceptions
    - generally bad
    - better to push responsibility for throwing to a factory

    Event Aggregators
    - useful for pushing stuff up to aggregator from separate controls to then re-notify other controls on page


    Console2
    - tabbed cmd prompt for xp

    Day 4

    Real World Issues
    - work within you're circle of control
    - TDD is part of being a professional software developer, its how to design code and specify contracts, not worthy of debate with other devs/mgt so avoid it
    - life and careers are too short, do your due diligence before taking on projects and contracts
    - don't insult other dev's by saying you'll code to lesser standards to ease complexity etc. not doing anyone favours, help them by pairing and getting them up to speed on better approaches than what they are used to
    - ultimate agile goal is to deliver value quickly, never lose sight of that, esp when considering design approaches
    - don't let mgr's and other devs label you, provide lots of details and be enthusiastic to describe specifically what you are doing, don't just tell them you're doing it the TDD way etc, this doesn't help anyone
    - can't change your job...

    Pairing
    - takes humility, can be painful to ego but very worthwhile in terms of speed, intensity and learning potential

    Ping Ponging
    - SR dev writes test, junior writes implementation

    Learning strategies
    - don't waste time at work, ditch the email, msn etc, deliver number one priority,
    use spare time to ramp and add even more value to employer
    - set aside dedicated time
    - jp's book list,
    - follow the order of the books in the lists
    - MIT & Waterloo are producing grads that already know this stuff, follow them and invest time going through the MIT Open CourseWare
    - study group
    - ask lot's o questions
    - get fast on the keyboard
    - reading books is great and necessary but coding is better
    - avoid re-using your older solutions, instead evolve and try
    to get better, besides IP can't be ported to new contracts

     

    Refactoring
    - ESSENTIAL
    - can't be done without tests backing it up

    Table definitions
    - system.codedom  to iterate and build a class per table etc...

    Simplest thing that makes sense is very relative to dev skill/experience

    Web Stuff
    - firebug for js
    - watin/water

    Exception Handling
    - if you can handle it, do so, never just try catch for the sake of it
    - tdd helps define better and drive out where they should be handled

    Mapper tests
    - should be integration tests, if they reference columns etc, they do need to hit the db and fail if columns etc change

    Good Way to learn a true OO project is to look at the tests
    - collaborations are tough to figure out just by browsing classes and interfaces.
    - goood tests show collabs and interactions

    How to be a good developer
    - lots o info here,
    - discipline, focus, time and hard work, nothing untennable

    Day 3

    NOD32 - nice virus protection


    Duplicating Code in TestMethods
    - not necessarily a bad thing
    - too much refactoring to common methods can lead
    to readability issues which should trump the need for removing duplication

    State vs Dependency
    - black vs white box testing
    - dependency based with mocks starts to define the contract with other mocked
    objects but it doesn't dictate the external dependent object's behaviour

    Teams
    - Break up responsibilities by layer
    - have them work on it independently of each other
    and come together to determine the interface needed


    JP's Dev approach
    - JP will work on UI first on most projects, get it signed off

    MVP - Passive view
    - presenter is an observer of UI
    - by having it as an observer, it eliminates the coupling between the presenter and UI

    Ajax
    Prototype
    Script.aculo.us

    Service Layer
    - really a facade
    - course grained

    DTO's
    - dumb ojbects serialization
    - little lightweight objects to pass back and forth
    - ProductBrowserDisplayDTO - very specific to the UI
    - UI, Service, Presentation know about DTO's
    - good candidates for code gen
    - no tests needed in this layer

    Mocking and Order
    -surround with using(mocker.Ordered)
    {
     - expectations inside here must be met in this order
    }


    Integration Testing
    - stuff that hits files/db etc
    - more end to end through silos
    - mapping from db should be tested here too because database changes could happen and not
    be caught with dependency based testing
    - random get people up and type call outs are quite effective at making people pay attention

    Why TDD Fails
    - get's frustrating that you realize quickly how much you need to learn/re-learn, exposes weak OOA&D skills


    Day 2
    Check.Condition(numberOne>0) - design by contract
    - pre and post conditions
    - used to reveal intention
    - fail fast as oposed to fail later

    Readable code trumps a lot of other design choices
    - comments are a smell

    Test Coverage
    - 80% a decent goal

    Method Naming
    - LivingIn(Country country) better than LivingInCountry(Country country)

    Domain should drive out all yer code, except maybe logging
     - Utility should be only project that most other projects references
     - logging ok too
     - lots of utilities are a smell that you didn't assign resposibilities properly & poor design

    Refactor to patterns, don't start with them...

    User Stories
    - ID stories, identify tasks for each story, estimate on tasks
    - Pre Iteration Meeting
     - iteration mgr and biz analysts have time to take docs and extract key stories to focus on for an iteration
     - they try to break down into tasks

    - Iteration Meeting
     - Stories with tasks
     - Team identifies tasks that are too big that might be candidates for stories
     - Estimate tasks
     - Dev's sign up for tasks
     - 8 hour workday translates to about 5 hours a day of real work
     - Don't factor pairing etc into plan
     - any task over five hours deserves a separate story
     
    - Each day
     - update prj mgr's where you're at
     - get done early, go help other devs finish their work
     
    - Availability of SME's is key to success on agile and really any other projects

    Typically you only test external public methods
    - could have internal public methods in an assembly, these could be tested by using assemblyinfo attribute: InternalVisibleTo="testassemblyname"
    - or a post compile for prod could lock them down...

    Tracing & Logging
    - instrumentation - tracing, affects performance
    - aspect type logging, pre/post method execution, aspects on classes, goes further than decorators or proxies, waste of time to write this into your code
    - logging get's into the methods internals
    - good as a debugging tool
    - avoid the slow debugger!
    - expand on tests in logging factory
    - so that we don't depend on


    Domain Classes Candidates
     - an exercise to identify classes.

    Primary Keys
    - insist on surrogate keys, keys that are meaningless


    BDD/TDD
    - primarily a difference in naming, bdd is tdd done right

    NSpec - bdd for .net

    Dependency based testing
           
      // we want to test that Log was called on some class
      // returned by Current
      [Test]
            public void Log_ShouldLogMessage()
            {
                Logger.Current.Log(this, "message");
            }
     
     
             [Test]
            public void Current_ShouldLeverageFactoryToCreateLoggingComponent()
            {
                // How To write a dependency test:
       // start from the bottom (#5) up!
                // 1. Create mocks and fake results
                // 2. Setup expectations for methods to be called on your mocks
                // 3. Prepare mocks object to expect real calls form the object under test
                // 4. Invoke the method under test
                // 5. Make assertions if necessary
            }

    First Implemenation once test runs:
    - The simplest thing that makes sense, returning a hard coded 1 etc doesn't add much value
    - don't waste your time running something you absolutely know will fail

    UAMTC for SVN
    update add merge test commit

    Day 1

    - wpf nice, good support for design pats
    - MBUnit - leaner meaner more dev than nunit
    - createing a shortcut to create a new blank sln in the explorer new dialogue, see "Solution in New dialogue.zip"
    - visualsvn good ide svn add-in
    - myuninstaller - keyboard driven, ctrl U to uninstall selected program
    - keyboard link firefox for mouseless browsing
    - snippet compiler

    Test naming convention
    $TestedMethod$_Should$Name_Conditions$
     - roy osherove
     -
    http://weblogs.asp.net/rosherove/archive/2005/04/03/TestNamingStandards.aspx

    JP the IAxeMan 
    - interfaces for everything except DAO's, ValueObjects
    - code classes inside test exactly as how you would use it in real app
    - how do you want it to behave, how would you want to use it
    - simplest thing possible
    - get the red compiler errors before red test fail errors
    - doesn't use I for Interface, consumer shouldn't know they are talking to abstractions...
    - remove refactor so resharper is only R option in alt clicking - right click on tool bar, customize, re-arrange...
    - try to minimize number of assertions to one per test
    - mbunit RowTest with Row and params in sig for nTest scenarios
    - check out mbunit.org, rollbacks, decorators
     - drill Assert.*
     
    - assertions - heavyweight guard clauses, using exceptions instead of debug.assert makes it a biz rule rather than just a debug helper

    - TestFixtureSetUp/TearDown - only runs once per test class vs setup and teardown which run once per test method
    - SetUp is a good candidate for doing things as you don't want to maintain state between tests, don't want to have some tests affecting behaviour of other tests

    Automate anything that needs to be clicked more than once
    - VS for building is too slow
    - prefer logging to debugging, a good presentation layer test suite, 
    - TDD minimizes the sheer horror of click driven development

    Partial Classes
    - good for tool gen code
    - null objects -- see missing person example, an object creates a null object to return in casses where null is needed to be usable by client, Person frees person class from being cluttered up.

    Delegate
    - type safe function pointer, reference to an event

    Constructor Overloading
    - the one that takes the most params should do the work, don't have all your constructors doing stuff when they are overloaded
    - when you get an object back you should just be able to call stuff on it without any client initialization needed

    Decorator
    - have to be same type as class they are decorating, implement interface, inherit from base

    Events
    Creating
            // step 1 - create an EventArgs derivative (if necessary) it inherits from Event Args
            // step 2 - create the delegate sig for the event handlers
            // step 3 - Create the calss that will raise the event (subject)
            // step 4 - Raise the event to notify the subscribers
    - you need to test to see that you're object under test does what it is supposed to do to the mocks, you're not testing the mocks though!
    - be careful when raising events


    StateBaseTestDrivenDevelopment
    - setup state and assert

    DataDynamics good for reporting


    Lose the Mouse...
    - alt d - get's you to the address bar in explorer
    - alt s c - constant
    - alt F W = new folder
    - backspace = up folder
    - alt F D = new project
     - alt N - edit project name
     - alt P - project Type
    - alt P R - add reference
    - alt R N - add new file type from template
    - alt W L - close all open text editor tabs
    - f2 - rename
    - ctrl shift enter - fullscreen text editor
    - ctrl e - recent files
    - f12 - next error
    - alt enter - available fixes
    - alt ins - gen code
    - alt ins, i,  ctrl a, space, enter - gen code, select all, select, to gen interface implementations
    - never checks off "remove redundant qualifiers"
    - ctrl shift alt f - reformat without dialogue
    - .. Enter - in file dialogue, goes up a dir
    ctrl shift v - clibboard ring
    ctrl shift uparrow - moves method up
    ctrl shift downarrow - moves method down
    pull members up - ctrl shift r b - brings a member up to the base to define it
    alt-delete - will delete it safely and make sure that no one is using it(no other references)
    f6, alt f - move a type to another file
    alt f12 - next error in soln.
    ctrl n - find by type, case sensitive to get the right one
    ctrl alt n - inline variable
    alt s r - add a reference when inside a web project

     

     

     

More Posts