lördag 28 april 2012

SharePoint, TDD, code monkeys and Agile

I have been reading Eric Shupps (albeit old) thoughts on the matter of SharePoint and TDD as well as Andrew Woodwards series of articles about the subject. Thought I would share a few words on the subject since I find it truly fascinating.

First up though. There is a difference between unit testing and TDD. I don't subscribe do a single school or train of thought about TDD. In my head TDD is a way to use unit testing to achieve greater results then by writing tests to validate code already written. TDD can drive design, test should be written and fail before code is written. Unless you are doing exploratory coding (ie when you are not sure what the test case is. It's a good point to try and think more about what you are doing before diving into the code since this can lead you down a pretty deep rabbit hole).

While Eric gives a good summary of what he means with TDD and where it stems from I have a few issues that popped into my mind while reading his article that I want to study in more depth.

Pair programming

First a few notes about pair programming (which doesn't really have a 1:1 mapping to TDD but is still an interesting topic).

In the blog post mentioned above he quickly concludes the following regarding pair programming:

"First of all, companies quickly discovered that pair-programming is a tremendously inefficient process." [...] "putting two of them [developers] on the same coding task is rarely cost-effective".

And then he ends with:

"Finally, it has been my personal experience that two coders working side-by-side tend to engage in more discussion about how things should be done in a perfect world than they do actually writing any code. They are by their nature perfectionists, and each always wants to prove that they have the best and most innovative ideas."

I was a bit sad to not see any references to these claims beyond his own experiences, in general I find that it's quite hard to find any sources at all on the subject. 

The way that the Eric poses the problem it is more a problem of communication and ego, not the pair programming paradigm in my humble opinion. Angela Harms has done a really great talk about this subject at the Ruby Midwest conference as well as an appearance on the Ruby Rogues podcast

If I attempt to summarize her words bluntly she says that for pair programming to function you need to check your ego at the door. The process is not about finding the perfect solution, it's about figuring out how to move forward and combining brainpower. Being able to admit that you don't understand what is going on and that you don't know everything is step one in this process. The real point of pair programming and Agile in general is to bring problems to the surface early. If noone is admitting that the problems exists, you can't do anything about it.

Another great resource that should is the talk from Agile Roots named What We Learned in 8829 Hours of Pair Programming.

TDD Zealotry

"Developers who become adherents to the new programming religion of the moment quickly slip into the fatal trap of assuming, despite all evidence to the contrary, that their methodology makes the code they create bulletproof"

This is true and also the main point of Eric's post. A lot of my writing below could be considered nitpicking, but I like to see it more as a way to show what I object to.

"You can see this in action by listening to any TDD adherent as they bandy about phrases like "100% code coverage", "atomic validation", "no debugging" and other such phrases designed to reinforce their own misguided sense of infallibility."

In my humble opinion code coverage is not and should not be an end goal. 100 % code coverage can even be a bad thing. It's interesting thought, the whole time I was reading Eric's article I couldn't stop thinking about how different our views on TDD and it's evangelists is. Perhaps this has something to do with that I got into TDD from the ruby/rails community where TDD/BDD is the norm and the debate is around the concept of TDD and how it should be applied. In my mind there is no one true way of doing TDD.

It's perhaps fitting that the greatest battle is fought inside the ranks of the same militia? (Follow the link-trail around DHH's "Testing like the TSA" article to see what I mean).

"It is vitally important to emphasize that unit testing is only one part of the overall quality assurance lifecycle."

This actually neatly summarizes the whole argument.

Quality and the process of software development

Eric then goes on to reason about unit tests in relation to functional requirements and that writing the minimum amount of code is what give us unpredictable bugs among other things that I found hard to see the reasoning behind. But then he states that: 

"I'm sorry to point out this blatantly obvious fact but developers don't really know squat about quality and even less about how to achieve it."

