Friday, November 6, 2009

Reviewing This Year's Goals (2009)

Back in January, I created this post focusing around what I was hoping to accomplish this year.  I was going through my old posts and stumbled across it.  I figured it would be a good time to look over them once again to gauge my progress along with what else I may have done so far this year.

 

Learn F#:

While I do not claim to be an authority of F# by any means, I do feel comfortable in saying that I learned the bulk of the language and be able to determine where it makes sense to use it.  If time allows, I can see myself using it more and more; however, for right now, I've definitely learned a lot from such and can focus on learning other things.

 

Learn DDD:

This one I am really only about 1/2 done with.  While I have went through the information and can understand the concepts involved, I haven't had a good way of applying such yet.  There's existing applications that could benefit from the practices of DDD; but I haven't pushed myself into applying such on a new project yet.

 

Learn Silverlight 2:

I got sidetracked and ended up procrastinated on this one.  While I wanted to learn SL2, I still was a bit apathetic towards it since SL1 wasn't very impressive to me.  Thankfully, I've seen a lot of what Silverlight 3 can do and am going all out on learning more about it.  Except some posts on Silverlight 3 soon.

 

Other Things:

So what else have I been up to so far this year?  Looking back I have worked on some open source projects (namely my SchemaSpy Task for NAnt and contributing to .Net Migrations over on codeplex).  I've also focused a lot of time on keeping up to date on .Net 3.5 and other technologies that I wasn't able to fully take advantage of at a previous employer.  Lastly, I've really been focusing on TDD and just writing better code in general.  There's always room for improvements but being able to learn from what's being talked about over the past year is what's important.

 

Things on the Horizon...

Learning MEF:

The Microsoft Extensibility Framework (MEF) provides some great opportunities to make very extensible applications.  With a need to make a project extensible, I'm definitely going to be focusing on understanding MEF more.

 

Learning Silverlight 3:

I'm already in the process of working in Silverlight 3 but I have only started to write applications with such.  Just like a person who has finished their first true ASP.Net application, there's always room for improvements and things that one can learn to make things better.  I'm at that stage where there's a lot more I can learn about and I'm all for it since Silverlight 3 is awesome.

 

More SchemaSpy:

My SchemaSpy post earlier this year is one of my highest trafficked posts as well as one that I refer back to all of the time.  I'm planning on answering a few outstanding questions associated with that post and also see what else I can do with the tool to make things easier for everyone.

 

<Unknown> Things:

I always leave myself open to the unknown and unforeseen opportunities.  While November and December are usually swamped for me, I never know when inspiration will hit me and I learn something new.

Friday, October 30, 2009

Reviewing UppercuT - A Build Framework Based On NAnt

Earlier this week I went to the Kansas City .Net User Group meeting where the topic of discussion was UppercuT, a build management framework created by Rob Reynolds. The discussion was pretty good and Rob did a good job at showing a number of demonstrations on how to use the various aspects of UppercuT. All in all, I feel like the presentation got the point across as to the typical why/when/how/etc. questions.


What Is UppercuT?


UppercuT is a build management framework based on NAnt. It was created in order to establish a consistent way to build .Net applications with a minimum amount of configuration while providing areas for extensibility. In addition to just compiling, UppercuT provides a number of options to manage application versioning, automated testing, and code packaging. While it can be extended to include such steps through NAnt, UppercuT doesn't deploy code...it only stages it since every company/project's deployment strategies may be different. One nice thing that UppercuT does do in terms of deployments though is provide you instructions on how to wire it up to CruiseControl.net.


When Should UppercuT Be Used?


UppercuT provides a way for people who have not started to take advantage of automated builds to do so quickly. Because of this, it's best suited for projects that don't have automated build systems integrated into them yet. With some configuration changes, it is possible to integrate with your current scripts; however, changes would need to be made on both side to the point where it would honestly be easier to convert your current scripts to custom steps for UppercuT to take advantage on. If you currently use some build framework like MSBuild or NAnt, I would probably recommend at least checking out UppercuT to see if it's a good fit; however, if you or your company already have some system that works for you in place, it may be better to just keep with what you have.


Where Can I Download and Learn More?


You can find more information on Uppercut by going to it's project website at http://ProjectUppercuT.org. In addition, you can check out Rob's blog over at http://ferventcoder.com/ as well as on Twitter by following @ferventcoder and @ProjectUppercuT.


kick it on DotNetKicks.comShout it

Sunday, October 25, 2009

Is Learning though a UI worth it?

