Posted by: jsonmez | January 5, 2012

No Class is an Island

One of the biggest challenges I’ve found with any framework is to make it self-discoverable. 

It is often difficult to build a framework or API in a way that users of that framework can easily know what exists and when to use what.

One of the main reasons why it is difficult to write a good framework is that many developers tend to create classes that are very loosely connected to other classes in that framework with which they are intended to interact.

104004A.TIF

Defining the island

When you create a series of classes, do you explicitly plan for those classes to depend on each other or do you try to design them in a way so that they are independent?

This question brings up the old topic of loose coupling and tight cohesion.

I consider a class to be an island if it is loosely coupled, but also loosely cohesive.

A class that is an island is a class that does its own thing with very little dependencies or very weak dependencies.

Imagine for a moment a CurrencyConverter class.

This class is designed to take an amount of one currency and convert it to another currency.

There are several ways we could create the API for this class.

Here is one of them:

public class CurrencyConverter
{
    CurrencyConverter(ICurrency destinationCurrency)
    { ... }

    ICurrency Convert(ICurrency sourceCurrency, decimal amount);
    { ... }
}

 

Now this seems like a pretty reasonable API, but there is a problem here.  The problem is if you have a class that implements ICurrency, you don’t have any good way to know that this class exists.

If we don’t do anything else, this class might as well not exist at all.  It is an island.

It can see classes it needs to use, but the classes that could benefit from CurrencyConverter don’t know it exists.

The developer that is using an ICurrency implementation has no good way to know that this convert exists.  Most likely a developer will end up writing their own implementation of a currency converter. 

Duplication! Bad!

The date and time link

You will often see this in code bases and frameworks.  You will have many different utility folders or classes that help do date and time operations.

The problem is that no one really knows these utility classes exist and so everyone ends up rewriting the functionality all over your code base and you have a mess.

Take a look at your own project, see if you can find all the utility classes that deal with date, time or currency.  Now check to see if those utility classes are being used everywhere they could be.  Chances are they are not.

Building bridges

We need to build a bridge to the island so that everyone can enjoy the nice beaches.

No point building your wonderful CurrencyConverter if no one knows it exists, right?

So how do we solve this problem?

It definitely is a tricky problem to solve.

The best way I have found is to tie the dependent class back to its dependency. 

Yes, I am advocating circular dependencies!

Don’t be alarmed, it is not that bad.  All you have to do is make sure that your ICurrency interface has a reference to CurrencyConverter so that someone using ICurrency will know it exists.

Now there are many ways of doing this.  Some involve using a base Currency class, others involve creating different static constructors for Currency classes.

I am going to show you a very simple example, just to make my point.

public interface ICurrency
{
    ConvertUsing(CurrencyConverter converter);
}

 

It really is that simple.  You have now built a bridge to the island that was CurrencyConverter.

Now when a developer types ‘.’ on an ICurrency implementation they will see a convert method that uses your converter and they will know it exists!  Joy!

Again, there are many ways you could build this bridge.  My intention is not to debate them here.

The point is… BUILD THE BRIDGE!

But it is a circular dependency, that is bad

Really?

It is worse than 5 implementations of currency conversion in your code base?

What we have really done here is build something that is extremely tightly cohesive.  This is not necessarily a bad thing.

What we don’t want to do is to tightly couple the currency conversion to our billing system code.  We don’t want to have some building system class being used by our CurrencyConverter.

Applying the idea further

The basic idea here is that every time you create a new class you should think about how someone will know it exists.

If the class is out there on its own and it is likely to be useful in the the future, you must do something to tether it back to its dependencies.

It is helpful to have the attitude that if a developer can’t discover your class by some other class through intelli-sense, your class might as well not exist.

Every time I create a class, I try to think of two things:

  1. How will someone use this class
  2. How will they know this class exists
Posted by: jsonmez | November 21, 2011

Understanding the Vertical Slice

One of the biggest challenges in breaking down backlogs is knowing how to split up the work from a backlog into right sized pieces.

I’ve already talked about the concept that smaller is better, but I we haven’t really addressed the decision of how to actually divide a backlog up to make it smaller.

slice

The default path

Most developers trying to break down a backlog into smaller chunks will automatically head down the path of using a “horizontal slice.”

horizontal

This is how we tend to think.

What do I mean by a horizontal slice?

A horizontal slice is basically a slice through the feature or backlog that horizontally divides up the architecture.

Most things are built this way.

If you were to build a house, you would probably start by slicing up the project horizontally.

You would first pour the foundation.  Then put up the walls.  Then put on the roof and many more steps, leaving the finishing work for last.

This same thinking usually gets applied to breaking up backlogs in Agile development.

