Sunday, November 18, 2007

Stealing from the masters

I recently read Seth Godin's blog http://sethgodin.typepad.com/seths_blog/2007/11/sorry-to-talk-s.html that was summing up how you shouldn't begin a speech.

Anyway, this evening, I had to give the best man's speech at a wedding and I opened thus:

"The public speaker Seth Godin recently wrote that you should never begin a speech with an apology, because a speech should be regarded as a gift. All too often I've heard people begin a speech with:

I'm sorry to keep you from the dancing... or
I don't mean to interrupt your coffee... or... more commonly
I'm sorry to keep you from your wedding night.

But nevertheless I feel I owe it to the groom to say: Jock, I'm sorry."

If I had never read Seth's blog I wouldn't really know how to speak in public, and that's not just because I steal his best lines. Instead he's taught me how to tailor to an audience, and tell them what they want to hear.

As a software geek that's often quite difficult to do, but the easiest time I can remember was when I was put on the spot to do some interface training because the architect was stuck on the tube - because I hadn't prepared anything there was nothing for me to be nervous about, and hence it ended up with me having a conversation with about ten people, on their level and not some ersatz echelon that I'd tried to prepare in advance. Without reading Seth, it'd never have gone so well, just like the best man's speech that I had to deliver this evening.

Thank you.

Friday, November 17, 2006

Thank you Microsoft

One of my friends was bitching about Microsoft this evening. It's a recurring theme and I have to hold my hand up and say it's one that I'm guilty of - it's almost something you have to put on your CV these days in order to be taken seriously as a developer.

