David Redding

Blog? What blog? Theres no blog to see here. Please move along
posts - 52, comments - 43, trackbacks - 31

My Links

News

WM Day of .Net May 10, 2008 - I'll be there! Cleveland Day of .NET
www.flickr.com
This is a Flickr badge showing public photos from dredding. Make your own badge here.

Twitter












Tag Cloud

Article Categories

Archives

Post Categories

.Net Resource Sites

.Net User Group Sites

Language Resource Sites

Mason Sites

My Bloggin' Buddies

Monday, May 12, 2008

Hot Damn!!

I know a WMDODN (West Michigan Day of .Net) Post is in order, but that can wait.  check this out!

http://blogs.msdn.com/xna/archive/2008/05/07/announcing-xna-game-studio-3-0-community-technical-preview-ctp.aspx

Finally, we can start building games for our zunes! WOOT!  I expect to create a talk on the topic very soon

posted @ Monday, May 12, 2008 10:14 AM | Feedback (0) | Filed Under [ Personal XNA Speaking Misc Tech Stuff ]

Tuesday, April 22, 2008

My traveling talk begins with CODODN!

    The C# variety Show began on Thursday with my trip to GLUG.net in Lansing, (this is a great group of guys and gals, and if your free, I highly recommend you to attend, they even have a user group in Flint now!) and didn't stop until yesterday when I got home from CODODN.

     At about 6:30 on Friday, Mr. McWherter shows up at my house and the road trip begins.  After about 4.5 hours, stopping only for necessities we arrive in Wilmington Ohio around.  After checking in at the hotel adjoined to the conference center we started twittering to find out if anyone else had made it down yet, and got no love.  Now...for those of you who have never visited Wilmington, this picture should illustrate what it's like...