It would seem pretty silly to build a house where you finished one room completely at a time.

Agile software development is different

There is a distinct difference though, between developing software in an Agile way and building a house.

The big difference is that in Agile software development, true Agile development, you don’t know exactly what you are going to build until you are done building it.

With a house this is rarely the case.

With a house, you have some blueprints that you have drawn up ahead of time.  You know exactly where each wall will be and where each outlet will be.  You may have even built houses before that are very similar.

When building software, unless you are taking a waterfall approach and planning everything upfront, you don’t know what you are really building until you are done.

Before you object to this statement, consider this:

This is the point of Agile development.

Agile means responding to change.

Building a house, you do not expect the customer to say:

“Hmm, yeah, I don’t really like that wall there.”

“Actually, I am thinking we are going to need 5 bedrooms now.”

In software development, you are expecting statements analogous to the above!

So what is vertical slicing?

Simply put, building one room at a time.

But it’s not functional!  Who wants a house one room at a time?!?

Correct! It is not functional as a house, but we can pour more foundation, change how we are going to do the rest of the rooms and even knock down the walls and start over without incurring a huge cost.

The point in building our software “one room at a time,” is that we are giving the customer a chance to see the product as it is being built in a way that matters to them and enables them to test it out.

Sure they aren’t going to be able to live in it until it is all done.  But, they will have the ability to step into a room and envision it with all their furniture in there.

Customers don’t care about foundations and framed in walls.  As a developer, you might be able to look at some foundation and framed in walls and envision what the house will look like, but the customer can’t and worse yet, it can’t be tested.

Vertical slicing in software development is taking a backlog that might have some database component, some business logic and a user interface and breaking it down into small stepwise progressions where each step cuts through every slice.

The idea is that instead of breaking a backlog up into the following:

  • Implement the database layer for A, B and C
  • Implement the business logic layer for A, B and C
  • Implement the user interface for A, B and C

The backlog is broken up into something like:

  • Implement A from end to end
  • Implement B from end to end
  • Implement C from end to end

Sounds easy enough, why the debate?

Because it is NOT easy.

I’m not going to lie to you.  It is MUCH easier to slice up a backlog horizontally.

As developers we tend to think about the horizontal slicing when we plan out the implementation of a backlog.

We tend to want to implement things by building one layer at a time.

Thinking about how to break apart a backlog into vertical slices requires us to step outside the understanding of the code and implementation and instead think about the backlog in small pieces of working functionality.

There is almost always some progression of functionality that can be found for a large backlog.

What I mean by this is that there are almost always smaller steps or evolutions in functionality that can be created in order to produce and end result in software development.

Sometimes the steps that are required to break up a backlog vertically are going to result in a bit of waste.

Sometimes you are going to purposely create a basic user interface that you know you are going to redo parts of as you implement more vertical slices.

This is OK!

It is better to plan small amounts of rework than to build up an entire feature one horizontal slice at a time and have to rework huge parts of the feature that weren’t planned for.

So what is the benefit?

You might be thinking to yourself that this sounds like more work without much benefit.  So why would I bother to break up a backlog vertically?

Is it really that important?

I’ve already hinted at some of the benefits of slicing things vertically.

The true impetus behind vertical slicing is the very cornerstone of Agile methodology.  It is about delivering working functionality as soon as possible.

We aren’t going to cover the whole reasoning behind this idea in Agile development.  I am assuming that you already subscribe to the idea that delivering working functionality as soon as possible is important and valuable.

Based on that premise alone, you can see that horizontal slicing is in direct violation to one of Agile methodology’s core tenants.

It is interesting to me how many people are huge proponents of breaking entire systems up into functional pieces that are delivered one piece at a time, but are so opposed to doing it at the micro scale when dealing with individual backlog items.

If you are opposed to what I am saying about vertical slicing, you really have to ask yourself whether or not you truly subscribe to the same idea applied at the larger level, because there really isn’t a difference.

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code.  Also, you can follow me on twitter here

Posted by: jsonmez | November 6, 2011

Teaching is Simplifying

I’ve been doing quite a bit of teaching lately.

I really enjoy it, but it is not always easy.  Many people have asked me what I think makes someone effective at teaching and I have given it quite a bit of thought.

I don’t think there is one simple answer to this question, so I’ll try and approach it from one perspective – the way I view it.

Programmers teach the computer

If you are a programmer, you are already a good teacher.  You just may not know it yet.

When you are writing code you are basically teaching the computer different algorithms.  Of course the computer never really learns what you are trying to teach it, but the process of teaching to humans is very similar.

