Should everyone learn to code?

January 31, 2013 | 6 comments

I posted this the other day, blissfully unaware of how contentious it would be:

“Learning to code is non-optional in the 21st century.”

It’s a piece of hyperbole, of course; learning to code is perfectly optional. Nobody’s pointing a gun at your head and forcing you to do it. But here’s what many of my friends and contacts read into it:

  • People who can’t code are less valuable in the 21st century.
  • Coding is as important as, or more important than, learning to read, write, do math, or cook.

Of course, I didn’t say any of those things. It’s interesting that they were inferred, and that the idea that everyone should code was seen, generally, as being self-important and enthocentric from the perspective of the tech community.

Here’s why I said it:

  • Software technology is an integral part of all of our lives. It’s part of our environment, and will only become more so.
  • Coding gives us an increased level of control over our environment.
  • Without being able to make or alter software, you are relegated solely to being a consumer of it.
  • Learning to code is virtually free (if you already have a computer), and it’s not hard to get started.
  • The web in particular is a medium that has the potential of allowing anyone to contribute to it. I feel strongly, ideologically, that it should not be yet another medium where a few large companies dictate the form.

It’s also true that, in today’s economy, technology is one of the few growth industries, and having technology skills means you’re much more likely to be able to get a well-paying job. It’s also, generally speaking, not an elitist industry: most tech companies care much more about what you can do, rather than where you went to school (or even if you did). There are also no required professional qualifications to obtain. It’s a pretty good deal. All you need to do is know how to make things well, and you get to teach yourself. (Codeacademy and Mozilla Thimble: both fantastic.)

Far more importantly, technology isn’t going away. It’s not a fad; it’s ingrained in everything we do. There’s no reason at all why you should have to do it for a living – and obviously, there’s a universe of fulfilling career options out there – but understanding how technology works is empowering. It’s a 21st century literacy that will differentiate – as Douglas Rushkoff says – between the programmers and the programmed. And guess what: I do think that the people who understand how it works will ultimately be more valuable. They’ll make better technology decisions, which – as technology becomes more and more ingrained – will mean that they’ll make better decisions overall.

But hey, what do I know. What do you think? Was I out of line? Or is code as important a skill as I think it is?

Disrupt the mainstream

January 29, 2013 | 1 comment

Anonymous contre Acta à Rouen

“Mainstream culture,” as a concept, needs to die.

A little pre-history. The Diamond Sutra, a sacred Buddhist text and the world’s oldest surviving printed book, was produced in China in 868 AD. It took another couple of hundred years before moveable type was invented, and another four hundred years for the printing press to be invented. Almost six hundred years after the first printed book was created, it became possible to mass produce literature. Two hundred years after that, the first newspapers began to appear, but they didn’t reach large circulations for another two hundred years – a thousand years after the first book.

Because of the advances in the printing press that allowed for larger circulations, newspapers could be distributed over a much larger geographic area. Prior to that, they had mostly existed in communities, where the publishers were easily reached. An unintended side effect of wider distribution was that this feedback loop was eroded. Newspapers became a one-way medium; a trend that continued with the invention of newsreels, radio broadcasting, and the television. Almost simultaneously, manufacturing techniques improved to allow for mass-market products made out of new materials like plastics.

The separation wasn’t clean. Because of its capacity to reach large audiences quickly, both government and business had interests in the media that went well beyond (while embracing) traditional advertising. They underwrote content, leaned on the companies who produced it, censored both explicitly and implicitly, and created a media environment that sold not just products and ideas, but a way to live your life. More than ever before, there was a wrong way and a right way. There was a mainstream, and then there were niche interests. This had always been true to an extent, but the main route for lifestyle propaganda had previously been churches, who fearfully controlled the means of communication. In the modern age, the media itself began to take the place of religion. (Think about the semantics of the phrase “mass culture” for a second.) Business and government had a direct channel to get their messages to the people. At the time, this seemed like a liberation.

