top border

Matt's Blog

Matt Durr, Guest Blogger


Go Back
  • Enforce Correct Usage By Wrapping Types

     
    I came across this post by @jsonmez last week via @elegantcode: "Enforce Correct Usage By Wrapping Types".

    Enforce Correct Usage By Wrapping Types: Have you ever written an API or a method and expected it to be used a cer... http://bit.ly/9AHp4aless than a minute ago via twitterfeed

     

    In it, John tackles the problem of ensuring your code is used by other developers as you intended. He gives an example of a method that takes a date parameter that *should* be calculated using certain business logic. How do you prevent another developer from using this method and passing in a hard-coded date?

    Normally, one might write up some documentation or add xml comments to the code describing how the method should be used, what parameters are needed, and so on. Of course, there's no guarantee that those guidelines will be followed, if read at all. A second solution is to write a utility class that calculates the parameter using the correct logic (this is what I see most often). This is still no guarantee since it requires knowledge of the utility class's existence and where to find it.

    The better way, John writes, is to not accept primitive types at all! Instead, wrap the parameter in a data type that creates the needed type with the required business logic. This allows you to force the correct input instead of having to validate anything that might be thrown in. 

    For a simple code example and more ideas on where you might use this, check out his full post on elegantcode.

     

    Full story

    Comments (0)

  • Subscribing to a RSS feed in Outlook

    Chances are you already use a web app like Google Reader or Bloglines to subscribe to RSS feeds, but did you know that you can get the same feeds right in Outlook? While this might not be ideal for power users with hundreds of feeds, it's great for keeping up with one or two blogs. Here's how to set this up:

    1.       Open Outlook, and look on the left side for the RSS Feeds folder
    2.       Right-click on RSS Feeds and select Add a New RSS Feed
    3.       In the box that opens, paste in the blog URL (e.g. http://www.thinketg.com/blogs.rss.ashx)
    4.       Click Add, and in the following box, click Yes
    5.       If all went well, the feed is now added and will automatically populate with recent and future blog posts
    6.       Depending upon the type feed, the articles may be abbreviated. Our company blog is set up this way: simply look for View Article link (or something similar). Clicking that link will take you to the full article on the blog site.


    Full story

    Comments (0)