IOC and Ninject
Who said an old dog can’t learn new tricks? I have two Gen Y’s in my team teaching me and as much as I have been teaching them. Which is a great place to be - but recently they have been showing me Ninject (http://www.ninject.org/) which seems like magic to me.
Let me explain. I understand the concept of IOC, but when you have been writing code for over 20 years it is hard to break the “new” habit. What really gets me is that you can add a new dependency to a constructor and NOT have to add that to all the callers - because Ninject will automatically create that extra dependency (assuming a rule exists for it). Magic. It gets me every time.
Now don’t misunderstand me. IOC is great. Great for unit testing. Great for class design. Keeps class concerns separate. etc. It is just a new way of thinking for me, that I hope will be second nature very soon.
I have also been wary of applying Ninject everywhere (ala my first experiences with PostSharp) and trying to find the right balance. Where is the right place to use Ninject and where the old fashioned “new”?
While I don’t have an exact answer (and it will depend on many factors in each application) I think it is fair to say in general that you should use IOC for concerns that you are very likely to want to replace/update/change during the life time of the application. Taken too far and I think IOC would tip the balance from flexibility to over complexity and increased maintenance.
That said, what would an old dog like me know?
Hiring good software developers
All technical managers need this skill if their teams are going to shine - interviewing and picking out great candidates.
Hiring good software developers is one of the hardest jobs in software development, however I have picked up a number of tips and tricks that combined together have served me well.
- Your attitude. Make sure you treat this as an extremely important task. I read this article from Joel on Software many years ago (http://www.joelonsoftware.com/articles/GuerrillaInterviewing3.html), and getting in this mind set has always meant that I tackle the hiring process as my main objective - not something that I fit into my schedule or expect recruiters to do for me.
- Technical test. This should be short (10-15 minutes max), but cover some important areas for the role. It should be easy for those that know their stuff, but have a few common gotchas that help you identify those not up to your required level. Make sure the answers are black and white. Writing a test that states “what is printed out” works well. Make sure you set a benchmark of what you are willing to accept (say 7/10). If they fall below this then you can terminate the interview early.
- Role play. Set up a situation that will allow you to explore just what kind of person you are interviewing. What works well for me is a typical scenario in the business today - and then take it to an extreme. What you are trying to find out here is not whether they can code, but how they work under pressure, or with missing requirements, or with lots of change, etc. Do they try and fix the issue? Do they just go along with the status quo? This should take around 30 minutes and have quite a bit of depth to it so that it feels real to the candidate. It might take some time to develop, but this will this will pay back big time.
- Read body language. At all times make sure you are watching their body language very carefully. Of course they will be nervous at the start, but try and get them relaxed as soon as possible. Once you do you will start to see the real person come out in their body language. Do some Googling on reading body language - it is an interesting topic (http://www.google.com.au/search?q=body+language+reading)
- Team and culture fit. So they have past the technical test, done well in the role play, and you are confident they can fill the role - but will they fit in with the team and the culture of your business? This is important - they have to become part of the team and fit in with the culture or else you are in for a world of pain. For example, the culture at Zappos is not for everyone (http://about.zappos.com/our-unique-culture/zappos-core-values)
Follow all this and you are on your way to hiring some good developers for your team. Happy hiring!
Why does short term always win out over long term?
In any technology project you have the natural battle of “we need it now” vs. “let’s do this properly”. What is the result? In my experience the need-it-now camp nearly always win. But is that wrong? What is the right balance?
In any commercial business, especially start-ups, the need to get something out into the market place quickly is vital for survival. But as companies get some success and money behind them you might think that this thinking would change. After all, doing it properly is more economical in the long term - right?
Well maybe.
These days Agile is more than a buzz word in the software project management circles, it is becoming the defacto standard, and it preachers the need to keep iterations short; get feedback early; adapt quickly to change; communicate often; and make decisions at the last responsible moment. Why does this methodology work so well? Because you can never stop change, whether it be new ideas, feedback from customers, or from competitive pressure. Software is now so complex that trying to build it any other way is difficult.
So how do we build good software, rather than just working software. How do we make sure we can maintain it, extend it, and adapt it, without requiring us to start again? How can we keep software development fast whatever age the code might be?
There is no silver bullet, but these things can make a significant difference.
- Development Teams should own the software - not the business
- Pragmatic architecture & designs
- Isolate concerns without going overboard
- Re-use where it makes sense
Postsharp - An aspect-oriented framework for .NET
I have been playing and using Postsharp recently and would like to state “where have you been for the last 10 years of my life!”
As with all new shiny things there is a tendency to over use and abuse. I am as guilty as the next man - maybe more so - of this. Just because you can code something as an aspect - doesn’t mean it is an aspect. But once you settle on what Postsharp Aspects are, then Logging, Caching, Performance Counters, etc are a breeze to add to code.
One thing that does annoy me is that you can’t inject dependencies via constructors. I understand why - but it makes testing Postsharp Aspects a bit tricky/ugly.
If you can overlook this drawback, then Postsharp is a great technology that should be added to any .NET developers toolbox.
To find out more about Postsharp, check out http://www.sharpcrafters.com/
Geo Location Searching - How hard can it be?
The catch cry of any software engineer for a problem that is simple to describe. Geo searching does indeed seem to be easy but after spending some time on this I’d have to say it is one of the harder problems I have had to solve.
Let me explain.
Just say you have millions of records each with a Latitude and Longitude, which could be any where in the world. Now find the all the records that are with X distance from point Y.
Sounds easy. But try coding it. Then add the requirement that this needs to be quick. Real quick. Say less than 1 millisecond.
And you can’t assume a flat earth. You need to support a spherical model.
Also these records are constantly updating (some being removed, some being added, some changing) and you need your search to reflect these changes.
Then also add that you would also like to be able to do nearest neighbor searches. That is, given a point Y, tell me the top X closest records.
At this point you are thinking “just use SQL, or Mongo, or some other engine that supports GEO searching”. And normally this is a good answer but in our case we found that when returning more than 10,000 matches, the queries were taking way longer than 1ms.
So what do you do? How do you solve this?
The last 2 weeks my work colleague and I have have been doing just that and I can tell you “it is harder than you think”, but we have a working solution.
If you find that you have to solve something similar, then here are a few pointers.
Research and understand
- Haversine (http://en.wikipedia.org/wiki/Haversine_formula)
- Quad Trees (http://blog.notdot.net/2009/11/Damn-Cool-Algorithms-Spatial-indexing-with-Quadtrees-and-Hilbert-Curves)
- Determine the Lat/Long of a distance X kms away (http://jamesmccaffrey.wordpress.com/2011/04/01/determining-latitude-longitude-given-a-point-a-direction-and-a-distance/)
We did look at geoHashes (http://en.wikipedia.org/wiki/Geohash), but our current solution doesn’t require them (favoring a quad tree instead).