Do you remember the last time you learned a new, back-end technology like Linq-to-Sql, Entity Framework, NHibernate, the Twitter API, or some other 3rd party API? How did you first go about learning it?  If you used some tutorial of some sort (be it a blog, video, or some other medium), how did you try it out?  Did they have create a basic web page to present the data from the API that you were consuming? If you DID create any form or UI to consume this API, here's two questions for you...

 

  1. How long did it take you to create that UI compared to writing the code that uses the API?

  2. Did you learn more about the API from the UI or from writing the code that actually interacted with the API?

 

Now, let me restate that I'm aiming these questions specifically at back-end technologies.  Any technology that deals with any aspect of a UI (i.e. JavaScript, Silverlight, etc.) obviously depends on the UI and really does not apply. However, if you're NOT focused on a UI-dependent technology, why do you create a UI to learn something that doesn't require it?

Don't get me wrong.  I was guilty of this as well and what I found is that I got sick and tired and bored spending so much time creating a UI and it would take me longer to get to the subject of my studies.  Throw in a dash of OCD or ADHD because I couldn't just make a simple UI but needed some form of basic layout and color contrasts at the very least and it was a recipe of boredom.  It wasn't really until something clicked that I began to really realize that I learned more from the tests or the debugger while stepping through the code consuming these APIs than how the information was presented.  Sure it felt good when I could apply what I learned to a UI but applying the UI layer did not directly provide any value for me towards learning the API.

But again, if it takes so much time and provides a greater opportunity for distractions, is it worth it to learn a back end process by means of applying such to a UI?



kick it on DotNetKicks.comShout it

Wednesday, September 2, 2009

My Barriers to Learning TDD

As a follow up to my previous post declaring that I finally "get" TDD to some extent, I figured I'd reflect on the barriers that I have had up to this point which made it difficult for me to learn how to unit test in some effective manner as well as truly understanding the benefits of TDD practices.  Now, I am by no means claiming to be an expert in unit testing, mocking, or TDD.  I didn't open the refrigerator, drink some of the TDD-flavored Kool-Aid, and threw on a subsequent Mortarboard to illustrate that I've somehow graduated into this new, higher level of software development.  I'm still learning from others as well as my own errors experiences just like everyone else.  The purpose of this is to reveal to others some of the issues that I had and hopefully provide some insight on how to overcome such.

 

The Examples Are Too Simple

This barrier was by far the most difficult for me to overcome.  I would read up on all of the buzz about how to add unit tests to your code and how to apply unit testing into TDD.  I would follow the examples and understand it and be fine; however, I would always stall out whenever I tried to do it in a real world scenario. One day, I got extremely frustrated trying to fit all of this this together even if it looked like a square peg for a round hole to me at that time.  I began to wonder how unit testing in general would work on such complex real world objects and that's when it hit me.  Around this same time, I was diving into the S.O.L.I.D. principles of Object Oriented Design and began to count the dependencies I had in the code.  The more I broke out the code into less complex objects that followed the principles, the easier it was for me to map the unit test examples that previously were "too simple" to my code.  The barrier wasn't so much that the examples were too simple as it was that my code that I was trying to directly apply the lesson to were too complex.  On the last project I had, I didn't apply unit testing to it; however, I tried to adhere to the S.O.L.I.D. principles as much as possible.  When I was trying to retrofit the tests into it, I was able to do it as well as find places where I didn't follow the S.O.L.I.D. principles as much as I thought I did.  Looking back, I probably wouldn't have had any of the refactoring issues I had after the fact if I had used TDD to provide a test-first basis for the object designs.

 

But...This Class Uses the Database

This was another barrier for me that partially stems from the previous example.  Looking over the majority of Unit Testing and TDD books and blog posts out there, very few of them actually touch dependencies as common as a database.  Looking at my own code at the time, I had repository classes that handled all of the CRUD operations to the database as well as spit out the records as strongly typed collections (where necessary).  How do I test this class when there is such a deep dependency with the database?  I was truly perplexed by this issue and decided to ask the question on StackOverflow.  The responses led me to realize that my class was doing 2 things; calling the database AND transforming the returned data in to a manner I needed.  By pushing the direct database calls to a separate class, I was able to mock away the database and make sure these particular class could be tested.

Now, that only solved half of the issue.  I abstracted the dependency of those classes but I still had data provider classes that still interacted with the database.  This is where I truly learned the difference between Unit Testing and Integration Testing.  With such an outside dependency as a database or a web service, I began to see some examples that created separate, controlled instances of those dependencies in order to test the queries and CRUD functions.  The technique I use now for database integration is to use NHibernate, even if the primary project doesn't use it.  NHibernate has the ability to recreate table schemas for each tests which helps automate the state of the database for each test.  An example of this can be shown over at NHForge.org's How-To section under Your First NHibernate Based Application.  After setting this up, it provides me an easy way to test the barrier of the database.

 