wilmington

    Right...almost the middle of nowhere...However the Roberts Conference Center is conveniently located between the 3 major user groups in the area: Cincinnati, Dayton and Columbus.

    Unfortunately, I didn't get the opportunity to visit any of the sessions because I had to polish up the demos for my presentation.  I did however get to hang with some of the best speakers around in the speakers lounge.  It was great to be surrounded by folk who knew what they were doing and were able to throw this newbie speaker some great hints (Like, write your demos before you show up to the conference).  Also, with three user groups involved I was able to meet A lot of great folks.  All in all, the venue was a perfect fit for the conference.

    I had just finished up my Demos when it was my turn to present.  At first, there were only a handful of people in the room, but within a span of just a few minutes, there were people standing in the back.  I was nervous as hell, but managed to get through the presentation, even with my funky new presentation mouse constantly wanting to zoom in on everything (Kudos to Mr. Prince for the presenter mouse).  I had a lot of good questions throughout the presentation and most of the folk seemed to respond well to the "bite-sized-pieces-of-information" format.  I even managed to get a few laughs out of my crude since of humor. One of the best pieces of feedback I received was that my talk was "..Like the man show meets the Nerd show"...so maybe "Girls on trampolines" isn't to racy for my talk after all :)

   100_0077 After my presentation, I had the chance to hang out with Josh Holmes and Joe O'Brian where we talked about presentation styles and they regaled presenting war stories (I especially like how Joe was trying to make a point and almost fell of the stage...priceless!).  After the final presentations let out, we all ventured into the main ballroom for the swag give away.  Some folks walked away with great gear, including licenses to Infragistics controls, Refactor and a host of other fantastic developer tools. 

    Once the conference was declared closed, most of us headed over to Max and Erma's, which was attached to the hotel/conference center.  Due to a mis-communication, the restaurant had no idea that we were coming.  Eventually we wound up with a party of 30, which the Hostess' and wait staff handled very elegantly.  The service was top notch, however, most of us never received our appetizers (those of us back in the restaurant..there were quite a few of us still in the bar).  So dinner went GREAT and the food was fantastic (Loved my heartattack-on-a-bun-pulling-over-in-Toledo-on-the-way- back-to-blow-up-a-restroom burger...thanks Mr. Hawley and Mr. Prince). 

    After things quieted down at the dinner table, about half (if not more) of us ventured up the Mr. 100_0118Blankenburgs room for a little poker party.  things got off to a great start, at my table was Dave Smith, Sarah Dutkiewicz, Matt Casto, James Bender, Monish (Mo) Nagisetty, Phil (Can't remember your last name chief) and Dan Rigsby.  I had never had a chance to sit and hang out with most of these guys so it was great, drinking Sam Adams (even though Blankenburg got Miller and Coors just to f with me) and talking a combination of smack and tech.

    A couple of hours later, we combined tables where it was Me (I made it woot!), Dave, Phil, Jeff Blankenburg, Jeff McWherter Kevin (blanking on your last name to bud) Cory Haines, and I think Darrell Hawley (I had a bit of whisky in me by this point so I'm a little fuzzy on the details).  I ended up going out on the second hand where I called Kevin, thought he was bluffing...but he ended up having a flush and taking me out.  Was a great game and I walked away with "Extreme programming adventures in c#" as a consolation prize.  I do remember that at one point, Amanda Laucher Took all my chips while I was ordering Pizza and made them all pink...I immediately grabbed one of Dave Smiths chip racks and exchanged it for the pink one.  The night continued on in due form with lots of great tech talk and a whole lot of drunk humor.  Mad props go out to Blankenburg and the rest of the MS guys that made this happen.  It was a great way to end a fantastic conference.  100_0151

    The Next morning,  those of us who had survived the night of poker ventured down to Max and Ermas once again for a fantastic breakfast.  Shortly thereafter, we all headed back home.

    This was my first overnight stay for a conference and I enjoyed every last minute of it.  A perfect way to bring many people who are passionate about what they do together.  I had the opportunity to meet and talk with a fantastic group of professionals who are dedicated to the community.  I can't wait till the Western Michigan day of .net where we can all meet up again.  After that, who knows, maybe the Cleveland Day of .net? or even the upcoming Lansing Day of .net!

posted @ Tuesday, April 22, 2008 9:23 PM | Feedback (3) | Filed Under [ Techie .Net Stuff Because Josh Holmes made me Speaking ]

Friday, April 18, 2008

Lets start this show!

    So last night kicked off my tour with the C# Variety show talk that i'll be giving in about 5 other places (as of this writing).  I had the opprtunity to present before a fairly large group of folk at GLUG .net.  And I have to say that they were fantastic hosts.  I got alot of great feedback on the talk and we had a great time at the bar afterwards (As is tradition for all user groups). 

    I'll  be on the road tonight carpoolin' with Jeff McWherter starting tonight.  I've got two seats left in the BaddAss-Mobile if your interested in riding,drop me a line.  We'll both be speaking at the CODODN Tomorrow, and I encourage you all to just show up.  I'll be presenting around 2:50 in the afternoon. 

Central Ohio Day of .NET

Where:
Roberts Centre‎
123 Gano Rd
Wilmington, OH
45177 

 

    I look forward to meeting you all there.  I look even more forward to sharing my bottle of makers mark after the conference with you.

posted @ Friday, April 18, 2008 11:47 AM | Feedback (0) | Filed Under [ Speaking ]

Monday, April 07, 2008

Speaking engagements

So, you might have noticed the badges on the left.  Let me give you a run down.  I'll be presenting the C# Variety Show at the following places, at the following dates...feel like i'm on tour

Lansing .Net Usergroup                April 17th
Central Ohio Day Of .Net                April 19th
West Michigan Day of  .Net            May 10th
Eastern Tenn. .Net User Group    June 24th

  So, i'm going to be busy.  I'm still waiting to hear back from the Cleveland Day of .net and a few user groups in Texas.  Keep an eye out, The C# Variety show may be comming to a city near you!

 

posted @ Monday, April 07, 2008 11:36 PM | Feedback (1) | Filed Under [ Other Five Min Tech Speaking ]

Monday, March 31, 2008

Watashi no "IL Code" seksu desu

    So, I may not be entirely up on my un-couth Japanese sayings, but one thing is for sure, IL code, to the average developer (Read: Me) might as well be written in the same Romaji thats in the title.  That is, it's hard to make heads or tails of, and since you most likely never, or only rarely look at it, you get very little opportunity to actually study it.  I've been the same way for the past few years, acknowledging that IL exists, and just like that ugly friend, I don't actually acknowledge there being a relationship between "It" and I in public.

    That all changed for me last Friday when my buddy Joshua Haynes dropped me a note abut my "Unloved Operators" Tech in 5 minutes post .  He was interested enough in how the ?? operator stacks up against the if(x==null) else structure that, he compiled an example and then sent me the IL code, looking for my opinion. 

    So I was stuck.  I could not admit defeat because of my ignorance of IL.  So I leapt into action, quickly throwing out all the TLA's I could in an attempt to undermine my friends intelligence.  He quickly blocked, pivoted and swatted away my attack.  Before he could completely recover I attempted the Clinton-Dodge-the-issue move I had learned from CNN, but Joshuah quickly saw through funny analogy's and interesting tangents and held his ground firmly, so....I gave in and made a trip to the oracle Google.  Come to find out, it can be difficult to research an answer, as compared to just pulling out of god knows where.  But I think that I figured out how do answer Josh's imposing "What do you think?" question.  below is the code and the IL that he sent me.

Person myself = null;
Person myFriend = new Person("Johhny", "Cash");
Person newFriend = myself ?? myFriend;
Console.WriteLine("The new Friend likes: {0}", newFriend.FullName());

if (myself != null)
   newFriend = myself;
else
   newFriend = myFriend;
Console.WriteLine("The new Friend likes: {0}", newFriend.FullName());

IL_0012:  stloc.1
  IL_0013:  ldloc.0
  IL_0014:  dup
  IL_0015:  brtrue.s   IL_0019
  IL_0017:  pop
  IL_0018:  ldloc.1
  IL_0019:  stloc.2
  IL_001a:  ldstr      "The new Friend likes: {0}"
  IL_001f:  ldloc.2
  IL_0020:  callvirt   instance string Test.Person::FullName()
  IL_0025:  call       void [mscorlib]System.Console::WriteLine(string,
                                                                object)
  IL_002a:  nop
  IL_002b:  ldloc.0
  IL_002c:  ldnull
  IL_002d:  ceq
  IL_002f:  stloc.3
  IL_0030:  ldloc.3
  IL_0031:  brtrue.s   IL_0037
  IL_0033:  ldloc.0
  IL_0034:  stloc.2
  IL_0035:  br.s       IL_0039
  IL_0037:  ldloc.1
  IL_0038:  stloc.2
  IL_0039:  ldstr      "The new Friend likes: {0}"
  IL_003e:  ldloc.2
  IL_003f:  callvirt   instance string Test.Person::FullName()
  IL_0044:  call       void [mscorlib]System.Console::WriteLine(string,
                                                                object)
The top is the ?? test and below is if statements. What do you think?

   So, starting from the top, I began to investigate what each call was.

    The first thing i needed to figure out was, what was the "IL_xxx" marker? simple, line numbers, easy enough.  Next up, what does this mean:

brtrue.s   IL_0037

a little googling and i found that "br" means "Branch" so "brtrue" must mean "True branch from a decision" (the .s seems to indicate Short form, or something of that nature).  So combine that with a line number and we have a basic go-to statement of

IF True GoTo: IL_0037

Ok, so that tackles the low hanging fruit.  The next thing on the list was these

stloc.x
ldloc.x

To google for these, i had to rack my brain for a bit.  I discovered that there is an OpCodes object that lives in the system.refelction.emit namespace.  And surprisingly enough, it has codes that match what I'm seeing the the IL.  So I quickly discovered the following entries.

 

Stloc_0 Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 0.

 

Ldloc_0 Loads the local variable at index 0 onto the evaluation stack.

Alright, so basically, both of these commands manipulate the Stack (more on "The stack vs The Heap" in another post).  Stack, from wikipedia For now, lets just call the Stack = Fast memory but limited The Heap =Slow Memory, but massive.  Think of the stack as a tower of single bricks.  Each brick represents a single amount of data.  When you "Pop" an item of the stack you grab the top most item and remove it (in our case, we also "Pop" from an indexed item), when you Push (again, in our situation "Load into"CEQ Compares) your putting something.

There were a few other things to check out before I could move on.  For instance, what does ldnull and ceq do?

Ldnull Pushes a null reference (type O) onto the evaluation stack.

Ceq Compares two values. If they are equal, the integer value 1 (int32) is pushed onto the evaluation stack; otherwise 0 (int32) is pushed onto the evaluation stack.

    Ok, simple enough. LdNull puts a Null Reference Type onto my stack, and Ceq checks for equality.  This will become important later on.

    Ok, so I'm armed with some basic implements of the trade, time to start interpreting.  The second section seems a bit more straight forward, so lets start there.

  IL_002a:  nop 
                    means no-operation, do nothing, waste time, etc...
  IL_002b:  ldloc.0
                    Load into a local var whatever is in location 0 on the stack (object "MySelf")
  IL_002c:  ldnull
                    Load a reference to a value on the heap, into my stack...
  IL_002d:  ceq
                    Compare the last two values to each other and stuff them into the stack (if x == null)
  IL_002f:  stloc.3
                     Pop item at index 3 of the stack and into the local variable
  IL_0030:  ldloc.3
                    Load the value stored in index 3 of the stack to the local variable stack (the result of ceq)
  IL_0031:  brtrue.s   IL_0037
                    if that value is 1, skip to line 37
  IL_0033:  ldloc.0
                    Load the value stored at index 0 of variables into the stack (remember, the person "MySelf")
  IL_0034:  stloc.2
                    Pop the item at index 0 of the stack into the local variables (what we just loaded);
  IL_0035:  br.s       IL_0039
                    Branches us directly to line 39. do not pass go, do not collect $200
  IL_0037:  ldloc.1
                    in our else statement, Load item at index 1 into the stack (remember, make x = y if null , essentially)
  IL_0038:  stloc.2
                   
pop off item 2 from the stack into the local variable (the actual variable getting assigned)
  IL_0039:  ldstr      "The new Friend likes: {0}"
                    
load  this string into the stack
  IL_003e:  ldloc.2
                    
load variable 2 into the stack (the "NewFriend" object)
  IL_003f:  callvirt   instance string Test.Person::FullName()
                     
call the following method and load it's value
  IL_0044:  call       void [mscorlib]System.Console::WriteLine(string,
                                                                object)
                     
call this method, which has full access to the stack, so were passing it, in this order, the string "The New Friend Likes:{0}" and then stack item[1] which = the return of Test.Person.FullName property.

    Well, that was quite a bit.  So the simple rundown is....it does exactly what our code tells it to.  Interesting to note though, is were newing up an object of type "Null" and doing an object comparison between it and "Myself".  This isn't bad, but it's a tad slow.  You also have to load up every property and variable to see if they do actually equate.  Find in most situations, but like in the previous post, if you make a comparison of Type B to Null from Type A, when Type B Has references Type A doesn't, your going to error out...because your loading values in Type B, that Type A is ignorant of....GetItGotItGood.

     Ok, so we've seen what the commands do, lets take the short route examining how the ?? works in IL.

  IL_0012:  stloc.1
  IL_0013:  ldloc.0

  IL_0014:  dup
                   
Duplicate the item on top of the stack and pushes the duplicate into the stack
  IL_0015:  brtrue.s   IL_0019
                    If the values are the same (if the value of the object is empty like the first register) jump to 19
  IL_0017:  pop
                    Else pop the first item off the stack and get rid of it
  IL_0018:  ldloc.1
  IL_0019:  stloc.2

  IL_001a:  ldstr      "The new Friend likes: {0}"
  IL_001f:  ldloc.2

  IL_0020:  callvirt   instance string Test.Person::FullName()
  IL_0025:  call       void [mscorlib]System.Console::WriteLine(string,
                                                                object)

    First off, we have obviously fewer instructions. Secondly, and most important, notice that were not doing any object comparisons or loading any objects from the heap.  so the breakdown after examining the two IL statements is this

If(x == Null) is like saying (If object x is the same as object Null)
and
x??y is like saying (If object x is as empty as Brittney Spears head)

    So in short, ?? is faster, and easier to evaluate because were only comparing it to an empty value in the stack, not a reference type.  Obviously the speed gain is minuscule, but it's still there.

    Ok, so IL probably will only help you gain geek cred and debug issues that you'd rather not be debugging.  But understanding IL code is worth serious geek cred, and helps you prove (or dis-prove) your theories on how your .net code works.   And hey, chicks dig the serious geek ;)

posted @ Monday, March 31, 2008 10:52 AM | Feedback (0) | Filed Under [ Techie .Net Stuff Other Misc Tech Stuff ]

Tuesday, March 11, 2008

Tech in 5 Minutes: Nifty C# operators that don't get much love

    In my travels around  .Net land, I've come to know, love and exploit several denizens of the tribe of C#.  Some of these have already been written about, such as Yield return and the => operator.  But more recently, I've had the opportunity to educate some fellow travelers on two of the most useful, but least used operator.  Those being the Comparison Operator (?:) and the Null Coalescing Operator (??).

    Lets start our adventure by watching the Comparison Operator in it's natural environment.  If you watch closely, it'll show you it's syntax...

bool statement ? true : false 

    Due to it's nature, this operator is sometimes called the Ternary operator. The reason being is that it takes 3 operands.  In normal use, here is what it looks like:

CurrentBeer.Empty==True ? CurrentBeer = Wife.GetMebeer() : Me.TakeDrink(CurrentBeer);
(this can be shortened further by taking out the ==True, since .Empty is most likely a bool property)
CurrentBeer.Empty?CurrentBeer=Wife.GetMeBeer():Me.TakeDrink(CurrentBeer);

    You can see how this replaces the overly verbose syntax of :

If(CurrentBeer.Empty)
    CurrentBeer = Wife.GetMeBeer();
else
     Me.TakeDrink(CurrentBeer);

    Syntax sugar? Maybe.  But it's definitely useful as a quick way to get things done. Elegant, Efficient and Desirable, three features my first girlfriend was lacking in.

    But wait! Theres more!  Just send me three easy payments of $29.95!

  So now, lets check out the ?? operator.

    The ?? operator has saved me boat loads of finger_impact_on_keyboard stress ever since the advent of C# 2.0.  It's easiest to think of this operator working similar to the comparison operator above.  Lets lift it's skirt real quick and have a peek at how it functions

x = ValueThatMightBeNull ?? DifferentValue;

    Ok, much like the first time you played doctor, things might be confusing, but it's really simple.  Basically the ?? will evaluate whether or not the thing to the left of it is null, if it is, it will evaluate and return the thing on the right.  Lets just see it in action, it's easier that way...<Dear "Usually offended by my posts": Please Insert vulgar joke of your choice here>

 //This is how my wife found me
Mate SuitableMate = Mate.Get(GoodLooking)??
                                      Mate.Get(AverageLooking)??
                                      Mate.Get(DoesntHaveAnAssForAFace)??
                                      Mate.Get(AtleastHeHasAJob)??
                                      Mate.Get(Dave)

    If your confused, let me lighten things up for you hear.  Each A = B??C statement is the equivalent of saying

If(B != null)
    A = B;
else
    A = C;

    So when we string them together like that, it's just like saying If = null else if = null else if = null  etc etc etc...  So, obviously, based on our previous statement, everything up to Mate.Get(Dave) must have returned null if my wife wound up with me.  I do have a job now though....so I wonder if i still would have made the cut.

    There is one more benefit of using the ?? operator that I actually stumbled across.  Take this code as an example:

public class DataObject
{
    public NullableObject a = 1... etc
}

public class BO
{
 public NullableObject  Stinks= 0;

  public static implicit operator BO(DataObject e)
  {
      return new DataObject{Stinks= e.a};
  }
}

now...later on in the UI of the app (which should NOT have ANY reference to the DataObject class) if we write this code:

If(MyBo==null){Console.WriteLine("WOO HOO, You have no BO!!");}

..were going to get a compiler error.  The reason being, as far as I understand (hopefully commenter's can expand on this) is that when you compile that statement, the compiler is doing type checking against the objects used in the class your checking for null in.  In other words it checks to see if anything is returning null from within the class.  Now, since the operator takes a type of DataObject, the complier expect you to have a reference to that class...if you don't, then *Poof* no compile.

    Now, to get around this, we can write...

SomeoneElsesBo = MyBo??(MyBo = new BO());

   ....And the compiler is happy.

Hell, we can even put these two operators together, check this out:

Mate SuitableMate;
Step Next_Step_In_Life = ((SuitableMate = Mate.Get(GoodLooking)??
                                                                                Mate.Get(AverageLooking)??
                                                                                Mate.Get(DoesntHaveAnAssForAFace)??
                                                                                Mate.Get(AtleastHeHasAJob)??
                                                                                Mate.Get(Dave)) == Dave?SobQuietly():null)??(Step)PartyItUpWOOT();

  I'll leave you with this.  The best places I've found to use the ?? operator is in returning data base fields where the value might be null, here is a quick example and the best way I've found to implement the ?? solution

//First i check to see if the value from the db is DBNull.value
//Dr = DataReader
//Do = Data Object with nullable Types


DO.ValX == DBNull.Value?null:(Int32?)dr[0]
//If you don't get the ? reference after the Int32, no worries, It's a nullable type, and I'll post about it soon.

    The reason I do this, is so I can keep the actual DB value in my DataObject, which is supposed to be a true reflection of my data.  Later on, in the actual business object, where I don't accept Nullable types I can say this.

BO.ActualValX = DO.ValX??-1;

      And Bada-Bing, I'm good to go.  Later on, i can pass either -1 or even null back into the DB and repeat this cycle when retrieving my data, it works, and i don't have any logic, other than conversions from DBNull, in my Data Object class.

posted @ Tuesday, March 11, 2008 11:31 AM | Feedback (0) | Filed Under [ Techie .Net Stuff Five Min Tech Handy Tools ]

Tech in 5 Min: TDD: Code, Your Way

    We've all heard the buzz acronym TDD.   But has anyone actually put these things to use in a practical way?  I know of a couple of guys who have, but for the most part, a majority of developers tend to shy away from this new fangled gadgetry.  The main reason, I believe, is that it can be difficult to justify a learning curve when:

  1.  A solution in a current ver. of code exists
  2. Management is on your ass to just "Get it done"
  3. Open source projects are a natural contraceptive

    Now that I've stated the obvious, lets get on with it.

    Requirements, everyone gets them, no one knows how to write them and they are usually so vague that you can tell someone has a huge ass their trying to cover.  The biggest pains when it comes to requirements are, the acceptance of a "Moving Target" as part of business, and flaky UI designs in the document.  Honestly, does Barbara, the manager of the mail room, really know what the hell a number spinner is or is she just a control freak who needs a coke and a bottle of horse ex-lax to work that stick out?

    To put it bluntly, Requirements define the business logic that needs to go into the app.  They are not justification for the app, that should have been done long ago.  Neither are they "Screens" or "Mockups".  Those get done by someone who actually (supposedly) knows what their doing.  That may be you, it may not, depends on your shop.  Either way, they don't belong in the document.

    So, what do these obvious statements have to do with TDD?

    Lets start at the top.  Typically, in non-TDD terms, when you get the requirements, you start coding.  Sure, you look at whats needed, pick out the sticky algorithms and look for logical objects, but ultimately, the first thing you write is:

Namespace Giveme
{
    public class Beer
    {
        public int AndWomen()
         {

    Your mileage may vary, but typically you start writing code intended for production right away.  And when the boss man speaks, you refactor refactor refactor.  What happens after several refactors?  Well, for one you've lost an easy way to CYA because none of your code matches the original requirements, it all matches what Boss man said.  So now your left, holding the bag while Barbara and the Boss man say "We did our part, the developer is taking to long".  At this point you get the "Talk" from someone who has no clue what it is you do, but by god, they know how to manage!

    Enter TDD.  It may not cover your ass completely, but it may slightly, depends on how big an ass you are.  Plus, you'll get your work done a whole lot faster.  I know what your thinking...that writing unit tests is as painful as sitting the wrong way on a pineapple (is there a right way?),  and it can be.  Typically we've been introduced to unit tests by means of testing after development, which goes something like this





Manager:  TDD is shiny. Bob, go write unit tests for all our legacy code
Bob:  OK, but that will take me several months to complete
Manager: Nonsense, your just making sure working code works, Now, Kiss the ring and get me a pineapple.  Then I expect 150% code coverage by tonight!

    So Bob goes off and attempts to generate unit tests around the existing code.  The existing code has some pretty complex methods which must be refactored out in order to test, so more tests are written.  Come to find out the refactored methods need to be refactored again, and again and again....and new objects must be created.  This cycle can (and in most cases does) create unstable code. This is what makes developers climb the bell tower, or have the sudden urge to become postmen (if you didn't get that last joke, just move along).

    OK, so say your starting a new project.  You've learned that unit testing after the fact leads to A LOT of re-factoring, and is a code destroying monster. So you want to avoid that at all costs.  The solution?  Write your tests first, get them out of the way.  The simplest form of TDD is:An excellent diagram from Brad Wilson, click the image to see his blog

  1. Write Test
  2. Fail Test
  3. Write Code to pass test
  4. Pass test
  5. Refactor to nice code
  6. Go To : 1

Otherwise known as

1.) Red
2.) Green
3.) Refactor

So here is how it helps you. (I'm diggin' the numbered lists today)

1.) Unit Tests are tied to the requirements
2.) Writing tests first ensure you write ONLY the functionality you need
3.) 1 + 2 = quickly written solid code .

 


  Here's how it works.  First off, before writing any code for production at all, you break down your requirements into subsections, and then break those down. so on and so forth.  Once your at the smallest bit of requirement (determining how much beer it would take for individual A to take individual B home in this instance), then you write a unit test that specifies how your method will act and look from the outside:

public void BeerGogglesTest()
{
       //We really should atleast have a container class
       BarFlys bf = new BarFlys();

        //What we expect the method to return given the inputs
       double expectedValue = 20;

       //Test constants
       //We'll talk about the whole "Mock" thing in a second.

       int Dave= new MockPersonDave();
       int DavesWife=new MockPersonDavesWife();

       double BeersAlacContent = 7.5;
       
        //Here we check
        double HowManyBeers  = bf.NumberOfBeers(BeersAlacContent, DavesWifes,Dave)

        //Here we assert the value we received was the value we expected
        Assert.IsEqual(expectedValue,HowManyBeers);
}   

So...now you compile that.  Yes, before writing any more code.  Of course the test fails with a few exceptions.  Your first task, get rid of those exceptions.  With TDD, your essentially coding to your implementation, or API.  Similar to coding to an interface.  So every bit of your application comes down to ,"Write enough code, just barley enough, to legitimately pass the test"(notice i said Legitimately, so all you smart asses who would return 20 every time need a lesson pineapple-fu).  In our scenario above, we would need to implement a public BarFlys class with one and only one method.  That method would only take the 3 parameters listed.  Don't worry about extensibility or any fancy OOP crap yet.  That will come in time....maybe. 

public class BarFlys

{
    public double NumberOfBeers(double AlacConsistancy, IPerson p1, IPerson p2)
    {
           double p1DesireToLeave = CalculateDesire(p1.InitialInhibition,p1.alacholConsumed,p1.tolorance);
           double p2DesireToLeave = CalculateDesire(p2.InitialInhibition,p2.alacholConsumed,p2.tolorance);

 

           return Math.Sqrt((p2.CalculateDesireAbility(p1) + p2.DesireToLeave)/p2.tolorance)*p2.CommonSense
    }
}

    As an important aside, we must have already written tests for CalculateDesire in order for this to be a valid test run.  We'd want to test it in the same manner we are testing "NumberOfBeers."  If we didn't test  those method first, then we may end up skewing our test results if there is a failure in one or both of them.  Meaning NumberOfBeers would fail, but only because a Dependant method failed.

      Once you pass that test, you move onto the next test. And continue on until you have a nice little set of tight, solid code.  After wards, you begin to refactor.  But, at this point, refactoring isn't about design changes.  Your design has already been defined by your tests.  Instead, you can focus on the real things, like optimizations and readability.

       So, what are these "Mock Objects" I was going on about earlier?  Well, Mocks can warrant their own blog post  in- and-of themselves.  But here are the essentials.  A mock object works just like a bottle of O'Dules or Coors Light, it's a fake implementation of a real solid object.  Take this for example: You need to develop the front end to a website that runs exclusively off of web services.  However, like most developers, the guy working on the services was hit by a bus or married a super model (your choice, i for one vote bus, that still leaves me the opportunity to meet this super model turned on by developers). 

    Management has threatened to stop paying you if you don't get off your ass and start writing that front end.  The Solution? "Mock" the web services.  Essentially, your going to write an object that mimics the behavior and implements the interface of what the web services are supposed to look like.  Your also going to have those mock objects return data in the same format that the web services would.

  Now, granted, it didn't take that many beers when I  first met my wife. However, I think her common sense had some environmental issues to contend with, like she just saw dirty dancing or some other chick flick.  Either way, I beat the odds :) 

posted @ Tuesday, March 11, 2008 11:29 AM | Feedback (2) | Filed Under [ Five Min Tech ]

Monday, March 10, 2008

Central Ohio Day Of .Net

It's that time of year again.  Where the snow hasn't quite gone away, and it's still cold as Steve Job's gaze.  Which means it must be time for a Day of .Net event! WOOT!

Central Ohio Day of .NET     I'll be presenting a new talk I've derived.  Some of you may remember the XNA presentation I gave for the last DODN in Ann Arbor.  Don't worry; my ADD has kicked into overdrive and now i'm off to other sparkly things that are not XNA.

    For this go-around i'll be giving a new talk that I've wrangled up from the inner most reaches of Reddingdom.  Here is the abstract in it's original and uncut format.

Abstract: The C# Variety Show! Lvl: 200-300
 
    Let's face it, Technology is boring to the non-technologist.  How many of you run home to your significant other and say "Ooh OOH Guess what I learned today…"  I'm guessing at this point you get "That's nice dear, what's for dinner?".  Well, let's change that.  If you really want something to talk about, come listen to Dave Redding explain how his wife's only job is to fetch beer from the fridge using Yield Return, or about how Mom and Dad give Kid a personally disorder since he's a Singleton.  This talk will cover a wide variety C# and Software development topics, ranging from Design patterns to C# specific implementations.   I guarantee you'll see more references to Beer, Women and small furry rodents than you ever had in any other technology talk.

    I'll be updating this in the weeks to come based on some excellent feedback that i've received.  But the spirit of the talk will be the same.  Roughly, this talk will cover a few key Tech in 5 min articles I've written over the past year.  Maybe I should change the title to "Tech in 5 min Live!" or "How to offend your neighbors with C#", either way, it's going to be a great time....assuming Ohio Isn't still buried under 123' of snow.

    Come on down and I might ... just might, get you to buy me a beer.

posted @ Monday, March 10, 2008 12:12 PM | Feedback (0) | Filed Under [ Speaking ]

Thursday, February 21, 2008

Microsoft announces Open Protocol Specfication

The link explains it all

http://msdn2.microsoft.com/en-us/library/cc203350.aspx

As a developer, you now have full access to the information about Open Application Programming Interfaces (APIs) and Open Protocols. All Windows client operating system API documentation is now available on this MSDN website.

Wow!!!

posted @ Thursday, February 21, 2008 1:15 PM | Feedback (0) | Filed Under [ Techie .Net Stuff Other Personal Misc Tech Stuff ]

What I've learned from bloggin'

    I know, 2 whole blog posts in 1 week, i'm going nuts!  Actually i'm trying to ramp up my blogging frequency, so keep an eye out for a few more tech in 5 min and other sheeeet.

    If you would have asked me a little more than a year ago if i'd have a (psudo) active blogging habit, I would have laughed it off as something I "Should" do and dropped it.  So I still find it a little hard to believe that i've been at this for as long as I have.  

    Now, while most bloggers seem to make a post in this vein targeted at non-bloggers. I'm not going to.  if you don't want to blog, don't.  Honestally, I'm not trying to convince anyone of anything and i'm narciscistic enough that I can truly say, I could give a shit less.  It's your decision to make and I fully support anyone taking on the daunting task of blogging, I also support everyone else who doesn't.

    When considering starting a blog, I had the same excuses as everyone else:

  1. I failed English in H.S., there is no way I could carry on with some kind of constant writing that was open to public scrutiny.
  2. I don't have time.
  3. Does the saying "It's better to be thought  a fool than open your mouth and remove all doubt" mean anything to you?

    And the most pervasive argument people make to get out of blogging

      4.    What do I have to say that has'nt already been said before? most likely in a better way than I could ever pen!

        Bearing all that in mind, I finally succumbed to my buddy Josh Holmes pressure to start a blog.  It's been an interesting trip,  and I'd like to take a moment to share with you all what i've learned along the way.

      1.) Whatever you write on your blog is inxoriabally tied to you and your name on the internet AND the real world.

        Boy, was this a hard lesson learned.  Like many other people, I've grown accustomed to the annomity provided by the internet.  Like schisophrinic wearing a straight jacket looking for a bathroom, I've bumbled across the web acting and speaking in ways that just are not appropriate in polite company.  Which is fine, if your assuming annoyminity. But with a blog, especially a trade blog, you are not anyonomous, not even if you use a pen name.  Someone will know who you are and let others know and then BAM, your Real Life name is tied to your writings.  Point in case: the lambda expressions tech in 5 min offended a buddy of mine.  This buddy exists in Real Life.  We drink beers together, talk shit and hangout.  So to find out that he was pissed at my real life persona because of something that my internet one did...that was quite a shock.

    2.) People are interested in what I have to say, even if they've read about the topic 20 times already.

         The one thing I've found through blogging is that, people like options.  Like, what kind of car to drive, where to buy their hamburger, or where they go to drink.  That urge to have "Options" tend's people to look around.  Just because Jay says Vista Sucks for this reason and that, someone else may say it sucks for other reasons.  Every blog post (except the ripped off from the authors site) is a unique perspective on the world around the author.  So, yeah, someone out there is going to talk about WPF, but is it you?

    3.) I've never learned so much about technology so fast.

         There has never been a truer statement.  When writing my blog, especially the tech in 5 min, i'm forced to double check my assumptions and do a little research before I post to my blog.  You don't want to post mis-information, and you don't want to appear a hack, so you have to study.  Also, you have to stay on top of technology if thats your blogs focus, you don't want to become stale.

    4.) Having a blog gives you geek cred.

        Having a blog is a highly interactive deal.  It may not seem like it, but the next time your at a launch or usergroup and you mention your blog, bam, someone's going to check it out, and possibally comment.  And, since your in print (sorta) you gain crediability.  Not only for the content of your blog, but for having the huavos to put your name out there and voice your opinion.

    So, i'm not going to say, "Get out there and blog" or something crazy like that, but what I will say is that if your making excuses to not blog, then your only letting yourself down.  Blogging is strangly addicitve, a great way to network with people, a fantastic way to show people what you have to offer, an excellent opprtunity to enhance your communication skills and overall, gives you a voice on the internet.

posted @ Thursday, February 21, 2008 9:33 AM | Feedback (2) | Filed Under [ Other Personal Misc Tech Stuff ]

Powered by: