hellswraith's profileCoding and BeerBlogLists Tools Help

Blog


    June 25

    Guarding Clauses

    I have been reading Jimmy Nilsson's latest book titled "Applying Domain-Driven Design and Patterns With Examples in C# and .NET".  In the refactoring section, he eluded to Guarding Clauses.  He put a name to something that I have been doing in my own development without knowing that others have talked about it as a good practice.
     
    To be fair, he mentioned that it originated from Martin Fowler in his refactoring book.  Either way, it felt good to know that on my own I came up with something that others would consider best practice.
     
    So, just what is a guarding clause?  Well, it is where you guard your code without mixing all the code up in if statements.  That is probably way overly simplistic, but below is a simple example to follow:
     
    Here is a method before being refactored to use guarding clauses.  Notice that the two if statements have nothing to do with what the method is supposed to do, they are just there to ensure the variables are correct before executing the code that needs to run.  In affect, they are guarding the functionality in order for the code to run as expected.
    public void DoSomething()
    {
       if(_someVariable != null)
       {
          if(_someOtherVariable == "")
          {
              _someOtherVariable = _someVariable.ToString();
          }
       }
    }
     
    When you look at that code though, it just looks messy.  You could simplify it to this if you wanted to:
    public void DoSomething()
    {
       if(_someVariable != null && _someOtherVariable == "")
       {
          _someOtherVariable = _someVariable.ToString();
       }
    }
     
    Still, just doesn't seem right that the functionality of the method is in-cased in a if statement.  Using a guard clause, the method now looks like this:
    public void DoSomething()
    {
       if(_someVariable == null || _someOtherVariable != "")
          return;
     
       _someOtherVariable = _someVariable.ToString();
    }
    The benefit to doing it this way is really shown when the method has many more lines of code, but for the example I didn't want to confuse the concept with what the code does.  Further refactorings can make this code even clearer if you wanted to:
    public void DoSomething()
    {
       if(VariablesHaveNotBeenInitialized())
          return;
     
       _someOtherVariable = _someVariable.ToString();
    }
    We just extracted out the conditional logic to a new method to provide better readability to our code.
     
    Our team has been using these concepts on our current projects with great success.  It is nice to glance at a method and realize that if conditions are not met, the code will not execute .  It is easier that trying to execute the code in memory to see what code will run and when.  Readability is key to this refactoring!
     
    Brian Russell
     
     

    TDD, BDD, and DDD oh my!

    I haven't posted in a while, and thought I would catch everyone up with what I am doing.  I have been on a pretty deep exploration of Test Driven Development (TDD), Behavior Driven Development (BDD), and Domain-Driven Design (DDD).  That is a lot of 3 letter acronyms.

    Why all of this at once you may ask?  Well, for me, I feel that a lot of this is all intertwined, and should be explored together.  TDD and BDD are so close that it is just your thought processes when you approach the testing that makes them different (from here on, I will just refer to both as TDD).  DDD goes hand in hand with testing.  Testing your domain model is important in order to effectively refactor when necessary.  Check out this video of Dave Astels giving a talk to Google employees about BDD.

    It’s funny that it took me shifting away from everyday development in order to free my mind enough to look at the bigger picture of software development.  Sure, I could always handle any problem passed on to me because I felt comfortable with my technical skills to do so.  The problem was I never truly ‘designed’ my software well.  That was hard for me to admit for awhile, but I have since seen where I have been and where I want to go.  Most of this thought process came from the fact that I wasn’t ‘in the trenches’ everyday, doing the same thing over and over.

    I got on this track of thinking by reading the writings of some very smart people on the subjects.  I found Jeremy Millers blog which totally enlightened me on TDD.  His blog is hosted on the CodeBetter.Com site which contains many other blogs that provide some great value as well.   Martin Fowler is another author whose work has been a great resource.  I can’t believe it took me so long to read Martin Fowlers work, but once I have, I can’t get enough.  Last up, I have been reading a book called “Applying Domain-Driven Design and Patterns With Examples in C# and .NET” written by Jimmy Nilsson.  I am not even half way through the book, but so far I really like it.

    So, that is where I am at right now.  I am going to finish up the book, do a small project to solidify the concepts, and start integrating the knowledge learned into future projects.  I will post any worth while updates on my progress here as I go on.

     

    Brian Russell

    June 08

    MSDN Wiki

    This is pretty neat.  MSDN has a beta of their documentation with some added Wiki functionality.  What I think is neat is that if you are researching the help, and something isn’t helpful, you can add more information to it. Likewise, you can learn from others.  The documentation stays the same, but below it in the green area, you can add your own content.
     
    Brian Russell
     
    May 26

    Stored Procedure Debate

    I have found this ongoing debate about stored procedures interesting, so I thought I would post the links here so I can come back to them at a later time.
     
    It all started with this funny post.  The last couple of sentences referred to stored procedures:
     
    Next up came a general posting of why stored procedures are good:
     
    Next, a response showing the other side of the argument:
     
    And finally, a response to the response:
     
    There will probably be some more, I will try to keep this updated.
     
    Brian Russell
    May 13

    Blog From Word 2007

    I have often wondered when it would be put into word, but blog posting is going to finally be integrated into Word 2007.  I am excited that they are going to support MSN Spaces since that is what I use, but they also support other blog engines.  They are allowing it to be extended, so if your engine isn't supported out of the box, someone will probably write support for it soon.
     
    Now, if only OneNote had native blog support like this.  OneNote would be a great blog posting tool for me.
     
    Brian Russell
    May 12

    ASP.NET 2.0 Membership and Roles

    So I have been trying to come up to speed on the new ASP.NET 2.0 features.  I am just floored on how easy it has been to set up security on your websites with 2.0.  I have been reading a bunch of information online, but everything keeps coming back to this post by ASP.NET guru Scott Guthry
     
    That might be the only ASP.NET 2.0 membership / role link you ever need since it spiders out to every other article needed.
     
    Brian Russell
    April 30

    TFS Customization

    I am just starting to explore how to customize Team Foundation Server, and I am amazed at how deep this goes.  I should clarify; I am not customizing the product itself, but the process templates and work items that the TFS product provides the framework for.
     
    At first, we just took TFS out of the box and started using the MSF Agile template.  This template can easily be used by a lot of teams to start working because it is so robust.  Since we have used the product since beta 2, we were not so eager to trail off the beaten path and do a lot of customizations.  Now that we upgraded to the release version last week, we are ready to fine tune and expand our process.
     
    Just minor things like adding a new work item type is awesome.  I think I am going to try to put together a good template (or look for one someone else has put together) that more correctly fits our internal development process and methodologies.
     
    Brian Russell

    Change From Resolve to Associate During Check-In is a Pain

    Why is it that every time I go to check in code, TFS defaults the selected task during check-in as 'Resolved'?  I rarely want that.
     
    I am all for making things easier while I develop, but this one should require me to manually change over to resolved.  I should have to think about it.
     
    Brian Russell
    March 27

    Interviewing

    I interviewed for my supervisors position last Friday.  Interviewing really helps you understand your strengths and weaknesses.  You can work in your same job for years with the thought that you are on top of everything, but when you interview, you realize how much you need to work on and how imperfect you really are.
     
    I don’t think I am horrible or anything, just that there are some things I can work on; not only technically, but for personal growth as well.  I feel like I am a self aware person, I look at myself every now and then and try to figure out why I am that way, whether it is good or bad, should I correct something, work on a skill, etc.  The process of writing out your resume and cover letter, going through the interview process, and the re-thinking all your answers to the questions after your interview provides you with some different perspective that could provide some good knowledge for positive growth.
     
    Brian Russell
    March 07

    Internet Explorer 7

    Check out the new IE7 site.
     
    Brian Russell
    February 27

    Site for Whole Project Examples

    After my last post, where I asked for the experts to show us full examples, I stumbled upon this site.  Reading the sites objective, it seems real close to what I was asking for.  Unfortunately, no one has posted any projects at this time.  Maybe I will try my hand in it, but I still don't view myself as the expert that should be doing it.
     
    Brian Russell
     
     
    February 20

    Object Oriented Design - Show Me Please!

    I was reading the I Object article in the latest Code Magazine and really enjoyed the way the J. Ambrose Little explained true object oriented design.
    By “true object-oriented design” I mean object-driven design; that is, basing your software solution domain on the actual problem domain as opposed to, say, data-driven design, which is by far the more common design approach within Microsoft circles. I think this point doesn’t bear much proving in this article, as it is patently obvious by the artifacts existing today in the form of marketing, presentations, tutorials, the majority of Microsoft-related articles, developer tools, and indeed in the many millions of applications existing today that are clearly the result of data-driven (i.e., starting with the data and how it will be stored and reported upon) design.
    I feel the problem is that there are too many developers who don't know what true object oriented design is (including me, I just have a vague fuzzy idea, enough to inject my opinion).  Sure, we hear the great programmers of our time talk about it, but there are so many data driven design programmers out there, it is rare to get an object oriented design programmer around you to learn from.  This leads to more people learning the data driven approach rather than the object driven approach.
     
    To be fair, a great number of applications out there are not hurt by using data driven designs, which is why I feel we continue down this path for the most part.  Because we follow this path, it also leads the data driven designs to be applied to problems that should have object oriented design.
     
    I found a real world example of this in our latest project at work.  We used code generation to generate an object layer that mimicked the database tables.  Consider the generated code to be close to what an OR mapper does; moves data in and out of the database in an ‘object-ish’ fashion.  This is great for the most part, as our application generally needs to perform simple CRUD activities to records in the database.  There are a couple areas in the application though that, looking back, could have really benefited from object oriented design.  These areas are more logic driven than simple CRUD activity.  Lots of business rules needed to be enforced as well as complex workflow which needed to be processed correctly.  Because we set our selves up with a database looking object design, this tended to complicate our coding greatly.  We have so many areas in our code that feel like if you do something wrong, it could topple over and all come down.  The coding is solid now, and works well, but later, when we need to make changes, I know this is a scary area to work in.  I think that if we had went with a object oriented design approach for this area of the application, we could have coded it in less time, and have far more flexible and maintainable code.  Live and learn.
     
    Anyway, here are the problems, in my opinion, that are really stopping object oriented design.
    1. Reporting.
    2. Storage (database, file system, etc).
     
    If we could get the object oriented design leaders to produce high quality tutorials on building a 'real' application from start to finish in a object oriented design fashion and answer the questions us 'simple folk' programmers are wondering about, I think we can get the conversion to start happening.  Learning from past mistakes I make is nice and all, but it would be really helpful if someone was there to guide from the beginning to end.  We need the guides in the community to step up and show, not just continue to talk about theory if we are to try to change over to object oriented design.
    Brian Russell
    February 19

    What Kind Of Programmer Are You?

    I have had feelings throughout my programming life that there was a clear seperation of programmers in terms of ability as well as motivation.  Usually the two follow each other quite nicely.  After reading Mitch Denny's posted entry titled The Day Programmer vs. The Night Programmer, it is clear others have this feeling as well.
     
    In his conclusion he hit the nail on the head from my perspective:
    If you are a day programmer, you look at the night programmer and think that they don't have a life. And you laugh at them when they come in excited about some cool new trick they can do in the framework.
     
    I am a night programmer by the way he describes them.  From my perspective, I just can't believe that others are not into programming as much as I am. 
     
    Brian Russell
    February 09

    Upgraded Team Foundation Server to RC

    I upgraded our Team Foundation Server 2 nights ago from Beta 3 to the Release Candidate.  Following the upgrade guide and using the upgrade apps they provided, everything went just fine.
     
    All our developers are now using the RC version and we haven’t run into any issues yet.  As a matter of fact, we have seen some performance improvements.
     
    We found we had to update our custom queries to use our Display Names instead of our Login Names.  This was a known change though, so we were happy to do this.
     
    Find a bunch of Team System stuff here.
     
    Brian Russell
    January 03

    Consultants are Prostitutes?

    This section of Sahil's post about aging techies made me laugh:
     

    See, tech consultants are very much like prostitutes.

    - Younger are preferred than older, unless you have special needs and preferences.
    - The job is stressful, the hours are weird.
    - We get paid hourly.
    - We all hate, yet need our pimps.
    - If the client is rough, you find another client.
    - Family life is tough.
    - We find it hard to explain what we do for a living at family get togethers.
    - Our quality is judged by our performance in those last few critical excruciating moments.
    - We both get screwed in the end.

     

    I never thought about it that way, but it is spot on if you are operating as a consultant.

    December 27

    Good Programming Habits

    Every programmer should read this:
     
    Brian Russell
     
     
     
    December 24

    Ruby

    During my normal daily Slashdot scan, I found a link to this article:
    Anyway, I thought it was a pretty short and consise intro into the Ruby language and I liked how the article seperated Ruby from the Rails project.  Take a look.
     
    Brian Russell
    December 03

    Team Foundation Server and MS Project

    I have had the opportunity to use MS Project and Team Foundation Server now for a bit to track a project and assign tasks to individuals.  For the most part, this is pretty neat.  I am not a MS Project guru, so I can't speak from that point of view, but as a general user to track my project, it works well.  The great thing is when I assign a task to an individual and publish the project file to TFS, the work item is assigned to that user.  In Visual Studio, they get to see their assigned tasks, check in code and relate it to the task(s), as well as update and close the task when completed.  This loop is closed when the project file is synched up with TFS next time.
     
    Right now I only have 2 issues with the whole thing.
    1. I can't assign multiple people to a single task (work item).  This is a limitation of the default work item template for TFS.  I know I can modify the templates and what not, but out of the box, this won't work.
    2. There is no out of the box mapping to the description field of the work item.  I think this is an obvious oversight, and I am hoping that it is in the final release (it is beta, sometimes I forget).

    Over all it is good.  I am actually going to look into using it with Excel sometime soon, I will report back how good that experience is when I have more to offer.

     

    Brian Russell

    November 22

    Book Review: Code Complete 2nd Edition

    I finally finished up Code Complete Second Edition by Steve McConnell.  Good book.  I learned a few things, but even more important, it made me re-evaluate things I already knew (or thought I knew).  The reason I picked up this book was because others rated it so high.  I can definately agree with all those positive reviews.
     
    I read this book in small pieces.  I would pick it up and read about it for about 10 - 15 minutes at a time.  After putting it down, I thought about what I read for about 15 more minutes while doing other things.  I think that was what I liked most about the book, I was about to sectionalize it into small pieces, but yet still get a lot from it.
     
    I highly recommend the book for every developer.
     
    Brian Russell