Tuesday, 8 February 2011

Hmmm– what happened to my brain?

I’ve been reading the excellent “Joel on software” and “More Joel on software” books recently (by Joel Spolsky obviously) – I’ve got to say I wish more people had his insight into what motivates and drives a good developer to work well. I’ve lost count of the number of clients I’ve turned up at to find brow beaten developers sat next to the telesales department staring at postage stamp screens and wondering why their productivity is so low….

Anyway, I’ve got a few things to say about that myself, but I’ll save it for another day, today I’m thinking about some of the stuff Joel talks about with regards to groking pointers and how programming is getting easier, or should I say dumbed down (due to University teaching higher languages such as Java rather than C, C++ or assembly)  and I looked back to where I was in the early ‘90s and realised that I seem to have forgotten a lot since then!

Back then, I remember writing games in my spare time in C/C++ and assembler – I remember knowing about memory segments and offsets, I remember using registers to set source/target memory and moving bytes around, I “got” pointers, I knew about memory allocation, doubly linked lists, and I could write assembly language until it came out of my ears - I even remember using “debug” on the command line to inspect what a game was doing during the license key check at the start up of the game and then changing the op codes from a JE (jump if equal) to a JNE (jump if not equal) so that if you put the wrong key in, it let you play the game (sorry about that, but we’d erm, lost the key, that’s it, lost it).

I even remember myself and a few colleagues (John Steele and David Mort, just in case you’re out there!) having competitions on writing double buffer, screen swapping algorithms that would push the delta from two buffers into VGA video memory (0xA000)– because writing to video memory was so unbearably slow compared to RAM – we would actually sit there, pouring over the assembly listings, counting the iterations and how many clock cycles it would take to refresh a partial or full screen and therefore who’s routine was better. Geek fest, and you know what, I loved it and feel sorry for any developers out there that haven’t had a similar experience.

Anyway - what is my point? Well, I don’t think I have one other than this was a nice trip down memory lane, and I think I might struggle to go back and do that again now. I could do it with my eyes closed back in ‘92 and I had to for a variety of, usually performance, reasons, but because I’ve not had to use that skill in a long time, it’s gotten old and rusty like a neglected banger of a car left in a leaky garage. These days I work at a higher level of abstraction – I work with C# and I build software in that higher level world rather than in the bowels with assembly and whilst there are numerous principles and concepts learned in the past that are still useful, I’ve not needed to drop into assembly for any reason (building LOB apps) in the last, I’m guessing, 10 years.

Is that a good thing? Part of me is happy that building software is easier, but the other part of me feels that those kinds of skills provide an essential grounding to really understanding what is going on under the hood, even if you do spend your days in the .NET C# clouds.

Friday, 4 February 2011

SDLC – agile in the real world – consulting and long complex projects (Iteration 0)

Building software isn’t like building a bridge. This is not new thinking, this is well understood and has been a factor of software development since the 70’s.

When building a bridge someone has a vision that is part creative and part engineering on how the bridge should be built. The engineers then take this vision and run calculations, build models, run stress tests and so on to make sure that the design will stand up in the real world. They then produce a detailed schedule of work on what needs to happen each week to get the bridge built – there is no deviation from the plan, no changing your mind about how the bridge should be implemented and, beyond the initial vision and problem solving – very little creativity.

Building software on the other hand is a creative process. Developers who write code can approach a problem in a number of different ways, some good, some bad, some passable – but all creative, drawn from their bag of experience and knowledge.  Yes, it’s engineering, but I propose it’s also extremely creative.

The case for up-front-design (but not BIG up-front-design)
I’ll even go so far as to argue that planning a bridge is easier than planning software – we already know every little detail about the bridge design up front, we know that design isn’t going to change and we know it will take 4 hours for Dave with a spanner to attach two I beams together, typically it takes 3 hours to weld the plates that make a section, but sometimes that weld is poor, so you build in a contingency factor and so on – easy. (Aside: for any bridge builders out there who just happen to have stumbled on this post, I’m sure it’s really not that easy!)