But I can't help playing Devil's Advocate so (and also because I'm currently reading Microserfs) I started defending the Seattle giant. And just to note that I'm not talking about that coffee company - friends should stop friends going to Starbucks.

One thing we take for granted is that everyone these days *can* use a computer - and it's all down to Microsoft. If you're swearing right now it's probably because you think I'm prejudiced so let me digress...

My first modern computer experience was about 18 years ago on an Apple Mac. (My mother was a teacher and the headmaster spent a truck-load of money on the latest, greatest computer hardware). I thought it was bloody brilliant. I could create a document that looked good, not only when I printed it out, but_also_on_the_screen! I discovered fonts and justification and tab stops. The problem: that was all I could discover. That was all that the computer allowed me to do and I kinda wanted to do more.

Fast forward... five years... sitting at a DOS prompt and it seemed like the world was my oyster. Again I was in my mother's classroom but this time with a black screen and a white c:>. The mouse did_nothing_at_all. I had to install a special programme to make the mouse move around the screen. But *I* did that, and it was really easy to do.

Anyway, DOS and Windows 3.1 crossed the divide between the all-knowing WIMP world of an Apple Mac and the closed-circuit world of I've-never-heard-of UNIX. It gave us the "in" to the rabbit hole... and it was deep hole.

There are some sceptics out there swearing so I'll point you to a much better source than I: http://www.adambosworth.net/archives/000031.html

As Adam says, technology only works if it's simple enough for users to adopt. Macs gained a following because everyone could use them, but the geeks among us didn't take to them because they didn't offer us the opportunity to mess around enough with what we were using - at the time it was more fun to make some patterns with a magnet and some iron filings... at least it felt as though you had some control over what was happening, even though we later found out that we were messing with something a lot bigger. That's what Windows gave us - the ability to change some innocuous parameters that made us seem like we were in control - and sometimes with some disastrous results:

You've all been there, when you were younger, and someone's aunt's friend asked you to come round and fix some problem they were having with Windows. You booted up the machine to be presented with some various-shades-of-green windows with purple scrollbars and you wished in that moment that Windows didn't allow the users that much control over their environment. Yet at the same time, if it didn't, their PC would've lain dormant in the corner, only to be used to type out the odd letter during the holidays. No one would've played. And systems only improve when a lot of people play with them - the web being a case in point.

Fast forward... ten years... and I'm developing an application in .NET because I_have_to. Paul Graham will argue differently but just try walking into a (relatively small) bank in London and tell them that you want all their users to run a program written in Lisp or Python and you'll be out the door before your bum hits the chair. They may be early adopters but they're not idiots.

And the only idiots at the end of the day are us - those people that begrudge and slag off Microsoft for opening the door to development and letting the public in. Without Microsoft there wouldn't be a PC in every kid's bedroom for them to install Linux on and try to take over the world... and I'm glad that they try, because without those sorts of people we'd all be sitting in front of our Macs, pointing and clicking; or even worse sitting in front of our Unix terminals counting registers and writing essays of command-line parameters. Sometimes the only way to appreciate the present is to be thankful of the history that brought us here.

Labels:

Friday, October 06, 2006

Functional programming in an OO world

Hands up who likes functional programming? Is that a straggler I see at the back of the class (yeah, that was always me, the one who snuck in late and didn't know what the lecture was about*)?

I work with a non-programmer. By that I mean a guy who, annoyingly, has not been classically trained in programming but still holds the title and paycheck of a very-good-developer. He doesn't really understand OO programming or design patterns or regular expressions or software engineering paradigms but unfortunately that's vastly outweighed by his ability to anticipate appropriate HCI. Yes, the git knows how real users actually use the software that we develop. And he's very good at it - they even trust him when he tells them to reboot!

Anyway, the problem with not knowing how to properly program is that he's not constained by the rules we have been taught over the years. He's grown up (I dare say developed) in a C# environment, but I made the mistake of recently introducing him to XML (which we all know is a kind of static version of Lisp**).

So back to functional programming in OO. All you have to do is decouple your functions from your objects - easy, eh? It is if you use XML!

Assumption: you are building a thick-client windows forms app using .NET.

So forget that your whole system is based on a load of C# objects; instead start with an XML document that tells you what you need to load. The beauty of a windows forms app is that you already have a God Object - it's the bloody form! But the trick is that that is NOT your God Object. Instead use a factory-pattern to create all your controls based on - oh yes, you guessed it - that XML document. So well done, let's have a biscuit and congratulate ourselves for implementing WinFX. Thank you Microsoft.

Now comes the science... Look in the mirror. Relflection is your friend. Any node in your XML document corresponds to an object that can be created, so use reflection to create it. Any attribute is a property of that object, so use relfection to set that property. So you've instantiated any object you like - and using [note plural] custom interfaces (which the MFC conveniently doesn't supply you with for the Control class - so you have to create your own - which if you think about it you would need to do anyway) you can invoke any initialization method you like. Hmm, that sounds ominous...

So imagine that child-nodes don't have to be controls, instead they're just objects which you instantiate which accept parameters (or, if you add some programming magic, variables which can be passed through our 0mniscient factory - who said God is Dead, oh Nietzsche, but he was full of it) which can then throw events to themselves or other objects (which can in turn pick up variables through our omnisceint*** object) and you have an OO system that behaves in a funcational way.

So we've got it working. Yes, we have. And I promise we'll publish it in a bit, once when we've ironed out those pesky bugs!

* No really, I was always late. I did an electronics degree - lots of stuff about Fast Fourier Transforms and Singularities - but I so rarely turned up on time that I was surprised that I passed in the end. I think it was only the CompSci modules that saw me through. Anyway, when I turned up for my interview I got the wrong bus so arrived at Southampton Uni a half-hour late, only to walk in to the front of the lecture theatre with a green streak in my hair (and obvoisuly a green-streak in my demeanour - I'd been to a "bad taste" party the night before). So late was I that I ended up on the CompSci tour instead of the Electronics one, which was much to my embrassment when they handed out offers at the end of it and mine was in the wrong pile - though it was an appropriate preconception of what was to become.

** Okay flame me now - I dare you. We don't care 'cos it works!

*** It's not really omniscient - it has a local scope (othewise how could it really behave?) - but it does take care of all the localised objects (either controls or datasets - see previous post) which it is responsible as a factory for creating and destroying [which is equally important if you know that windows has a GDI, window handle and object limit] to conveniently access variables. I know that this breaks a few rules and paradigms but believe me the performance benefit is worth it.

Labels:

Java to .NET and OO-ooh

A long long time ago, like any other programmer, we all thought that Object-Oriented Programming (or even worse, Object-Oriented Analysis) was a bit of a fad that would never really make it to frution - what are those Java guys doing? - let alone fecundity. But we soldiered through and ended up where we are today. Up until then hacking had seen us through. I blame Frtiz Bauer:

"The establishment and use of sound engineering principles in order to obtain economically software that is reliable and works efficiently on real machines."

How to take the FUN_OUT_OF_PROGRAMMING = 0x00000000;*

But then again, that's what academia is for, right? There is a point, right? So we graduated and all got jobs for web companies (y'know, back when it was cool). We took the usual route of scripting, then server software, then a bit of client side RPC before AJAX earned it's cool acronym. Then when the bottom dropped out we chased the money and all ended up working for banks <jealousy>or starting our own Spolsky-esque company, or working for Microsoft</jealousy>.

So as a naive Java programmer I've arrived in .NET world, but like a Catholic convert to Islam I've brought certain prejudices with me:

1) There's got to be an open-source framework out there to fulfil my needs.
2) Everything is an object - EVERYTHING.
3) NHibernate must be as good as the Java version - it can do EVERYTHING.