Think about the steps to write some code.  We usually have to start by fully understanding a problem or algorithm we are trying to solve.  We can’t teach the computer to solve the problem if we don’t understand it ourselves.

Then we have to take this big problem and break it down into bite-size chunks.  We take each chunk and we translate that chunk into the language the computer understands.

Teaching effectively to humans is very much the same process.

When I am preparing for a course I am doing, I spend a good deal of time first making sure that I have researched the topic and understand it well myself.

I may read a few books, play with some code, implement a project or whatever it takes to get a very good grasp of the subject matter.

After I feel like I have enough knowledge to talk about a subject, I spend some time breaking down that topic into smaller pieces that need to be understood or digested in order to understand the whole.

The final step is to take those bite-size chunks of knowledge and translate it into the language of the students or target audience. 

You always have to know who you are targeting when you are trying to teach something.  Sometimes you can target multiple audiences, but you have to know who you are trying to target so you can know what language to translate the subject matter into.

Translating to your audience

One method I frequently use to translate my message to an audience is the analogy.  I find that if you can take a thing that someone already understands well and map it to some concept you are trying to convey, you can accomplish the task with much less effort and a much higher chance of success.

As humans we tend to always relate new things to things we know.  It seems to be a built in process of how we learn.  Whenever I am teaching a subject and someone makes a statement like:

“Ah, I see so it’s just like this _______”

Then I know that they are grasping what I am trying to convey, because their mind is mapping the unfamiliar to the familiar.

I usually try to find an analogy that can map in some way to what I am trying to teach.  It doesn’t even have to be an exact match.

For an analogy to be effective, you just have to take some concept you are trying to convey and map it to one or more aspects of some other thing that is well known.

Analogies are kind of like Velcro.  The two velcro surfaces don’t have to match up exactly, but as long as there are enough “hooks” matched to the “fuzzies,” it’ll stick.

michael

It is all about simplification

The most important thing when teaching is to take something that is complex and to simplify it down.  Part of that simplification process is breaking things down into bite-size chunks.  Part of it is to translate it into your audiences language.  Analogies can go a long way to help you accomplish both.

Ultimately though, you are just trying to take something that might be difficult to understand and make it into something that is easy to understand.  A large amount of what I do is repackaging.

I’m pretty good at reading technical books and sitting down with problems and working them out.  I enjoy that kind of thing.  Many people aren’t or prefer not to take the time to do it.

My job as a teacher is to take those forms of learning that are complicated (reading boring technical books, hunting through APIs, trial and error, etc.) and repackage them into something that is much more simple.

Often the real world has all the information out there that we want to know, but it is not packaged in a way that is easy for us to consume.

A good teacher can take a bunch of hard to peel fruits with pits and stems and skin them, chop them up and make a fruit salad you can eat with a fork.

By the way, I just got my Java Fundamentals course published on Pluralsight!  Check it out if you are interested in learning Java.

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter here.

Posted by: jsonmez | October 30, 2011

MonoTouch

I’ve been so busy lately that I have neglected to write about a great platform for developing iOS applications called “MonoTouch.”

I recently released a new course on MonoTouch at Pluralsight.

I wanted to take a bit of time here to talk about MonoTouch and to tell you why you should be using it instead of developing iOS applications in Objective-C

text-monotouch

Flipping directions

GoPhoto_0197_Scanned-Image-00363

When I first started developing with iOS, I firmly believed that the job should be done using the tools that Apple provided.

I still think it is a very good idea to learn Objective-C and how to develop an iOS application using Objective-C and XCode.

But I am convinced now that overall MonoTouch is the way to go.

Objective-C is a decent language, but it has a fairly steep learning curve for a C# or Java developer.  XCode, the IDE for developing iOS applications, is a decent IDE, but it is not nearly as powerful as MonoDevelop or Visual Studio.

The reality of the situation is that Apple’s development platform is still back in 1990.  Even though there have been some changes and growth, I firmly believe now that Objective-C and the underlying technology cannot ever catch up to .NET or Java.

I don’t say this lightly.  As I said, before I developed a fairly large application in Objective-C.  I authored a Pluralsight course on iOS development with Objective-C.  I was pretty convinced this was the way to go until I gave MonoTouch a try.

An unfair test

I really gave MonoTouch an unfair test, but it passed anyway.  I set out to learn, configure, build a MonoTouch application, and deploy it to the Apple App Store in 1 weekend.

I figured if MonoTouch could pass this test then I would immediately save more than the $400 cost for the software since the next application I was going to build was going to probably take at least a week worth of time to build in Objective-C.

MonoTouch easily passed my test and really exceeded my expectations.

The main advantage

By and far the main advantage in using MonoTouch is the language.