Planning and managing software development on the other hand – well, I’m an advocate of SCRUM and agile approaches, sure, and that’s a great way to run a project,  but I’m not so sure that it’s a great way to start a project from the beginning. XP would have us diving straight into code, SCRUM we’d already have a backlog to pick some items off ready to start building in iteration 1, so I guess this post is about how that backlog get’s filled to start with – an iteration 0 - just diving headlong into code without first understanding the holistic picture of the app you’re going to build, the pieces that will make up the whole and the general stages you need to go through is a recipe for disaster on a project that lasts say 2 years with 3 workstreams (custom dev, business intelligence and data migration).

Also, I’m a consultant and I generally work with a team of consultants from my company (often with other developers supplied by the client or with an offshore development team) and these people cost money – it’s extremely rare for a client to engage say 4 consultants at £1,000 a day without having some sort of idea of how long we’ll take to deliver and how much it will cost.

So, I’m sorry XP purists, but you can’t escape the fact that we need up front design.

Up-front-design in perspective
I’m not saying we need big thick, 000’s page long manuals with detailed conceptual, logical and physical designs down to sequence diagrams for individual methods, no, but we do need to;

  1. Gain insight into the overall application surface
  2. Identify the pieces of the application – essentially the sub-applications within the whole – we’ll call these domain components.
  3. Flesh the high level use cases/user stories for each domain component.

From this the project can be planned into iterations and roughly estimated – the estimate won’t be 100% but it will be an indication and a yardstick to measure change by. In other words, if the customer during a sprint decides to change tack on part of the application, its quite easy to see that adding that extra work to the next iteration will make something fall off the back end of the project and either not get delivered or will cost more. The exercise of defining the high level project will give you a good idea of how best to structure delivery in iterations and let you populate a backlog so you can see the effect of change and re-plan accordingly during the execution of the build.

Alongside the identification of the big picture, the application architect will also be considering the approach to development – will the user want a rich UI interface, will it be a desktop application, a web based application, maybe SilverLight would be a good idea – should the business logic be distributed and exposed as services – will this application expose itself to other applications – how will we handle workflow – should we surface through a SharePoint portal? - all these things will become clearer as the high level design above is being done, but at the same time, the architect will be making some technical decisions that are based on assumption and are therefore risky for the success of the project – we need a way to mitigate that risk, less we head off in the wrong direction only to find that the assumption was wrong in 10 months and have a lot of re-engineering to do to fix it!

Projects need iterations but they also need phases
All of this indicates what we already know - that projects need phases. They need this start up phase to identify the big picture, estimate the whole and de-risk technical assumptions, but what are the phases of the project from there? Well, if you subscribe to any of the methodologies like RUP, Open/UP, MSF etc, you will already be familiar with project phases – the list below describes the phases of a project how I personally like to work (but I’m not precious or religious about these in any way – call them whatever works for you!).

  1. Inception
    • During this phase you identify the big picture – application surface, domain components and drill into use case titles/user stories
    • You also identify the proposed architecture for the solution
    • Build a proof of concept to start to de-risk some of the technical assumptions
    • Deliver
      • 30,000ft map of the entire application
      • High level use cases
      • Iteration plan
      • Proposed costs and timescales
      • Use case detail, wireframes and specification detail for the first elaboration sprint.
  2. Elaboration
    • This phase we start to work in iterations, using SCRUM to manage those iterations.
      • Each iteration delivers the use case detail (building on the high level headers), lo-fidelity screen wireframes and other pertinent specification detail for the next iteration.
    • De-risk any additional technical risks
    • Build a fully functioning vertical slice through the architecture and problem domain
  3. Construction
    • SCRUM sprints/iterations through the build of the product.
    • Stringent quality control – continuous builds, nightly build released to testing.
    • Continue to provide design detail 1 sprint ahead.
  4. Transition
    • Releasing the product – a release sprint.
      • In some cases you can’t release at the end of each 2-4 week sprint – the application may be too large and what you can build in an iteration too small.
      • Instead each iteration should deliver demoware – a presentation or demo to some of the users.
    • Some applications can be extremely complex involving multiple deployment steps, these should be planned.
  5. Support
    • Handing over to the people responsible for the upkeep of the system.