Which is fine until you're deploying a thick client on real machines which suffer from real problems which they don't actually tell you about in academia. You only find out about all these things when your program crashes and you're browsing the backlog of Eric Chen posts. It's at this point that you realise what's wrong with Object Oriented Programming - there's objects involved.

It would all be a bit simpler if we could just deal with primitives and not worry about the overhead of creating and ridding ourselves of these turbulent objects. Why is it that the garbage collector never seems to turn up on the same day each week?

So that's my dilemma

- eh? what's your dilemma?

Sorry, let me explain. I've got to pull about 8000 records from a database to client side and display them to the user in a cool way (not just standard Windows I can do this stylee) and provide an interface that real people can use. But it's got to be quicker than the 8 seconds windows-I'll-draw-you-a-list-view. Why? 'Cos otherwise I'd get an earful from "them upstairs" every time they click on a button.

So what did we do? Simple, we borrowed a good open source .NET control and bastardised it till it fit our purposes - using an asynchronous data grabber to retrieve a primitive rectangular array, with an MVC interface and custom IComparer to load and sort 8000 records in under 2 seconds whilst decoupling the data layer from the presentation layer using XML definition files (a la WinFX or whatever-its-called-these-days). Which is occasionally quicker than Enterprise Manager - backed up with no factual evidence whatsoever.

The point is that, like religion, one has to adapt to an environment - what is appropriate in one sphere (e.g. Java server programming) may not be relevant in another (for instance Client Side .NET developement). So whilst you skills are transferrable, you aptitude may not be so, and you may yet (like all of us) have a lot to learn.

* The most pointless constant in the universe (next to Planck's - what use it that, really?)

Labels:

Why?

So why pentasyllabic? Because all the good titles were taken, so I thought that something autologos would do. Why? Well a bit about me then: I'm a bit of a pedant, but that's what 10 years of writing software will do to you (especially when you've failed to write anything else of significance). I'm 28 years old and have worked as a Software Engineer* (note capitals) for the best part of the last decade, here in London, during the early days of the dot-com boom through to the rise of the sleeker, halcyon Web 2.0. So this is my two cents (or 1.09 pence) worth - my homage to all the Spolskys, Gunderloys, Chens and Sinks of this world; those guys who've made me the developer that I am today. And those guys that continue to inspire me to be the developer of tomorrow (that's if I make it in to work) - to stick at it and not to give up in those dark times of NullPointerException hell.

Luke.

* So, C > ASP etc. > VB > C++ > Java etc. > C# .Net ... and whatever's next