C#’s ability to wire up events through event handlers and delegates makes working with iOS so much easier.

There are many situations in iOS where you have to create a special class to act as a delegate for providing behavior for various iOS controls and classes.  In C#, many of these delegate classes can be replaced by a C# delegate or lambda expression.

Another really painful situation in Objective-C is memory management.  If you aren’t used to tracking memory usage it takes a bit to get adjusted to it in Objective-C.  Sure, it really isn’t that hard, but once I started working with C# to build my iOS application, I realized how much faster I could fly through the code without having to even think about it.  (The newer version of Objective-C has somewhat built in memory management, but it is not a true garbage collection implementation.)

Along with C#, you get the full power of the .NET framework.  Almost all of the base class libraries from .NET are available in MonoTouch.  (You basically have the silverlight .NET profile.)

This really comes in handy in 3 main areas:

  • Working with XML
  • Working with databases
  • Calling web services

If you try to do these things in Objective-C, it is possible, but it will hurt like hell.

Give it a shot

If you are interested in developing iOS applications and you haven’t tried MonoTouch, go give it a try.  Trust me, it is worth the effort.  One of the big factors that had me developing Android applications and shying away from iOS was the hurdle of trying to learn and work with Objective-C.

MonoTouch lets you reuse your C# skills without any extra overhead, since the application is compiled down to native ARM assembly code.

If you don’t know where to get started or want to learn a little bit more about MonoTouch, feel free to check out my course on Pluralsight.

Kudos to the Xamarin team for building such a great product!

(BTW, that photo is me flipping.  Actually it is a thing I used to call “throwing myself at the ground for dramatic effect.”)

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter here.
Posted by: jsonmez | September 25, 2011

Even Backlogs Need Grooming

Imagine this common scenario if you will.

One of your friends calls you up and says:

“Hey, would you mind helping me move on Saturday, I am getting 4 or 5 people together and we are going to move my stuff to my new house?”

You of course reply:

“Sure I can help, what time do you want me to be there?”

“We are starting at 10:00 AM sharp!”

You might have guessed what is going to happen next.  You show up at your friends house expecting that everything is nicely packed in boxes and that you are just going to move some boxes and furniture into a U-Haul, but instead what you see is this:

messy

Seriously?

He couldn’t have cleaned up the house and at least put the stuff in boxes before having 5 people show up at his house to move stuff?

So what should have been a 2 hour jobs turns into a 2 day ordeal as you and 4 other friends sit around waiting for moving friend to pack up his stuff so that you can put it in the truck.

All 5 of you can’t actually help with the packing of stuff and the throwing out of garbage because there is only one person who knows what is trash and what things need to go in what boxes.

If your friend would have cleaned up the trash and packed up everything in boxes before he had the 5 of you come over and help, things would have gone much much faster!

Your backlog list is your apartment

The same kind of thing happens when you call up 5 of your developer and QA
”buddies” and ask them to get some work done for a sprint.

If the team is trying to sort out what needs to be done, what is trash, and what things need to go in what boxes, they are going to be much slower at actually getting the work done.

You see, your list of un-groomed backlogs is not unlike a hobo.  Often times it could use a good wash and a proper shave.

hobo

When I am talking about backlog grooming here, I am not even talking about having a planning meeting, where you plan what you will do next.

Angela Druckman has a good description of a Grooming Session.

The idea is that periodically you groom the top x% of your backlogs so that they are in nice clean boxes ready to be worked on when the team picks them up.

The important thing here is that this is a team activity, everyone should be involved with backlog grooming.  The business really owns the backlogs in most cases though, so they should be directing the team as to which things go in which boxes so to speak.

What about just in time backlog grooming?

Why work on a backlog until the very last responsible minute?

Good question.

For the answer I point you back to the moving scenario I started this post with.

The reason why it is so inefficient for your friend to have everyone come over and try to move him before he has packed up everything and gotten rid of the trash is that you end up having a large amount of idle time waiting on one person.

Think about when happens when a team of 8 developers starts working on backlogs for an iteration at the same time.

If all of the backlogs are not “groomed”, but instead are a scattered mess of mismatched sizes and parts, each developer is going to have to talk to perhaps the same business person about the backlog that developer is working on.

What happens when this business person is out of the office?

What happens when this business person is trying to field questions from 8 developers?

What happens when there is a turn around time to get back to the developers on questions about the backlog?

Now contrast this with the scenario where all the backlogs that are going to be worked on in an iteration are nicely packaged in neat little boxes.

The backlogs may not contain all the technical details of what is going to be implemented, but they are broken down to small bite size pieces that are fairly well understood by the team.