It wasn’t a liberation compared to what came next. The beginnings of the Internet showed up in 1969, not at all coincidentally during the peak of the counterculture movement in the sixties – the first cultural movement to challenge the mass-market status quo. Usenet showed up ten years later, allowing anyone to participate in semi-public discussions. Ten years after that, Tim Berners-Lee invented the World Wide Web. Ten years after that, Napster was allowing anyone to trade music. A decade later, mass-market publishing was in free-fall.

For ordinary people, the utility of mass culture was coming to an end. Information was freely available without the involvement of businesses, governments or churches – both to consume and to produce. Anyone could publish, without anyone’s permission, no matter who or what they worshiped, where they had gone to school or how much money they had in their bank accounts. There were no corporate policies dictating who could be heard, and no slush piles where ideas that didn’t fit pre-defined marketing templates could languish. It was a free-for-all. Free as in speech.

In the middle ages, the church decried texts that defied its authority, often sentencing authors to death. In the 21st century we’re a little more laid back, but it’s nonetheless predictable that corners of the mass media, sensing that it’s under threat, have been arguing that Internet content is less reliable, or shady, even, contrary to the views held by the public. Meanwhile, proposed legislation like SOPA and PIPA and the Communications Decency Act were transparently aimed at neutering the new medium, and were often sponsored by the media companies themselves. (Wiser corners of both business and government have gone another way, and are simply buying these new media outlets.) Even now, opposition to SOPA is spun as a tech company triumph, while the truth is more subversive: the Internet is a grass-roots people connector, and it was the people who spoke in defense of their free speech.

Just as the media had fragmented from a few large organizations to something that every single person in the developed world could participate in, manufacturing is currently enduring the same kind of shock that publishing experienced. Sites like Kickstarter are flying in the face of traditional manufacturing processes, and allowing anyone to begin making products.

Mainstream culture was a construct. It was created partially by accident, because we were all consuming the same products and the same media, and partially on purpose, because people who conform to a set of ideals make better consumers from the manufacturers’ point of view and better citizens from government’s point of view. Once upon a time, it improved most of our lives through new manufacturing techniques and distribution models. In a world where this is no longer necessary, however, this imposed conformity is a kind of oppression. One need only look at the prevailing American ideals of strength over intellect, wealth over integrity, or the dismissal of “special interests”, to see a kind of fascism at work.

We’re all special interests. Humanity is beautiful because we’re all so different. We have dreams, ideals, values, goals and loves, and for each of us, down to a person, they’re all slightly different. That’s why democracy is so great – or at least, has the potential to be so great – and why freedom of speech is so important. We create a better society, and better lives for all of us, by embracing those differences and letting them form a patchwork, building something bigger together than the sum of all of us. Different ideas, cultural contexts, sexualities, abilities, preferences, characteristics, likes and dislikes; all of these are complementary as part of a bigger whole. The technology we build is there only to make our collective lives better; it doesn’t exist for itself, or so that we can make a profit. We’re building to progress. Technology is subversive, and always has been, because it empowers the previously unempowered. With the Internet, the time for enforced values has passed; we can all have a voice, and we can all have a media that serves us for who we really are. Ideas can and should be freely exchanged. People can and should be free to be themselves.

The concept of mainstream culture needs to become obsolete. That’s not to say that all the things in it can’t live on, enjoyed by audiences, or that the people who make their livings creating it can’t apply their skills to make new things for different kinds of people. That’s the point: it takes all sorts.

 
Photo: Anonymous contre Acta à Rouen by Frédéric Bisson, released under a Creative Commons license.

Using PHP closures with the observer pattern

January 28, 2013 | Leave a comment

PHP 5.3 introduced the concept of anonymous functions, often called closures. These have been present in languages like JavaScript for a long time, and have been incorporated into PHP as part of its ongoing transformation into a first-class web programming language.

Simply put, they allow you to assign the workings of a function to a variable. For example:

$myFunction = function() {
    return true;
}