Next
In future posts I’ll cover some of these phases, how we go about running the inception phase for example, key things to do in workshops with customers, and how best to start the process of identifying the big picture.

To conclude though, I will say this - yes, the above is applicable to larger sized projects. If you’re writing a simple expense tracking application for the sales department or a personal journal application for yourself then yes, go pure agile and start coding. If you’re working in a larger team on a larger project, you’re going to have to put some effort in up front I’m afraid to get the project rolling – you can run the project as SCRUM from then on and get all the juicy benefits from it, whilst also understanding the bigger picture, budget and timescale implications.

Friday, 28 January 2011

Prism, MVVM and Silverlight – Gripping it by the short and curlies – introduction.

Today, and for a few hours yesterday, I found myself “on the bench” for the first time in 4 years – that means I’ve got a little bit of time to brush up on some concepts, write some spikes and equip myself with some new tools before I start another engagement. I figured I’d use this time productively to brush up on the latest incarnations of Silverlight (4) and Prism (4) by trying to build out a sample application.

The question is, what to build? I only have a day or so which means I need it to be simple-ish, but interesting. Well, recently, I’ve been playing with an iPad application called Popplet (links: Website, get it on iTunes) – which is a pretty neat little app that lets you essentially drop post it notes (text or image) onto a canvas, drag them around into some layout that makes sense to you and connect the various boxes. I’ve used it for brainstorming ideas, thinking about application components and how they relate and a bunch of other things.

iPad Screenshot 1

Inspiration? Check! – this kind of application covers a bunch of things that I’d like to cover off with this exercise;

  • Expressing a reasonably complex model.
  • Visualising that model
  • Data templates or components for the notes.
  • Best way to do the connections between things
  • Decorating the notes with resize handles and (for our version) rotation.

So here goes – our back of a napkin specification;

  • As a user I want to see a canvas of notes.
  • As a user I want to be able to add a new note box to my canvas.
  • As a user I want to be able to rotate or resize any of my note boxes on my canvas
  • As a user I want to be able to connect note boxes
  • As a user I want to be able to delete note boxes
  • As a user I want to be able to zoom in and out
  • As a user I want to be able to drag my canvas around
  • As a user I want to be able to click a button to zoom out to the extents of my canvas so far.

At this point, I’m not going to bother with persistence – that’s a problem that’s well and truly solved, I just want to concentrate on the Silverlight side of life and I’ll stub out the service that would get the data for the user from the database.

So that’s the idea – I’ve spent around 8 hours on this so far and I’m quite impressed with how far I’ve been able to get – the screenshot below might look like crap, but it’s proving out some of the technical issues I’m interested in; If you’re interested, the top and bottom diagrams mirror each other and have two separate data templates – you can add new notes, move notes around, pan the canvas as much as you like and zoom in and out…. quite good for 1 working day!

image

In coming days I’ll post the full diary, along with all of the source code - I’m keeping a detailed log of the issues I faced and how and why I made the decisions I made in building the application – once I’ve got it all together and the app finished, I’ll post it here. Watch this space!

Wednesday, 26 January 2011

Software development lifecycle – Part I – Introduction

Software development lifecycle – the process of how we build software, the steps we go through to design software, build it, test it, deploy it – it means a lot of different things to a lot of different people, but yet we find that many organisations aren’t really paying close enough attention to their processes and management of software development which leaves them reacting to problems, not knowing when they are going to deliver, delivering features that are irrelevant or lower priority than missing features and with no deep insight into what they are supposed to be delivering in the first place.