In this scenario the team is going to be able to pick up the backlogs and start going to work.  Sure they will still have to ask the business questions about the backlog, but the kind of questions being asked change fundamentally.

Contrast this kind of question:

So what exactly is this backlog about?  What kind of things do we want to build to report on this data?

To this kind of question:

As we discussed previously and I see in the backlog, we are creating a custom report for this customer.  I also see that we had defined what this column A should do.  Should I be using calculation X or calculation Y to compute this column?

The first kind of question is better answered in a bigger meeting with all the right people.  To answer the first kind of question might require some research.  The first kind of question would hold up the completion of a backlog because it is not easily answered.  It requires thought and perhaps asking other people, talking to the customer, etc.

The 2nd kind of question is specific.  This is something that can be figured out usually by a single person.  Most importantly it does not hold up the work.  Developers can continue implementing parts of a solution and put in the algorithm for computing some value later.

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter here.
Posted by: jsonmez | September 21, 2011

Add APPLY to Your TSQL Tool Belt

Every once in a while I stumble across some SQL keyword that I didn’t really know about, but is extremely useful.

The other day I came across APPLY, or rather CROSS APPLY.

After reading through documentation on how it works and articles about it, I had a bit of trouble understanding it because I couldn’t really find a simple explanation.

criss-cross_1256682

I am going to try to explain it as simply as possible so you can start using it right away.

How CROSS APPLY works

The basic idea behind CROSS APPLY is to allow you to join two sets of data together.

If you understand how INNER JOIN works, you already understand CROSS APPLY.

The only difference is CROSS APPLY also allows you to join in a set of data in which that set of data is created or dependent on each row in the first set.

So basically what that means is that for a normal join you would, for example, join two tables that shared a common key.

I could join my customer table to my orders table to see all the orders for a particular customer like so:

SELECT *
FROM
 orders o
 JOIN customers c
 	ON o.customerid = c.customerid
WHERE
 c.companyname = 'Around the Horn'

Notice how the join is operating on a key that exists independently in each table.

We could rewrite this to be exactly the same using the CROSS APPLY syntax instead like so:

SELECT *
FROM
  orders o
  CROSS APPLY (
    SELECT *  FROM
	   customers c
    WHERE
	   o.customerid = c.customerid) AS c
WHERE
  c.companyname = 'Around the Horn'

We can prove these results sets are exactly the same by using EXCEPT to make sure there are no rows in one set that aren’t in the other and then flipping it, like so:

SELECT *
FROM
    orders o
    CROSS APPLY (SELECT *
                 FROM
                     customers c
                 WHERE
                     o.customerid = c.customerid) AS c
WHERE
    c.companyname = 'Around the Horn'

EXCEPT
SELECT *
FROM
    orders o
    JOIN customers c
        ON o.customerid = c.customerid
WHERE
    c.companyname = 'Around the Horn'

Just run this exact query again swapping the SQL above the EXCEPT with the SQL below and make sure it has no results as well.  If both of those queries have no results, then you know the results from each query are the same since EXCEPT will show any results that are in the top query but not in the bottom one.

So when is CROSS APPLY useful?

Remember how I said it can do more than a simple join?  Joins are restricted to only joining two sets of data that could be queries independently of each other.

What if I said give me the three most recent orders for each customer?

Take a minute and think about how you would write that query.  Go ahead and try to do it.  I’ll wait.

There are a few ways to do it without using CROSS APPLY, but none of them are really very easy or perform very well.

Using CROSS APPLY it is simple though:

SELECT *
FROM
    customers c
    CROSS APPLY (
                 SELECT TOP 3 o.orderdate
                            , o.shipcity
                 FROM
                     orders o
                 WHERE
                     o.customerid = c.customerId
order by o.orderdate desc
) as top3;

So CROSS APPLY is useful whenever you have some data that you would want to be able to join against, but are forced to do some kind of sub-query instead because the data you are trying to join is not going to map well against a single key.

The other instance in which CROSS APPLY will be useful is when you are  doing a sub-select that has more than one value you would like to use in your final query.

For example if you were sub-selecting from an Order Details table to match up order ids that had a Quantity greater than 5, that sub-select would need to return exactly one column in order for you to use it in your where clause.  If you wanted to use other columns from the sub-select, you would have to do another sub-select for each of these columns.

If you first try to rewrite the sub-select as a JOIN and find that you can’t, you may be able to write it as a CROSS APPLY.

How to know when to use CROSS APPLY

There isn’t a good solid rule you can use to identify when you should use a CROSS APPLY but having the knowledge of CROSS APPLY and how it works can help you when you are trying to tune queries and you are having a difficult time constructing one.  It is another option you can try.

