Principles not techniques

I like to think of coding in terms of principles vs techniques. I’ve met tons of good coders with lots of technique. Good technique. Rote technique. I’ve met very few coders who have good principles. A principle will let you look at anything code related…..and understand it….and if need be troubleshoot it.

I see this idea a lot in Tai Chi and few other Chinese martial arts I’ve been exposed to. The idea of principle, not technique. If you understand the principle of body movement, you can eschew learning thousands of techniques, you can remove the need to run through a million scenarios in the hopes that you will train your reflex for each one to the point that it just works. The millions of techniques that you will never have enough time to run though anyway. You can instead, simply use a principle to move appropriately for your current context. Context is very important. I’ve seen people who have technique so entrenched that they are blinkered to context. The last thing you want is to be so “well trained” that when a toddler runs towards you playfully trying to grab your leg that you mistake it for someone trying a double leg take down. You feel proud as you slide off the line, tap the kid on the back of the head and send them headlong into the wall! Context is important.

Now principles can be different things to different people, but lets take a simple idea from Tai Chi – “every step is a kick, every kick is a step“. What a great concept. We draw lots of things from this idea. Every time we walk down the street or to the toilet or to get a cup of tea we are training our kicking. That’s one idea – and what a great idea! Imagine the extra hours of training you get from simply making walking your training. Three times a week at class? ptha….you would be training practically non-stop. Another idea is that kicking should be as effortless as walking. As easy and natural as putting one foot in front of the other. We could also say that in a fight, any time you step it is an opportunity to kick.

It is odd, principles often get distilled into a poetic statement. Though I guess it makes sense – what better to show a principle than something like poetry, something that is open to interpretation, something that each person will find use in, no matter their level of expertise.

The great paradox in many martial arts is that principles are often learned through hours of working on techniques. Nevertheless, great teachers can take one simple move and create thousands of techniques from it.

This is the same in code – the experts will understand the principle. Then, the language becomes irrelevant by and large. It becomes a matter of syntax. My first “mentor” was like that. He could slip in and out of languages so easily, it was sickening. It wasn’t that he learned them quickly though. It was more that he just understood *how* to code and could apply it to any syntax he wanted to.

Of course this works on several levels – for example you could say all object oriented languages share enough commonality that the syntax becomes largely a by-product, but if you had to jump to a functional programming paradigm, you might be lost, no matter how much of a guru you were in OO. I like to think there are levels beyond that though that would allow you to transcend even larger shifts in programming paradigm.

To a certain extent, I think this ability is honed; honed through coding in several different languages, but also honed through the ability to create metaphors. Maybe it is the ability to code in your own internal pseudo code and simply translate it into php/ruby/python/c on the fly. Perhaps it requires a deep knowledge of at least one language to really allow you to build up that base of pseudo code (the paradox of the path from technique to principle). But maybe it really just relies on being able to think from a different angle. To reduce the task to a story and shape the solution using the tools at hand.

If coders aimed for this ideal, we would create a side-benefit. We would remove language wars. Which is not to say we would remove preference, because everyone is unique and will find themselves more at home in one language than another, but we would all be able to see the commonality between the code. And we would choose the most suitable language for the job at hand.