I’ve heard a number of teams say “oh, we’re agile"" – and what they mean is they have no specifications, no plans, no timescales and at the end of it, no jobs because the company employing the team went bust waiting for the team to deliver something.

So, in this series of blog posts I want to take a look through some of the things to think about when implementing structure around your development activity – on the one hand you don’t want to just have a team banging away at code with no formal structure, as the example above, but similarly you don’t want to get too binding with this otherwise you’ll end up with Carl (lets call him Carl in this situation) rocking in the corner, muttering about how he’s “too confined and boxed in maaaan” – development is a creative, problem solving process, let them be creative but within some structured boundaries.

I’m going to keep this series open ended an just chew the fat on a different topic each week and see where we come out. Whilst not a list of topics that I’m going to write on individually, below is a list of some of the things I'm going to explore in this series;

  • Typical phases of a project
  • How to understand the problems and get a holistic view.
    • Involve the business or customer early and keep them engaged!
  • Defining the product
    • Why bother
    • What format
    • Who owns the product?
  • Understanding and addressing risk.
    • Prove it – show me the code.
    • The point of spikes.
  • Housekeeping!
    • Keeping track of risks, issues and key decisions.
    • Backlog pruning.
    • Keeping the customer engaged.
    • Other project artefacts.
  • Making a plan – estimation is not about marketing!
  • Iterating and aggressive construction.
  • Transitioning to live/launch.
  • Supporting the product.
  • Managing the team
    • The role of team lead
    • 8 hours does not a day make
    • Motivating technical people.
      • Doesn’t involve putting the dev team in an open plan office next to the sales department hotlines!
      • Continual harassment != productivity.
    • Monitoring progress
    • Dealing with hold ups and blocking issues.
    • Why it’s possible to keep the reigns of management loose and still be impossible to get away with being a slacker.
    • Capability leads and subject (domain) experts.
    • Recruiting technical staff
      • Show me the code!
      • Solve this problem!
      • Welcome on board – induction or abduction?
    • Training and/or free time to experiment.
  • Managing the code, the build and quality
    • Code reviews – still as important today! But let’s not get hung up on the traditional formality.
    • Daily and continuous builds
    • The build wall
    • Unit testing
    • Bugs – squish em soon and squish em often.
      • It works on my machine!
    • Source control.
    • Framework, framework, framework.
  • Strategy
    • Have one!

Monday, 17 January 2011

Quick explanation of generating dynamic WCF client proxies with Unity;

I’ve been using castle windsor for years now and it’s been my favourite IOC and DI container for a long time. On one of my current projects, I’ve been forced to look at Unity a bit more closely and the first thing that came up for me was how to create WCF client proxies automatically from the shared service contracts. This is how I did it;

I configure the container with code at the moment – I don’t know about you but the usefulness of IOC isn’t the fact that you can replace components at runtime, it’s the clean separation and testability that following a loose coupled pattern gives you. So, I configure my container in code – if I needed the ability to replace bits later, I’d devolve just that part of the configuration out to XML or such like, but I wouldn’t start at XML – it’s too easy to introduce a typo and it doesn’t support refactoring easily.

Anyway, so the complexity of registering a WCF client proxy is it doesn’t have a concrete implementation – I have an interface assembly that contains the service contracts and data contracts and I want to tell WCF to wrap the interface with a channel factory and create the resultant channel.

Unity provides a way of doing just that;

_host.RegisterType<TService>(new InjectionFactory(c => new ChannelFactory<TService>(endpointConfigurationName).CreateChannel()));

TService is our interface and endpointConfigurationName is the name of our endpoint configuration in app.config. What this does is when something wants to resolve an instance of TService, it calls the lambda contained within the injection factory and this in turn creates a channel around the interface.

As such, you can then just go ahead and call your interface members and it will wire everything up for you. No need for service references etc, it just works :)

Friday, 14 January 2011

A modicum of security would be appreciated!

My web hosting package was due for renewal today and I received this email (yeah, I’ve redacted some information to protect me and the people in question); I was quite shocked with the content of the URL that was in the body of the email;