Here are some general guidelines of times when you might want to use CROSS APPLY:

  • A query where the result set you want to JOIN against is in some way related to the data in the first set.  (Example: one column in the first table tells you how many rows in the 2nd table to get)
  • A query where you are doing a sub-query, but need more than one value from the sub-query
  • Anywhere you are using a Common Table Expression (CTE) could possibly be rewritten as a CROSS APPLY
  • A query that has a large set of data it is joining against and then filtering out.  You can change it to a CROSS APPLY that does the filter in the CROSS APPLY statement.
  • Any time you are trying to join against a table function (this is actually what CROSS APPLY was created for.)

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter here.

Posted by: jsonmez | September 19, 2011

Goal Setting and Routines

I’m back finally! After moving across the country.

I moved from Boise, Idaho to Wesley Chapel, Florida.  One of the main reasons I have been quiet lately has to do with the subject of this post.

goal

About goals

I have heard many people talk about settings goals.  Setting goals is very important, but goals themselves do not ensure success.

Goals give us a way to measure and define success, but not to actually achieve it.

We do have to start with good goals, so let’s talk about what a good goal is.

A good goal is like good done criteria for a backlog.  A good goal is one that is:

  • Measurable
  • Has a time constraint
  • Achievable without being overwhelming
  • Sufficiently broken down, (it is a single thing, not a collection of things.)

If you don’t define a good goal, the chances of achieving it go down drastically.  If your goal is not clear cut enough, you may not even be able to tell when it is achieved.

In my world, good goals are things like:

  • By Dec 10th I will lose 20 pounds.
  • I will read one technical book each month.
  • I will create and launch an iPhone application by Nov 15th.

Bad goals are things like:

  • I will improve my diet
  • I will start lifting weights
  • I will improve my SQL skills

Goals aren’t enough

Once you have good goals, you should be good to go right?

Wrong!

How many times have you set good goals that you never achieved?  Always something seems to come up, or the timing isn’t right, etc.

The problem is, life happens.  You have to deal with all kinds of issues you can’t predict, so you don’t end up having the time to achieve your goals.

You usually don’t have anything on the line, so nothing is forcing you to complete the goals.

First let’s talk about the issue of life happening and disrupting you from achieving your goals.

There is a simple solution for this problem…

Make your goals part of your life.  Rarely does life happen to me in such a way that it prevents me from doing things like showering, eating, brushing my teeth or going to work.  (I suppose now that I am down in Florida, a hurricane could happen and cause all that.)  In general though, we operate as humans best on routines.

I have found time and time again that the key to achieving goals is to build them into your daily routine.  Having a routine is critical to being successful.

Don’t believe me?  Think about the biggest losers you know in your life.  You know who I am talking about, that friend from high school that still doesn’t have a real job, sometimes sleeps on your couch, wakes up at noon, etc.

Routine or no routine?

Now think about the most successful people you know.

Routine or no routine?

Routine disruption

Part of the reason my posts stopped for the last few weeks is that I had my routine disrupted.  Back in Idaho before I moved, I had a pretty solid routine, it went something like this:

Every week day: Egg white + Spinach breakfast, Spinach + light soup lunch, Steamed Chicken + vegetable dinner, read 15-30 minutes technical book.

Monday: Lift chest and biceps, do prep work for Pluralsight, cook up chicken for the rest of the week

Tuesday: Run 5k, record for Pluralsight

Wednesday: Lift back and legs, do Android or iPhone app work

Thursday: Run 5k, prep work for Pluralsight

Friday: Lift shoulders and triceps

Saturday: Run 5k, record for Pluralsight and or do Android or iPhone work

Sunday: Write blog post for the week

That was my basic routine.  You can probably figure out my goals just by looking at my routine.

When I moved, this got disrupted, but I am getting back into a routine similar to this one again.  Once a good routine is established, life happens around your routine.

I usually stick with this basic routine and modify it based on the priorities of my goals.  At different points, blogging was a higher priority, so it took up a few more slots.  When I was really focused on getting my Android app done, that took more slots.

When you have a routine, you are making small steps on a regular basis towards your goals.

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter here.
Posted by: jsonmez | August 15, 2011

Inversion of Control Course Published on Pluralsight

Just published my 4th course for Pluralsight, Inversion of Control.

image

I was pretty excited to get the opportunity to do this course, because there is a large amount of misunderstanding out there about:

  • Inversion of Control
  • Dependency Injection
  • Dependency Inversion Principle
  • Inversion of Control Containers

I cover each of these topics in this course and then we even build our own IoC container.

If you liked the Back to Basics series, you’ll like this course.  I go and dive a pretty deep into the real meat of the patterns and principles behind IoC containers.  Then I cover using Unity and Castle Windsor.

