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

Derik Whittaker

Thoughts on Software Development, .Net, OOP, Design Patterns and all things cool

June 2008 - Posts

  • Removing the 'delegate' noise with RhinoMocks 3.5

    As you may be aware Ayende has recently released Rhino 3.5 Release Candidate. Among many of the great improvements to this release, he as simplified the code needed to mock void methods.

    Lets take a look at the older syntax:
    Expect.Call(delegate { mockSession.Login("", ""); }).IgnoreArguments().Repeat.Once();

    Lets now take a look at the new syntax:
    mockSession.Expect( x => x.Login( "", "" ) ).IgnoreArguments().Repeat.Once();

    Both ways will accomplish the same goal, but I know that I always hated having to use a delegate to set expectations on a void method.  To me the new syntax (using Lambda's) is much cleaner and flows off my keyboard much easier.

    +1 for all Ayende's hard work

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • Developer training, a real (non)success story

    About a year ago I created a few posts on the topic of Developer Ramp time and how companies can help the process as well as why different developers ramp up at different speeds.  Developer ramp time and how companies can aid in speeding up this time is critical not only to a new employee's success, but also that of the team they are joining.

    This is why I was so shocked to hear a story from a buddy of mine about his company and their philosophy on developer ramp time. 

    The story goes something like this:

    My buddy (we will call him Will for this post) has recently been put in charge of the maintenance team at his company.  Currently there are a total of 5 people on this team, 4 developers and him.  Because his team is rocking and getting things done the company decided to hire on 2 more developer and put them on his team.  Because Will is one of these guys that believes in doing things the right way and because he sees the value in trying to speed up/aid the ramp time for new developers he decided he would like to put together a plan of action for these new developers.

    So Will spent a little time putting together a high level list of things he thought a new developer would need in order to become a upstanding member of the team.  However, because he did not want to spend too much time on this with out getting buy-in from his boss (should be a walk in the park) he simply put together a outline of what he wanted to do and sent that to his boss.

    Along with sending the outline to his boss, he also provided a summary of his intentions and goals for his training.  Will was looking for his boss to give him the thumbs up on moving forward with this training and figured he would start putting together the materials in the next day or so.

    Will was shocked when he received the reply from his boss that simply stated the following

    'The new developers are both professionals and adults and should be able to learn all they need to on their own.'

    Needless to say that when Will received this reply he was not a happy camper.  How is he meant to help his team succeed if he is not allowed to help them ramp up?

    The moral of the story here is that training new employees is painful, it is hard and it can be expensive.  However, not training them can be even more painful and more expensive because they will be less productive and potentially make more errors.

    Any company that does not see this or does not value this is not a place I would like to work, and keeping me around may be hard. 

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • My first impressions with Rhino Mocks 3.5 (beta)

    I finally got around to downloading and playing with the forthcoming release of Rhino Mocks v3.5 (more info here from Ayende).

    The major changes to this version is that the syntax has been revamped to allow for the new language features in .Net 3.5.  Another big change with this release is that the dreaded Record-Replay semantics have been depreciated (although I have to admit that they never bothered me).

    What I thought I would do today is do a little comparison with Rhino 3.5 against Rhino 3.4 (and older) as well as compare it to Moq as this mocking framework has been getting a lot of buzz lately.

    The example below is a pretty straight forward example where I need to mock out my data repository for a test and I want to ensure that the correct call is actually made.

    Rhino 3.5 Syntax

    var admin = new Admin();
    MockRepository mockRepository = new MockRepository();
    var adminRepository = mockRepository.StrictMock< IAdminRepository >();
    
    adminRepository.Expect( x => x.GetSiteTotals() ).Return( new SiteTotals() );
    
    ObjectFactory.InjectStub( typeof( IAdminRepository ), adminRepository );
    
    var siteTotals = admin.GetSiteTotals();
    
    ... Asserts here....
                
    mockRepository.VerifyAllExpectations();

    Rhino 3.4 and older syntax

    MockRepository mockRepository = new MockRepository();
    var admin = new Admin();
    var adminRepository = mockRepository.CreateMock();
    
    using ( mockRepository.Record() )
    {
        Expect.Call( adminRepository.GetSiteTotals() ).Return( new SiteTotals() );
    }
    
    ObjectFactory.InjectStub( typeof( IAdminRepository ), adminRepository );
    using ( mockRepository.Playback() )
    {
        var siteTotals = admin.GetSiteTotals();
    
        ... Asserts here....
    
        mockRepository.VerifyAll();
    }

    Moq Syntax

    var admin = new Admin();
    var mockAdminRepository = new Mock< IAdminRepository >();
    
    mockAdminRepository.Expect( x => x.GetSiteTotals() ).Returns( new SiteTotals() );
    
    ObjectFactory.InjectStub( typeof ( IAdminRepository ), mockAdminRepository.Object );
    
    var siteTotals = admin.GetSiteTotals();
    
    ... Asserts here....
    
    mockAdminRepository.VerifyAll();

    Rhino 3.5 compared to older versions of Rhino
    Lets take a quick look at the syntax differences between the new version and the old. 

    First thing you will notice with 3.5 is that it removes the need to explicitly perform a record/replay.  I personally never had an issue with this syntax, but it does remove noise from your code and this is a good thing.

    Next you may notice that there is no more need to use the Expect object to set your expectations.  With 3.5 you can simply use the Extension Method Expect and it will do the same thing (love this).

    Lastly take notice to how I am calling mockRepository.VerifyAllExpectations() in place of mockRepository.VerifyAll().  From what I can tell this is just a naming change for clarity sake, but I like it.

    Rhino 3.5 compared to Moq
    Lets take a quick look at the syntax differences between Rhino 3.5 and Moq.

    Like the new version of Rhino you do not need to implement the Record/Replay semantics when creating your tests, and this is good as I said above because it removes noise.

    First you will notice that with Moq u create all your objects via the 'Mock' object were with Rhino you use the MockRepository.  They both do the same thing, however with Moq the object you get back is NOT the actual type you requested, it is a wrapper around your type that is used for testing.  Personally I find Moq's syntax a little annoying and clumsy.

    Next take notice that when you want to get access to the actual type instance of your mock you have to do mockAdminRepository.Object.  This is fine, but is just one more thing I have to remember to do.  I am always forgetting to add the .Object and my test will fail because of it.

    Last, because Rhino still creates all the mocks out of the MockRepository you are able to call mockRepository.VerifyAllExpectations() one time to ensure that all expectations where met.  However, with Moq you need to call mockAdminRepository.VerifyAll() on each mock object (if there is a better way in Moq, please let me know).  To me having to potentially call .VarifyAll() multiple times just adds more noise to my test.

    Now that I have spent a little time playing with Rhino 3.5, I have to say I am hooked.  In fact, I think i am going to gut my tests for DimeCasts.net that were originally written in Moq and replace them with Rhino 3.5.

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • First guest author (Kyle Baley) on DimeCasts.net released today

    I am happy and proud to announce that my good buddy (man, hope he feels the same) Kyle Baley aka The Coding Hillbilly is the first guest author to release an episode on DimeCasts.Net

    The timing this release could not have been better as just yesterday he and Donald Belcham released their first .Net Rocks Episode on Brownfield Applications (btw, the episode is great, both educational and funny). 

    Kyle will be producing a entire DimeCasts series on Brownfield Applications, so be sure to stop by and check them out.

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • The var war is brewing

    When C# 3.0/.Net 3.5 was released one of the new features that was included was the 'var' keyword.  Now I have to admit that when I first read about this new feature I immediately associated this 'var' with the Variant of VB6 or the var of JScript.  But that could not be future from the truth.

    The 'var' keyword was created to allow for anonymous types, these are types that at design time (code time if you will) do not have a concrete type, but at run time they do (compiler creates the concrete type for you).  The var keyword is statically typed, it is not a new version of the Variant.  Take a look at the code below:

    // Valid
    var someVariableName = "Foo"; // this is typed as a string

    // Invalid
    var someVariableName = new SomeObject();
    someVaraiableName = "Foo"; // this is NOT allowed

    Enough of the history lesson, on to the point. 

    The use of the var keyword has had some controversy since it was announced, but as of late this 'var' war has heated up with some recent blog posts.  Most notably there have been 2 posts that kinda sum up the general over all feeling on var.  One for the general use and one against the general use of it.

    In Jeff Atwood's (aka Coding Horror) post he talks about using var to remove redundancy.  However, in Richard Dingwall's posts he thinks that Jeff has it all wrong.  Well, I am here to tell the world that they are both wrong, yet both right (wow, what a way to pick a side Derik)...

    No really, to be honest I was NOT in favor of the var keyword at first, but after giving it some thought and use, I LOVE the var keyword.

    In Jeff's post he likes the var because he thinks it removed redundancy from your code (I 100% agree with this). However, Richard counters that saying that the use of var reduces readability. Well, again they are both right, but Jeff is soo much more right than Richard.

    So, if I think they are both right, then how do I code an use the var?  here are my rules for when the var should be used versus not used.

    1. Var should be used in all cases where the type can be visually inferred from the right side of the statement:

      // Use var
      var foo = "string";
      var anotherFoo = new Object();

      Both above we know the static type by looking at the code
    2. Var should NOT be used when rule 1 is not true:

      // DO NOT USE var
      var person = someObject.GetPerson();

      Above I can assume that the GetPerson returns me a person object, but I am not 100% sure.  In this case I would rather see something like below.

      Person person = someObject.GetPerson();

    Ok, now that I have cleaned up the 'var' war and everyone is happy again, it is time to tackle a larger problem like how to get my wife to allow me to have an iPhone.  Wish me luck.

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • How did I get started in Software Development?

    Looks like I was tagged by Javier Lozano to explain to the world how how I got started writing code.  Hold on tight as this may be a long, bumpy ride.

    How old were you when you started programming?
    Compared to most of the geeks out there, I was a late comer.  I did not code my first application until I was a senior in high school.

    What was your first language?
    QBasic, in fact I am pretty sure I still have the book in a box in the basement.  The first application was some simple little app that would display 'fireworks' on the screen....wow

    What was the first real program you wrote?
    I am pretty sure it was a web-site for a local business in the town where I went to college.  In fact I think it still may be up cause I still get spam email from them.

    If you knew then what you know now, would you have started programming?
    Oh hell yea.  I mean come on, first off I am too lazy to do a real job and lord knows manual labor is not in the cards for me.

    If there is one thing you learned along the way that you would tell new developers, what would it be?
    No, there are a few

    1. Learn to shut up and listen, you just may learn something (still working on this myself)
    2. Do not be afraid to ask questions, the only dumb question is the one you do not ask
    3. Be passionate and have fun, if you can have fun doing this you will be soo much better at it

    What's the most fun you've ever had ... programming?
    Professionally it was when I was working at a .com working with a group of 12 or so developers that were all great.  I was able to learn a ton and grow both as a developer and as a person.

    Non-Professionally it is when every I am creating something for my own enjoyment

    Who am I calling out?

    Kyle Baley

    Michael Neel

    Sergio Pereira

    Joey Beninghonve

    Kirstin Juhl

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • What makes me NOT want to leave a company/client/shop

    Many times while you are doing the whole interview dance the company will ask you why you left a former company or client.  But how often do they ask you what you need/want to not leave your NEXT place?  Sure some times they may ask what makes you happy, or what type of place do you like.  But how often to they ask you point blank, what can WE do, what can WE provided for you not to leave this company (assuming you were to hire on)?

    Over the years of working/consulting for various companies I have learned a thing or two about what I am looking for to not make me leave a company and I thought I would share them.

    Allow my voice to be heard 
    As someone how is relatively opinionated (shocking I know) I like to know that my comments/thoughts/concerns will be heard.  I need an environment where I can feel free to voice both my happiness as well as my displeasure.  If I do not feel that I can be heard, I do not feel like I can make a difference (more on this below).

    Put me in a position to succeed
    Every employee wants to feel like they can succeed.  No-one wants to or likes to fail.  In order for me to be happy I need to feel that the team I am on is put into a position where we can succeed.

    One example of how to do this is by having reasonable expectations on what can be done both both me and the team.  Nothing puts you in a place to fail fast than unreasonable expectations.

    Put me in a position to make a difference
    I want to feel that all the blood, sweat and tears I pour into my work is going to make a difference.  I like to know that something I did had a direct positive affect on someone else's job being better, easier or faster. 

    By allowing me (and others) to make a difference we will work just that much harder and take just that much more pride in our work.  And when this happens, watch out cause the success is about to start flowing like a tidal wave.

    Make effective communication must be priority
    I need a place that believes that open and honest communication is the key to success.  I want to be kept in the loop on all things that directly relate to the project I am on and the department I work in. 

    I want a manager that will let the team know what is going on and is willing to share information that pertains to the team openly and freely.

    Manager that will battle to the death for their team
    I want a manager that will stand up for and fight for their team.  This shows me that they are not afraid to try to do what is right.  If I have a manager that will fight for either me or the team, I will in turn fight for them, and am also more willing to go not only the extra mile, but even the extra 10 miles.

    Team members that challenge me
    I want to work with people that challenge me both as a developer as well as a person.  I love to learn, and I want co-workers that want to be the best because this will in turn challenge me to up my game and force me to learn something new.

    Cool technology
    Do I really need to explain this? 

    FYI, cool technology does not have to be the latest version of XYZ language, it could simply working with something that is new to me or different.  It could also be doing something that I have done before, but in a new way.

    I am sure my list seems like mostly obvious things, but sadly many places lack some if not many of these.

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • ReSharper Live Templates Distilled

    If you are a ReSharper user (I know many of you are) and you are NOT taking advantage of the LiveTemplates feature, you are really not maximizing your productivity.

    Today I thought I would do a quick demo on how to create and use a LiveTemplate.  Sit back, relax and learn how to make yourself more productive.  For some info on LiveTemplates from JetBrains check this out.

    Steps to creating your LiveTemplate

    1. Determine code that you create all the time
      For me I am always typing out Assert.That( XYZ, Is.EqualTo( ABC ) ) in my tests, so lets turn this into a LiveTemplate
    2. Launch the LiveTemplate Explorer 
      Reshaper -> LiveTemplates

      LiveTemplateExplorer
    3. Determine where you want to place your new template
      I would suggested you put it under the "User Templates" section, but your call.
    4. Select where you want to put your template and click the new button
      This should open up a new editor window, this is where the fun begins.
      1. Provide a Shortcut.  This is what you will type to produce the code in the LiveTemplate.  I would suggest you come up with a standard naming scheme to make life easier, but again your call.
      2. Provide a Description
      3. Copy and Paste in your code you want to use.
      4. Determine if you want any variables (dynamic content) in your template.  If you do, create the variables by putting $ around the name (ie $Value$). 
      5. Determine if you want your variable to use a macro.  If so, choose one fro the list on the right.

        TemplateCreator
    5. Time to use your new LiveTemplate
      Go back to your coding window and type in the shortcut you gave your template (ie ateq) and watch as code is generated.

    There you go, 5 simple steps to creating and using a LiveTemplate.  You should not be much more productive and be able to code circles around your fellow developers.

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • Using C# 3.0 (.Net 3.5) syntax in a .Net 2.0 application

    Did you know that if you are using Visual Studio 2008 but targeting the .Net 2.0 framework you can still use some of the new syntax features of .Net 3.5 in your applications?  That's right, you read that correctly you too can be a cool kid while still working on your old dilapidated, buggy legacy application (ok, maybe using the new syntax will not make you a cool kid... I tried).

    Anyway, turns out you can use the new syntax features just as long as you do not reference the new .Net 3.5 assemblies.

    The new assemblies are:
    System.Data.Linq
    System.Xml.Linq
    System.Core

    New Syntax/Features you can use is:
    Var keyword
    Lambda statements
    Extension Methods (kinda, sort, you need to read this for more information)
    Object Initializers
    Anonymous Types  (Moved from the cannot use section, thanks Jon)

    New Syntax/Features you cannot use is:
    Linq (any variant of Linq)
    Query Extensions
    Extension Methods (see the link above for more information)

    Now you may be asking, how can you use the new .Net 3.5 stuff when targeting the .Net 2.0 framework?  Well, simple all the allowed new stuff is really nothing more than compiler tricks.  The 'Var' keyword really is just replaced at compile time with the strongly typed equivalent.  Lambda's are really nothing more then a fancy new facade on anonymous delegates.  And Object Initializers are just ways to reduce the number of lines you right.

    So, if you are like me and stuck in a .Net 2.0 project but would like to use some of the new features and you are using VS 2008, have at it.  Just make double sure that you are 1) targeting the .net 2.0 framework 2) you do no reference any of the new assemblies that are part of .Net 3.5.

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • ReSharper 4.0 Keyboard Shortcut Cheatsheet

    Every R# developer should print this off and hang it on their cube wall.

    Keyboard Short Cuts

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • ReSharper 4.0 is finally released

    Looks like the much anticipated public (non-beta) release of ReSharper (R#) 4.0 is finally out.  I know many of you have been using the beta of 4.0 for quite some time (myself included) and we all know it has been a little rough.

    However, I am glad to see that it finally has been released, and looks like I know what I will be downloading today.

    Get your copy here

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • Generate your own RSS feed with Argotic

    Adding an RSS (Really Simple Syndication) feed to your website has never been easier.  When trying to find a way to add an RSS feed to Dimecasts.net I first thought of just hand rolling my own RSS document, but that seemed like too much work.  After a bit of searching and asking on Twitter I was pointed to the open source .Net library called Argotic

    In this post we will review the following steps needed to add a feed to your site.

    1. Creating the xml (rss feed) document for publication
    2. Creating an access point for the feed
    3. Adding the feed to your site
    4. Publishing your feed via Feedburner

    Creating the xml (rss feed) document for publicationReferences
    Setting up a feed with Argotic could not be easier, you basically just need to import the correct libraries.   After you have imported the correct libraries simply add a using statement for using Argotic.Syndication.  Finally you start coding. Below is the code I used (modified for this post) to create my feed.

    public XDocument GenerateRSSFeed()
    {
        var rssRepository = ObjectFactory.GetInstance();
        var items = rssRepository.GenerateRSSItems();
    
        var rssFeed = new RssFeed( "Main RSS Feed for DimeCasts.Net" );
        var rssChannel = new RssChannel( new Uri( "http://www.dimecasts.net" ), "Title", "Desc" );
    
        foreach ( var item in items )
        {
            var rssItem = new RssItem
                              {
                                  Author = "Your name here",
                                  Title = item.Title,
                                  Link = new Uri( item.Link),
                                  Guid = new RssGuid(item.Link),
                                  Description = item.Description,
                                  PublicationDate = item.PublishDate
                              };
            rssChannel.AddItem( rssItem );
        }
    
        rssFeed.Channel = rssChannel;
    
    
        return XDocument.Parse( rssFeed.CreateNavigator().OuterXml.ToString() );
       
    }

    Creating an access point for the feed
    In order to allow people to know about your feed, you need to create an access point.  This could be something as simple as creating a static .xml document and placing it on your website.  However, you will more than likely want to make the document dynamic based on the content of your site. I found the simplest way to create the access point is to create a .aspx page and change the content type from html to "text/xml". 

    // get the XML data/document
    var feeds = new Feeds();
    
    // Need to modify the Response type
    Response.Clear();
    Response.ContentType = "text/xml";
    
    StreamWriter streamWriter = new StreamWriter( Response.OutputStream, Encoding.UTF8 );
    
    // Make the call here to get the feed an write it out to the stream
    streamWriter.Write( feeds.GenerateRSSFeed() );
    streamWriter.Flush();
    
    Response.End();
    // Put this code here in your html part of the page.  This will cache the output for a given number
    // of seconds
    <%@ OutputCache Duration="600" VaryByParam="none" %>

    Adding the feed to your site
    In order to let the world know you have a feed, you need to expose it in your html documents.  For me, I wanted every page on the site to expose this so I added it to my mast page.  The code below shows how to add the pointer in your html page.   RSSIcon

    After you have added the reference to your html page you should see the RSS feed icon on your URL bar in your browser.  The image to the right is of the DimeCasts site when being viewed in firefox

    link title="[Your title here]" href="http://www.yourdomain.com/[rssfilehere]" type="application/rss+xml" rel="alternate" 

    Publishing your feed via Feedburner
    Now that you have gone through the pain of setting up your feed, I would suggest you syndicate your feed and use a tracking service like Feedburner.com.  One nice feature of feedburner is it allows you to track who is subscribing to your feed.

    Well, I hope this helps someone.

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • [ANN] Reminder about Chicago Alt.Net meeting July 9th

    Just wanted to send out another reminder about the upcoming Chicago Alt.Net meeting on July 9th.  Last week Serigo made the same announcement here.

    Hope to see everyone out there.

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • Code Annotations are a slick feature from SlickEdit Tools

    One of the pretty slick (pun intended) features that comes with the SlickEdit Toobox is the ability to create Code Annotations.  Think of Code Annotations as the 'ToDo' on Steroids. 

    There are multiple things I like about Code Annotations over ToDo and they are:

    • Code Highlighting of annotated code
      Unlike todo's, Code Annotation will actually highlight the method/property/code that is marked with the annotation for you to clearly see.  You can also open the view pane in the IDE and jump right to the annotation in your code.
      HighlightedCode

    • Ability to assign the annotation to a developer
      Because I can create an annotation for other developers, I have the ability to markup the project without actually affecting the code base.  This to me is huge.

      AddAnnotation

    • Ability to assign a 'due' date
      One neat feature is the ability to assign a 'due date' to the annotation, this way we can create tasks/reminders for us in our code.

    • Ability to assign the annotation to a given project
      When you create an annotation you have the ability to create mark the annotation for either your own person use (non-project specific) or for a given project, which then allows the annotation to be shared among other team members.

    • Ability to check the annotations into VCS for other members.
      Because the data for the annotations is stored in a text file (*.sca) they can be checked into your VCS (Version Control System).  This allows you to share these files and allows everyone to add annotations.

    Till next time,

    [----- Remember to check out DimeCasts.Net -----]

  • Linq'n in the Real Word Session at the Rockford IL UG

    About a week or so back I had the chance to head back out to the Rockford IL .Net user group and do a session about using Linq in the real world.  Chris and his group are great, they are a smaller (12-15) group that allows the session to become very informal and tons of great questions were asked.

    The intent of this session was to show how to use Linq (Linq2Sql, Linq2Object and XLinq) in your applications.  We started off by looking at Linq2Sql and how it can be used in your Data Driven applications.  We talked about the pros/cons of Linq2Sql as well as some the gotcha's that I have experienced.  We then moved over to see how Linq2Objects can be used in all the layers of your applications and how using Linq2Objects can reduce the number of lines you need to write.  Finally we ended taking a look at XLinq and seeing how that compared to old school Xml Manipulation.

    What was really fun was the fact that that PPT slides where not even followed.  I did refer back to them from time to time, but most of the session was purely in code. 

    Rockford guys, I had a great time, and would love to come back out whenever you need me.  If anyone is in the Rockford area, check out their UG, they are a great bunch, please you get some free pizza.

    Till next time,

More Posts Next page »

Our Sponsors

Red-Gate!