Tuesday, September 13, 2011

The Platypus

I read this in a book recently:
"Early zoologists classified as mammals those that suckled their young and as reptiles those that lay eggs. Then a duck-billed platypus was discovered in Australia laying eggs like a perfect reptile and then, when they hatched, suckling the infant platypi like a perfect mammal.

The discovery created quite a sensation! 'Why does this paradox of nature exist?'

Zoologists, to cover up their problem, had to invent a patch. They created a new order, monotremata, that includes the platypus, the spiny anteater, and that's it. This is like a nation consisting of two people."
The book is 'Lila: An Enquiry into Morals' by Robert M. Pirsig, more famous for 'Zen and the Art of Motorcycle Maintenance'. For some reason, maybe because I'd been coding that day, not unusual since I am a web developer by trade, it made me think of the canonical example of inheritance you always see:
Animal animal = new Dog();
which is described by one commentator as 'You are creating a new Dog, but then you are treating it as an Animal'. I thought it would be fun to go through that story in an object-oriented manner, and see what (unholy) code emerged.

Flickr photo
FlickrPlatypus, by Psycho Hamster

First of all, I need a base class and two interfaces
abstract class Animal() {}
interface ISuckleYoung {}
interface ILayEggs {}
such that
class Mammal() : Animal, ISuckleYoung { }
and
class Reptile() : Animal, ILayEggs { }
Now, classify things!
class Classification {
    void Classify() {
        Animal bear = new Mammal();
        Animal snake = new Reptile();
    }
}
This builds, and I'm experiencing the satisfaction that only a Victorian taxonomist could have known. Then this happens:
class DuckBilledPlatypus : Mammal, Reptile {}
This code causes a sensation! A platypus can't derive from both a mammal and a reptile, and C# knows it. So, rolling that back, I'm left with an unclassified Platypus. There's a band name if anyone wants it.
class DuckBilledPlatypus {}
Enter the Monotremata (sing. monotreme), an order that belongs to the Mammalia class:
class Monotreme : Mammal, ILayEggs {}
They're mammals that lay eggs! This new order squeezes in between the Platypus and the Mammal/Reptile level in the hierarchy, restoring taxonomical rectitude to the situation:
class DuckBilledPlatypus : Monotreme {}
class SpinyAnteater : Monotreme {}

Generic classes

Actually, I'd rather make a monotreme a generic class:
abstract class Monotreme : Animal {}
class Monotreme<T> : Monotreme where T : Mammal, ILayEggs { }
That means we can new up monotremes like this:
var platypus = new Monotreme<DuckBilledPlatypus>();
var spinyAnteater = new Monotreme<SpinyAnteater>();
But there's something missing. There's the poetic comparison that the author makes between this whole kludge and a nation that has two people.
interface IAmLikeANationThatHasTwoPeople {}
which decorates the Monotremata order, consisting solely of platypi and anteaters, which is a just a bunch of Monotremes:
class Monotremata : List<Monotreme>, IAmLikeANationThatHasTwoPeople
{
    List<DuckBilledPlatypus> _platypi { get; set; }
    List<SpinyAnteater> _spinyAnteaters { get; set; }
}
With this hierarchical scaffolding firmly in place, zoologists can continue classifying weird animals thus:
void Classify()
{
    var classifiedAnimals = new List();
            
    Animal bear = new Mammal();
    Animal snake = new Reptile();

    classifiedAnimals.Add(bear);
    classifiedAnimals.Add(snake);
            
    var platypus = new Monotreme<DuckBilledPlatypus>();
    var spinyAnteater = new Monotreme<SpinyAnteater>();

    var monotremata = new Monotremata
                                       {
                                           platypus,
                                           spinyAnteater
                                       };
    classifiedAnimals.AddRange(monotremata);
}

"Platypi have been laying eggs and suckling their young for millions of years before there were any zoologists to come along and declare it illegal. The real mystery, the real enigma, is how mature, objective, trained scientific observers can blame their own goof on a poor innocent platypus.

The world comes to us in an endless stream of puzzle pieces that we would like to think all fit together somehow, but that in fact never do. There are always some pieces like platypi that don't fit and we can either ignore these pieces or we can give them silly explanations or we can take the whole puzzle apart and try other ways of assembling it that will include more of them."

Copyright warning!

Please, if you use this code for commercial purposes, say in some zoo or vet app or something, give credit where credit is due. That's a joke, by the way.

Wednesday, September 7, 2011

How to be an unemployed .Net developer