I think it is pretty important that we understand clearly why we are using a particular technology or pattern and what problem it is trying to solve.

I see too many people jumping on the bandwagon of so many popular technologies without really taking the time to learn the background about the technology to understand why it is an effective solution to a problem and what problems it attempts to address.

As always I welcome any feedback or suggestions for future courses.

I’ve written before on the idea of refactoring a switch to a Map or Dictionary.

There is one major problem that I have been running into though.  Switch statements and dictionaries are not functionally equivalent for one major reason…

Switches allow for default

I kept struggling with this when I would implement a dictionary to replace a switch.  How can I deal with the default case?

There are of course many ways to deal with the default case in a dictionary or map, but I didn’t really like any of the solutions because they either required me to remember to check to see if my entry was in the dictionary before looking it up, or to rely on catching an exception.

Let me give you an example:

switch(vegetables)
{
	case Vegetables.Carrot:
		DoCarrotStuff();
		break;

	case Vegetables.Spinach:
		EatIt();
		break;

	case Vegetables.Peas:
		FeedToDog();
		break;

	default:
		Butter();
		Salt();
		SprinkleCheese();
		Eat();
}

Converting this to a dictionary we get something like:

var vegetableActionMap = new Dictionary<Vegetable, Action>
{
	{ Vegetable.Carrot, () => DoCarrotStuff() },
	{ Vegetable.Spinach, () => EatIt() },
	{ Vegetable.Peas, () => FeedToDog() }
}