This made me very upset, not at Eric but at the state of the developer in the world as seen from the eyes of some non-developers. The notion of developers as code monkeys that only care about solving the immediate problem at hand, system or users be damned always upsets me. If your developers have this approach to writing software, everything Eric is talking about up to this point is true and makes sense (although it's not related to the TDD practice).

Granted, there are lots of developers in the world who sees it as a job and nothing more. But why shouldn't developers care about quality? Do we not want developers who care about quality? The customers problem we are solving? The value we are bringing to the customers business? Why would we not want to promote something that makes developers think about these questions?

Interestingly enough this is the point he is actually arguing in the article. The way we are working is broken, the way we conduct software engineering is broken. But somehow he manages to wrestle this into an argument that unit testing only proves that an individual part work but not that it will work as a part of a holistic system. True, this is not what unit tests are about, this is functional and integration testing.

TDD, more than code and unit tests

The thing about TDD is this, it provides more value then just testing the individual parts. The tests that come out of the process are a great compliment to documentation. Especially if the TDD practice of red, green, refactor has been implemented.

Imagine having a test suite with passing tests, when you change something you can see if the unit still works as intended, even after the code has been changed. As long as we have passing tests we have documentation that actually represents the current snapshot of the system. This is what allows TDD to drive design, when we decouple and abstract things we can be confident that the unit still behaves as intended. This only holds true if the unit tests actually test our logic, not just snippets here and there.

Tests are a great supplement to documentation, if the documentation is out of date we can check the tests to see how it differs, or if we read the tests first the documentation will make more sense since we can see what approach the developer who wrote the code took to the problem.

Real testers are great for really bringing the wrath of god (synonym to putting the system in the hands of a user) upon our system. But what do testers really know about the details of the code? Why should they care? Other developers care about what other developers have done.

Understanding how the system works as a whole is crucial to the successful launch of a system. Although I don't see anyone arguing otherwise.

It's also worth noting that while TDD does drive a certain style of design (that can go overboard just as Eric talks about) it's always up to developers/architects to be pragmatic and ensure that the design still has a point and brings value. 

Agile, not just a word

Eric do strike a good point that I would like to expand somewhat on (this is where I go on a side-track):

"TDD assumes that everyone in the development lifecycle both understands and is willing to assume the overhead of enforcing the restrictions of the methodology"

The key words in this quote is understands and is willing. Can you see where I am going with this?

It is my firm belief that Agile in general wont work when people don't care or understand. When you don't care you are not going to put in more effort then you have to to keep your job. When you don't understand you rely on someone guiding you and telling you exactly what to do.

Of course pair programming, TDD or Agile in wont work when you don't have the people you need. Agile does not work in an 18:th century coal mine or the corporation where you have to sign a sheet of paper to go the bathroom.

I also object to the general thinking that we should only meet the required functional requirements. This kind of thinking assumes that the software development life-cycle is based around:
Order it from company X -> Create it -> Launch it -> Use it -> Throw it away -> Repeat with company Y, return to X when everyone has forgotten what they did last time.

The process should be:
Need it -> Think about it -> Build the minimum that you need -> Use it -> Think about it -> Build the next minimum you need -> Think about it

Testing SharePoint

Back to the point at hand.

Here I present a few simple rules for using TDD or even straight up unit testing within a SharePoint project:
  1. Don't over-test the SharePoint API, test your logic

    Don't test the retrieval of SPListItems from the Contracts list. Extract into ContractItem's and test those. Focus on core logic and have faith that Microsoft has tested it's internal API's. Mock where needed, not everywhere.
  2. Don't measure code coverage.

    Code coverage is arbitrary and says nothing about what we are testing or why we are testing it.
  3. At least test the happy path.

    If I give this method this input, does it work?
  4. Write enough tests so that you feel comfortable with the code you wrote.

    We do after all think about what is going to happen when we write code, let's put the assumptions into tests. I dare anyone to write a non trivial regexp and know if it works without testing it.
  5. Remember the refactor in Red, green, refactor.

    The first passing test is not a signal to move on to the next piece of code. It's the signal to refactor the code that you just wrote.
The list is quite far from what a purist TDD evangelist would describe. But I am pragmatic, and I think that until better tools are provided that allows us to do true TDD, we should stay in this kind of grey area of TDD.

I also agree with Eric about the fact that TDD isn't a silver bullet to anything, especially not quality. To write good code you have to know how to write good code. You learn how to write good code by writing code and learning from your seniors. This however raises the point that using TDD by itself is pointless unless you take other Agile practices to heart. TDD must be combined with things like code reviews, pair programming and the philosophy of continuous improvement to create good coders.

Talking about TDD without talking about the software philosophy surrounding it is like talking about how to reduce the price of wood without knowing what your building.

Now go read part 2 where Eric clearly has had time to reflect and formulate his points in greater detail.

onsdag 25 april 2012

Agave web extensions

The Microsoft enterprise blog has an article up about Agave web extensions and Office programmability that I took a shine to.

The integration between the Office suite and SharePoint have been missing an easy way for programmers to create solutions that brings the two together. These new shiny rumored objects are interesting.

Lets consider them from the context of the relationship that currently exists between Excel and the SharePoint BI offering. Microsoft could have tried to move people away from Excel to more powerful tools better suited for the purpose of creating business intelligence solutions. But instead they choose to allow people to leverage Excel and PowerPivot as powerful BI self-service solutions where a simple Excel sheet can act as a full fledged datasource. The philosophy of letting people use the tools they are familiar with to provide business value as well as offering more advanced tools that can be used when needed seems to be the underlining strategy going forward.

The new programmability could bring the same mindset into the rest of Microsoft's offering. Extend, don't reinvent.

Further tying SharePoint into the stack as the center of information distribution and collaboration seems like a great strategy, not just for us active in the business, but for the enterprise as well.

torsdag 19 april 2012

Links for 2012-04-19

Writing software architecture documents can be lots of fun. And since we are all good people we try to improve on our process of writing documents continuously right? In the quest for this i stumbled on Simon Browns excellently condensed overview of what he feels should be part of a well structured SAD. Well worth a read.

_____________

Caching is an everlasting problem. Jason Apergis has a nice summary of the SharePoint Server Caches Overview, Advanced details on the SharePoint BLOB, Output, and Object Caches whitepaper up on his blog.

måndag 16 april 2012

Use words to bring change. Or to reinforce the good

Since I always like to read things that agree with what I was already thinking I was pleased to stumble across this post from Michal Pisarek over at sharepointanalysthq. In his article he covers the topic on why it's a bad thing to use the standard "team-site". TL;DR: People don't know what a "team-site" is.

I agree. But let's not stop at these words, let's go one step further.

If I talk to people about what I do I usually tell them I work with SharePoint. Then they (almost always) ask me "Whats that?". Perhaps someday I will learn that SharePoint is a word without meaning if you never used the platform before. What I ought to say is that "I make you find the stuff you need to get stuff done. Like that document you and your colleague was working on last month, or that piece of news from the HR department about the new process for getting your vacation days approved". Thats simple, and most people can relate to what it means.

In the same manner no one of sound mind would come and tell me that they need a SharePoint document library set up to store pictures of products. They would say "We need a replacement for the products gallery". So that means that we should always refer to the new document library as the products gallery to be consistent with the business language, right?

Well not quite.

See, words are powerful things. We imbue them with meaning that goes above and beyond the individual letters. The product gallery might be a place of dread and horror which no one ventures into today due to fear of getting lost or the risk of suffering tremendous amounts of headache.

This is a golden opportunity to use words as a way to bring change. Don't call the new solution the products gallery. Perhaps call it the Inventory Portfolio. This gives employees the chance to associate new experiences with the word, perhaps even positive ones.

Now the same goes for the opposite. If everyone in the business is talking about the CRAD, and everyone knows that when you talk about the CRAD you mean business, don't go changing it to "the team-site".

It will loose it's value.

And yes, I claim that even small things like a document library can have power.

Now engineers usually don't want to care about this. Engineers wants to solve problems and move forward.

But. It is my true belief that even engineers will have to care about words to provide tangible business value in the long run. The days of code-monkeys in the cellar are going away. Now if we need pure, very detailed requirement driven development we outsource it. The only chance we have of providing continuous business value is to know our customers and help them going forwards.

Conclusion:

Words define our world and tools define how we live and work in the world. If we can find a way to make the tools more closely resemble the world, we will have a better chance of getting the people who live there feel more at home in our solutions. After all, it's hard trusting something that doesn't make you feel at home.

söndag 15 april 2012

Links for 2012-04-15

responsive HTML5 masterpage for SharePoint. He also writes other Great stuff on SharePoint design and HTML5.

Next an interesting article with thoughts about the multifaceted roles a SharePoint consultant will/should have to take on during a project. In his words: The BAD Consultant, Business Analyst Developer.

My eternal dismay over XML led me to this interesting project: The Genesis Framework. It promises easier provisioning of things like site columns and content types.

Being a really lazy developer it should come as no shock that I like design patterns. Christoffer von Sabsay has an old article up on his blog talking about the repository pattern, list based configuration storage and the application settings manager under sandboxed solutions. He also has another article about configuration storage options that is well worth the read. Find the oldies but goodies here and here.

And finally a new alternative to CAML that I want to fiddle around with. "Camlex.NET is a new technique in Sharepoint development. It abstracts developers from syntax of CAML queries and helps them to concentrate on business tasks. With Camlex.NET developers could think about WHAT they need to do, instead of HOW to do it"