Am I Just Testing the Mocking Framework?

I had a class the called into a 3rd party library that I wanted to test.  I abstracted the 3rd party library into a proxy and called such from my class.  The 3rd party library sent messages over a TCP socket connection and returned back an "OK" or an "ERR" message.  The class that I wanted to test created and sent the messages and then reported on what it got back.  For example, I would call a method in the class and it would send a message "FOO" to the proxy and get back "OK".  That's a little simplified (see barrier #1 above) but the class itself did pretty much that.  When I setup the test, I mocked out the proxy dependency and had it return "OK" whenever my class sent it "FOO".  This is not that meaningful of a test since there is no logic in that 1 method.  Other methods had logic based on the parameters; however, this one method was just this simple.  Was I just testing the mocking framework with this particular test?  Arguably, yes...I was; however, in the future, if that ever had to change, I now have a test that I can use to ensure that I get the information correctly.

 

But Unit Testing = More Code & Time

This wasn't so much a barrier for me mentally but was a barrier to adopt it at work.  From what I've experienced now, writing unit tests AFTER the code has already been written DOES lead to more code being written, more refactoring of existing code to make it testable, and more time to do all of this.  However, I have seen that writing your unit tests BEFORE you write any code (as advocated in TDD), you tend to code at the same speed if not a little faster.  I found that I wrote code faster when I did tests before since the production code was already designed for me through the tests I had just written.  There was less thought at the time of coding since the design was setup while I was writing the tests.  I also found myself near-instantly defaulting into the S.O.L.I.D. principles instead of looking at them sometimes as a refactoring step.  Lastly, I wrote less code that would have been for future use (i.e. YAGNI). 

All of this came with a paradigm shift in my object design style.  While some of the basic directory structure and such was the same, I looked at my classes more at a "how do I want to call this class" as opposed to "what methods do I want to show in this class".  The shift in my thinking was more of a consumer than a provider or retailer.  If you only code what you need, you tend to not code things you don't need.  It's as if you go to the grocery store for 1 item and that's the only item that the store has.  Nothing else to distract you in that point in time.  No other products around that you may need in the future.  You are in that 1 moment in time and in that moment, you only have 1 need as a consumer.

 

Summary

While there were other barriers I came across, the rest were either very minor or more about basic implementation like how to return an IDataReader object. I'm sure that I'll stumble across more barriers and moments of enlightenment the more I practice TDD or just unit testing in general.  Until then, I hope some of the items described and discussed here can help others who have struggled to get their head around unit testing in general and some of the principles of TDD.


kick it on DotNetKicks.comShout it

Wednesday, August 26, 2009

Finally Understanding the Merits of TDD

I'm not a TDD person...or at least I wasn't until last week.  Up until then, I had read the blogs and looked at the examples to try to understand TDD and unit testing (with mocking) in general.  Almost all of the examples I was shown demonstrated very basic scenarios that, in most cases, were too trivial to show value.  I would ask people who would speak about unit testing in general how you'd do a specific scenario and would get mix responses ranging from "just try it" to "you should be using this tool and it'll just write the tests for you".

Last week, I had some free time to where I could truly evaluate a code base I finished up with the prior week and see if I could apply some tests to it.  The code I wanted to add tests to were simple repositories where I had abstracted the database calls to separate classes.  Being told to mock the databases out in the past, I started to do that and focus solely on these repositories.  In some instances, it felt like I was testing the abilities of the mocking framework instead of my code but these methods were simple by design (i.e. "Get Customer by Id 'X'").  It was when I started to test more of the methods that I saw that some of the code I wrote had some issues.

The code was functional; however, it wasn't easily testable.  When I would attempt to describe the test, I found that the code did more than one things (breaking the Single Responsibility Principle).  Another incident showed that the name of 1 whole class didn't make sense.  A third incident showed me an issue with the number of complexities that come from multiple dependencies and object inheritance.  After each time that I finished refactoring these issues out of the code and eventually got to working tests, I began to see how the questions that TDD (and BDD) cause you to ask while designing an application really shine.

One example of this was a duplication of code.  I had a class called, for the sake of this post, UserRepository.  The UserRepository had a method to get all users in the system and returned a List<User> back to the calling code.  This class also had a second method that did the same thing but the List<User> only had the FirstName and LastName properties populated.  Why did I write such months ago?  Short answer - I have no idea.  Looking through the code, I found that a different feature needed just the FirstName and LastName properties and nothing else...it was then sending the List<User> to the client for an AJAX call.  While I can understand this now, I could have better implemented the solution by if I looked at the scenario and behavior better initially.