Action result;
if(!vegetableActionMap.TryGetValue(vegetable, out result)
{
     Butter();
	  Salt();
     SprinkleCheese();
     Eat();
}
else
   result();

So clunky, just to handle the default case.

Would be much better do something like this:

var vegetableActionMap = new Dictionary<Vegetable, Action>
{
	{ Vegetable.Carrot, () => DoCarrotStuff() },
	{ Vegetable.Spinach, () => EatIt() },
	{ Vegetable.Peas, () => FeedToDog() }
}.WithDefaultValue( () => { Butter(); Salt(); SprinkleCheese(); Eat(); });

vegetableActionMap[vegetable]();

Well now you can!

Enter DefaultableDictionary!

Also the first thing I ever put on GitHub!

The idea is pretty simple, I am just creating a decorator for IDictionary.

The DefaultableDictionary has a constructor that takes an IDictionary and a default value.

It then delegates all of the methods to the passed in IDictionary reference.  For the methods that look up a value, it handles returning the default if the key doesn’t exist in the dictionary.

I created an extension method that lets you just put a .WithDefaultValue() on the end of your dictionary declaration in order to auto-magically give you a DefaultableDictionary back with that default value.

Sleep well my friend

Knowing that you can not create a dictionary that has a default value which is returned instead of throwing an exception if the key passed in is not found.

I have no doubt that in 3rd world countries children are still starving, but in 1st world countries children with VS Express hacking away at iPhone applications using MonoTouch will not have to catch exceptions from dictionaries that do not know how to just return a default value.

So now there is no excuse!  Refactor those switches!

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter here.
Posted by: jsonmez | August 8, 2011

How to Break Down a Backlog

The process of breaking down a backlog is one of the most important steps in any Agile process.

I have found over the years that the better a backlog is broken down the smoother the implementation of that backlog is.

I have found that the single greatest influencer in the success or failure of a backlog is the process of breaking it down.

What does it mean to break down a backlog?

Before we can really discuss how to break down a backlog it is worth taking a minute to discuss what I mean by breaking down a backlog.

If you are following some kind of Agile process, you probably have a story board.  On that story board you probably have a swim lane dedicated to a step that is just before the development of the backlog is ready to begin.

The process of breaking down a backlog is moving a backlog from the state of selected for implementation to that state of ready for implementation.

Different teams indicate this transition in different ways, but most teams have some way of indicating that a backlog is ready to be worked on.

So when I talk about breaking down a backlog, I mean the process of moving a backlog into a state where it is ready to be developed.

Why break down a backlog?

So why do we want to do this thing?  Why don’t we simply pick up a backlog and start developing it?

The main reason we take the time to break down a backlog is because we adhere to the old philosophy of measuring twice and cutting once.

The process of breaking down a backlog is the process of thinking ahead to lay out a path which we can follow to the successful completion of a backlog.

By skipping this crucial step, we almost inevitably set ourselves up for failure.

Not breaking down a backlog to me is like going on a week long camping trip by taking with you everything you happen to have in your car rather than carefully planning out what you’ll need.

Packing the right gear

Now that we have talked about what breaking down a backlog is and why we should do it, let’s talk about the steps that are involved.

Step 1: Review the backlog as it is

In this step our goal is to understand the backlog and evaluate the kinds of questions that we will need to ask about the backlog and the areas of code that will likely be affected by the implementation of the backlog.

We will want to carefully read the backlog and try to understand the basic idea of what is being asked for.

We want to look for any kind of trouble areas that either indicate what is being asked for will not be possible, or that it will require significant architectural changes to the existing system or paradigm.

We also want to look for indications that a backlog might be too large and actually might be a fatlog that will need to be broken down into smaller backlogs.

Step 2: Pre-review the affected area of code

After we have gotten enough of a gist of what the backlog entails we should have an idea of the area of code involved.

It is important to take a look at the area of code that is going to likely be affected by the implementation of the backlog so that we know what we are getting ourselves into.

Nothing it worse than thinking something is going to be easy to implement then actually looking at the code and finding out that it is a total mess that has to be cleaned up before anything can be done with it.

Our goal here is not to solve the problem or even to outline the solution.  We just want to have enough education about the affected code to be able to have a conversation with the business about what will need to be done to implement this backlog.

Step 3: Initial discussion with the business and QA

Armed with an understanding of the basic idea of the backlog and the areas of code that are likely to be affected, we are ready to talk to the business and QA about the backlog.

The goal here is to fully understand what is going to be implemented and what the goal of the backlog is.

We have QA here so that both the development team and QA get the same understanding of the backlog at the same time.  We don’t want QA or the development team dictating what they think the backlog means.  If it is at all possible, it is important to get someone responsible for the backlog from the business to tell both parties exactly what they want.

Step 4: Define skeleton tests

Before we leave the initial discussion about the backlog, we want to come away with an initial skeleton of tests that everyone has agreed upon.

This is a very important step that is often ignored, because often teams think that QA will just go off and write some tests.

It is important to make sure that everyone, including developers and the business, has agreed to the general tests that are going to be used to qualify the backlog as done.

Without knowing exactly what criteria will be used to judge the completion of a backlog and agreeing to it up front, you may be committing yourself to whatever the whims of either QA or the business are at any given time.

Defining skeletons tests help to define scope.

It doesn’t mean that requirements and details can’t change, but it does mean that the current set of requirements and criteria is well enough understood for development to begin.

I often call the skeleton tests “done criteria.”

At times I have actually reworded a backlog to explicitly state the done criteria that has been agreed upon after this meeting.

Something similar to

This backlog is done when:

  1. I can create a new user
  2. I can see that the new user exists from the admin tool
  3. The creation of the new user is audited and specifies details about the creation of the user.

Step 5: Task out the backlog

If you can’t task out a backlog, you don’t clearly understand what you need to do to accomplish the goal.

Tasking out the backlog is the process of breaking down and identifying the steps required to implement the backlog.

I often try to make done criteria be in the form of business language and tasks be in the form of implementation details.

Tasking out a backlog can be a cumbersome process, but it is akin to mapping out a trip before and carefully packing your supplies before heading out on the road.

When I am tasking out a backlog, I try to think of each sequential step that is required in order to completely implement the backlog.

Part of this process often involves the actual design of the solution, because without some kind of design it is often difficult to create a series of steps to get to the end goal.

This is one of the reasons why I see tasking as so important, it ensures proper upfront design. Many Agile teams think that Agile means no upfront design.  This simply is not true.  Agile means that we don’t upfront design the whole system, but we should always try to design something to some degree before we implement it.  Especially in a complex system.

Tasking also helps to split the backlog up into workable pieces that can be worked on by different members of the team either jointly or in isolation.  It is very difficult to coordinate work on a single backlog item when it isn’t properly tasked out.

I often like to define done criteria for each task in order to make sure that anyone picking up a given task will understand when it is complete.

One thing to watch out for is whether certain tasks are sequential or if they can be done in parallel.  When possible, dividing up a backlog into parallel tasks is preferred, but many times tasks must be sequentially implemented.

Ready, set, GO!

Following these steps might seem a bit cumbersome to your development process, but I can assure you that if you take the time to implement this process you will not regret it.

Taking the time up front to clearly define the work that is going to be done on a backlog can save huge amounts of time that can be wasted reworking a solution that hasn’t been thought out clearly.

Here is a short recap of the steps for breaking down a backlog:

  1. Review the backlog
  2. Review the code affected by the backlog
  3. Discuss with the business and QA
  4. Define skeleton tests and / or done criteria
  5. Task out the backlog

I would love to hear any success stories or issues your team has trying these steps out.

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter here.

Older Posts »

Categories

Follow

Get every new post delivered to your Inbox.

Join 406 other followers