This simplifies a lot of common programming tasks. For example, prior to PHP 5.3, you might have used the array_walk function to perform operations on the entities in an array as follows:

function processEntity(&$entity) {
    // perform some action on $entity
}

$myArray = array('one','two','three','foo','bar');

array_walk($myArray, 'processEntity');

Whereas now you can go ahead and perform your entire processing step in one statement:

$myArray = array('one','two','three','foo','bar');

array_walk($myArray, function(&$entity) {
    // perform some action on $entity
});

This works because in PHP, an anonymous function is a callable: it can be included wherever the name of a function was previously requested, without any further modifications to your code.

This is handy in itself for many uses, but it comes into its own when you combine it with the observer pattern. Here, observer methods listen for an event to be triggered, and may alter the subject of the event (where appropriate). I’m a big user of observers: Elgg’s architecture has depended on them since 2004, and in every project I’ve worked on since, observers have been called on system events (for example to run code when an object is saved or updated), and actions (for example to run code when a form action is fired, to log the user on, post some content, or some other action). They allow you to create simple object-based architectures where the components are logically separate but each section can communicate with each other section.

While I used to roll my own observer code, lately I’ve fallen in love with Symfony’s Event Dispatcher component (not least because it does pretty much what I was doing before, with richer functionality and code I don’t have to maintain myself!).

Events and actions are referenced with a unique string. For this example, I’ll use unique.event.name, and attach a listener callable that will be triggered whenever the event is dispatched, as follows:

$eventDispatcher->addListener('unique.event.name', $callable);

(There’s also an optional third parameter, $priority, which is an integer that indicates priority. Higher integers have a higher priority.)

Remember that a callable can be a string containing a function name, an array referencing a class method, or an object with an __invoke method. But because an anonymous function is also a callable, we can stick a function right there in the listener call:

$eventDispatcher->addListener('unique.event.name', function($event) {
    // Do something with $event
});

Invoking the event is as simple as calling:

$eventDispatcher->dispatch('unique.event.name', $event);

$event here is an object of class Symfony\Component\EventDispatcher\Event, so you could make your life easy and create subclasses for different kinds of events that carry payloads of useful data:

class exampleEvent extends Symfony\Component\EventDispatcher\Event {
    public $simplePayload;
    function __construct($simplePayload) {
        $this->simplePayload = $simplePayload;
    }
}

Then you can trigger the event and attach some payload data in one line:

$eventDispatcher->dispatch('unique.event.name', new exampleEvent($someData));

Each listener callable has direct access to this event object, and can modify it in turn. The object also provides access to the event dispatcher via $event->getDispatcher(), which can launch more nested events, or halt propagation to the next listener in the chain.

By creating different subclasses of Event for different event types, you can easily attach special event functionality or payload support for those instances. I can easily imagine defining UserLoginEvent, UserLogoutEvent and UserSaveEvent, for example. Event listeners can then check for event type (if they need to) by checking the class of the event.

By using anonymous functions for this process, you get to keep your listener and logic code in the same place, and write fewer lines of code overall, while making the most of a very powerful software development pattern.

Aaron’s army

January 24, 2013 | Leave a comment

This speech, in honor of Aaron Swartz, pretty much sums up why I work on the web. This is why it’s worthwhile.

Aaron was part of an army of citizens that believes democracy only works when the citizenry are informed, when we know about our rights—and our obligations. An army that believes we must make justice and knowledge available to all—not just the well born or those that have grabbed the reigns of power—so that we may govern ourselves more wisely.

He was part of an army of citizens that rejects kings and generals and believes in rough consensus and running code.

[...] Aaron Swartz was not a criminal, he was a citizen, and he was a brave soldier in a war which continues today, a war in which corrupt and venal profiteers try to steal and hoard and starve our public domain for their own private gain.

Read the full text of the speech over here. It was given as part of a memorial for Aaron Swartz at the Internet Archive tonight.

Next Page »