If you ever find yourself wondering how writing more code for TDD or just basic unit tests can actually help the code, my recommendation is to just try it.  Take a simple class that has only a few pieces of logic in it and test it.  Next, take a simple class that has a dependency that you'll need to mock out and test that too.  After you understand how to write these basic types of tests, you can move into the self-reflective questions that really shine in TDD.  Questions like "What type of data do I want to work with when I call method X?", "What will this class need (a.k.a. dependencies) to get me data Y?", and "Is this functionality already present?" are all questions that get forgotten while we're sometimes blindly coding. 

Looking ahead, I can only imagine how my code will be looking.


kick it on DotNetKicks.comShout it

Sunday, August 23, 2009

ParseWiki.js - A JavaScript Wiki Parsing Engine

Like most developers, I have a list of applications or pet project that address various scenarios I would like to develop or find solutions for.  While I have to admit my pet project list seems to grow more than shrink, I do knock things out on occasion.  One of these items was a wiki parsing engine.  Now there are plenty of wiki-based solutions out there; however, I wasn't able to find one that allowed me to bring just the parsing engine into my own solution.  Most of the solutions that are available are full solutions that include the parsing engine, data store, and full UI.  Sure they can be tweaked a bit but having a simple tool that will allow me to mark up some text in a <textarea> field and then preview it is usually too simple for these solutions.  WikiPlex is a great solution to fill this gap on the server side and recommend everyone to check it out; however, it got me wondering if a JavaScript solution could be done for client side parsing.  This is when I started to work on ParseWiki.js.

 

An Overview of the Wiki Parsing Engine:

After looking at a lot of wiki solutions and engines, almost all of them use Regular Expressions to parse the raw text.  I decided to do a similar approach since JavaScript has a pretty good RegEx system.  Since the focus is to just build the engine and not a full solution like Luminotes or Tiddlywiki, I needed to look at the bare minimum items to parse in my engine.  Below is a list of what version 1 of ParseWiki.js has:

  • Headings 1-6
  • bold/italic/underline
  • horizontal rule
  • Named Anchors and Internal Links
  • External Links
  • Ordered and Unordered Lists (1 level only right now)

 

The Syntax:

I've used a lot of wiki platforms from Wikia to CodePlex to Luminotes and SharePoint.  Of the differences in wiki markup each provide, I found it that CodePlex's engine provided the easiest/fastest to use for me.  Because of this, I based a lot of my syntax on such as well. 

  • Headings:
    ! Heading1 text
    !! Heading2 test 
    !!! Heading3 text
    ect.
  • Bold:
    *Bolded Text*
  • Italic:
    _Italicized Text_
  • Underline:
    +Underlined Text+
  • Horizontal Rule:
    ---- (4 hyphens)
  • Named Anchors:
    [a:Anchor Name]
  • Internal Link:
    [goto:Anchor Name|Link Text]
  • External Link:
    [url:External Url|Link Text]
  • Unordered Lists:
    * Item 1
    * Item 2
    * Item 3
    * etc.
  • Ordered Lists:
    # Item 1
    # Item 2
    # Item 3
    # etc.

 

Using ParseWiki.js:

Since I wanted a simple wiki engine, using ParseWiki is very simple.

  1. Download ParseWiki.js
  2. Add it to your Html page
  3. Have your own JavaScript Code pass the marked up text into the ParseWiki() Method
  4. Do with the outputted text as wish.

In the example files provided with the ParseWiki.js download, a full implementation has been provided where I pass the contents of a <textarea> field into the ParseWiki() method and then output it into a <div> to preview.

 

Download the Code with Example:

 

Download ParseWiki.js and Examples: Link

 

Next Steps:

What's next on this pet project?  Well, there are a few things that I need to work on in order to make it better and provide more features.  There's a number of syntax features that I still need to add to the engine (obvious ones are multi-level lists and escape syntax).  Until that time, feel free to play around and with it and let me know what you think.


kick it on DotNetKicks.comShout it

Tuesday, August 4, 2009

SchemaSpy Task for NAnt v1.0 Released

Over the past couple of months, I've been working on creating a custom task for NAnt to provide a simplified way of using SchemaSpy, the open source Java application for database documentation and analysis.  While the code as been feature complete for about a month now, I have finally finished the documentation and cleaning up the code itself.  Please feel free to hop out to CodePlex and give it a try.

SchemaSpy Task for NAnt