"You're just another asshole with a resumé!"

Don't watch "The Company Men" when you're 'in-between' jobs. Nothing to do with making you more demoralized or anything like that. It's just not a very good movie. It's full of whingey business types who think they're owed a (very high standard of) living by The Man. And then they get to indulge a hard-hat wearing, toolbelt-toting, Kevin Costner-baiting, blue-collar-having fetish. Because that's real work, that's honest work. Anyway, don't watch it: that's my advice.

Flickr photo
FlickrTHE COMPANY MEN, by Savage French Grey-Blues. I'm not sure this was a great movie

Now I've been offered a job, I thought I'd write about one of the more difficult aspects of working as a .Net developer: not working as a .Net developer.

'Unemployed' is a vague term: there's unemployed, and there's finished a contract, gone to Greece, came home 3 weeks later, and looking for either contract or full-time work. So I don't know if the word 'unemployed' is a fitting term when I knew in all likelihood I was simply in-between jobs.

So what term would I use? Job lurking? Maybe. When I went for lunch with my working friends in the city recently I felt like a creepy old guy in a chat room full of giggling teenagers, pretending to be one of them, watching but not saying anything.

I'm the pig

One thing that surprised me was the flakiness and indecision of some of the places I interviewed in. I learned that you can't expect the courtesy of a definite response from some companies. When you explain to the guys who interview you that yes, you found the place ok, having taken two busses to get there, then it seems to me the minimum of common decency that they might make good on their promise to let you know soon one way or the other after the interview, but this wasn't always the case. A company whose website says 'Our Core Values: Professionalism... ' but who themselves won't say 'The last guy came back so we don't need you', 'We ran out of money' or that old chestnut 'We think you're shithouse' to your face is a big fat liar.

And don't harass your recruitment agent: they're just as pissed off as you are. Actually, they're about 15% as pissed off as you are, to be precise. It's a chicken and pig breakfast situation.

I'm lovin' it

Get out of the house! I don't care if it's full of bogans and kids, +1 to @McDonalds for providing free wifi. Go there in the mornin' and you'll see all these people surfin', phonin', drinkin' coffee - it's a digital hub in your local McCafé. I used to go there with my Android Xoom to do some blogging, catch up on some feeds, and of course vainly try to become mayor.

Upgrade

Devs are always complaining about how they can't use the latest tech, can't use MVC3, can't use Entity Framework, can't use jQuery. It's just not used where they work, and they can't go changing everything to keep up with Scott Gu. But I could. I upgraded my site to .Net 4, upgraded my IDE from the laughably archaic Visual Studio 2008 first to Visual Web Developer 2010 Express, and when I realised that that was incompatible with ReSharper 6, which I had also upgraded to, I upgraded to Visual Studio 2010. Such is the importance of ReSharper to me nowadays, that had I realised in the first place that Web Developer 2010 didn't support it I wouldn't have bothered installing it. In the end I only stopped upgrading because I ran out of things to upgrade.

Brand

As an unemployed failure your brand does take a bit of a hit, so work on it. In my case I got back into blogging. It's not directly going to help you get a job, but it gives the impression of movement, which in the circumstances is very important.

And go and meet people: even in this day and age it's important to get in and meet the agents face-to-face who are trying to get you work. I met some really nice people - Michael and Tom at Hays, Thomas and Leisa at Zenus. Showing up in person seems to matter to them too. It's nice to know that some old-fashioned niceties still apply. Of course, virtual introductions on LinkedIn still matter too, and I can attest to the power of these. Out of the blue I got a few credible offers leading to interviews purely, from what I can gather, on the basis of Linked In.

A prediction

Here's a prediction: even though my Careers 2.0 profile has been about as productive for me as the habanero plant in my back garden, I predict that will soon change and that the Stack Exchange tidal wave will reach these shores and change both the way we advertise ourselves as devs and how recruiters and clients assess us. Technical questions are part of any job interview. I actually enjoy that part of the process, and of the 5 interviews I did 3 of them involved being asked tech questions although thankfully none of the experiences was as humbling as the one I had at Zap Technologies 4 years ago.

But CVs and LinkedIn can't give an evidence-based evaluation of what you've done or are interested in. Careers 2.0 can, insofar as it links your account to StackOverflow and a bunch of other similar sites. There's absolutely no point in setting up an account there unless you have stackexchange sites to tie it to. And I predict that that particular careers site will become more important in the next couple of years.

Being unemployed's ok. Seriously. I'll miss it.