image

Yes, you read that right, they sent me an (insecure) email that contains in clear text everything you would need to access my account with that provider. Why bother with that https:// at the beginning of the url if you’re going to stick my username and password in the text of the email body too! You don’t need to try and bypass SSL and watch what is being sent to the site, all you need to do is get hold of the email being bounced (insecurely) around SMTP servers and you can have full unadulterated access to my hosting package! (and possibly more – read on!)

I don’t mean to pick on these guys, they aren’t an isolated case, and other people have articulated why this kind of thing is REALLY bad better than I can so I refer you to Jeff Atwood’s articles on “The dirty truth about web passwords” and his post about “The internet drivers license”.

Update: Forgot to add this link in; Smart enough not to build this website

Thursday, 14 October 2010

MVC1 to MVC2 caching gotcha

I’m presently helping a client refresh their solution to the latest technology in K2, ASP.NET MVC, Sharepoint etc and found quite a poor issue with how caching works in MVC 2 compared to MVC 1.

The scenario, lets say we have a single controller with InitialiseA(), InitialiseB() and Start(). The two init methods would set some session variables or do something in the database and then send back a redirect to action to go off to Start. This is what I expect to happen;

The reality is significantly different though. The above is how it would work in MVC1, but in MVC2, the following happens;

The result of the first invocation of Start is being cached and so, when the browser gets the 302 response it realises it already has the content for the redirected url and just renders that. So what’s changed?

MVC1 used to send an expires HTTP response header set to the current time, meaning  the browser wouldn’t cache the result. MVC 2 however doesn’t send this by default, so I found myself with a bunch of issues around the scenario described above. In just so happens that in this case all of my controllers descend from one common abstract base controller, so I was able to add the OutputCache(Location=OutputCacheLocation.None) attribute to this base class as follows;

[OutputCache(Location=OutputCacheLocation.None)]
public abstract class MyBaseController : Framework.Web.Mvc.ControllerBase
{
..
}

Sunday, 3 October 2010

Get executable full path?

Today I needed to know where a command line executable was running from – msbuild.exe to be precise. My path environment variable is extremely long on my dev box, so I just wanted a quick way to find out where the exe would be run from. The following does exactly what I needed;

for %f in (msbuild.exe) do echo %~$PATH:f

And the output?

image

Just what I needed :)

Wednesday, 29 September 2010

Attach and Detach VHD files from the command line

Very simple and quick way to attach or detach a VHD file on demand, from the command line – use diskpart;

A) Create a diskpart script to attach your VHD;

Enter the following into a new text document (for the sake of argument, let’s call this attach-script.txt)

select vdisk file="your.vhd"
attach vdisk

B) Create a batch file to execute the diskpart script;

Invoke diskpart with the /s parameter as follows in your batch file (again, let’s call this attach.bat)

diskpart /s attach-script.txt

C) Create a diskpart script to detach your VHD;

Should be as follows (calling this detach-script.txt)

select vdisk file=”your.vhd”
attach vdisk

Create a batch file to execute the diskpart script;

As before, call diskpart with /s (detach.bat)

diskpart /s detach-script.txt

And your done…. just execute attach or detach as needed to mount/unmount your vhd file….

Getting a free lunch? Bitbucket is now free.

I’ve always been told there’s no such thing as a free lunch, but an email I received this morning appears to contradict this mantra!

I switched to Mercurial for my own personal/project source control earlier this year, abandoning subversion after many a happy year. When I made the switch, rather than host mercurial myself and have to worry about back-ups and the like, I signed up for a 10 repository plan with bitbucket, which was a meagre £10 a month. I had to do some creative merging of repositories to get all my projects into 10, but I was more than happy with the platform.

This morning however, I received a free lunch - an email that my plan was now free. They’ve teamed up with Atlassian and are now offering unlimited private and public repositories with 5 users for free!! I’ve not been able to find a catch :)

More info here: http://www.bitbucket.org