notes from the bigfug

programming light and other strange tales

Skip to: Content | Sidebar | Footer

Dan Pink on motivation; Nietzsche on bigfug

7 June, 2010 (13:47) | Uncategorized | By: Alex May

I was reading a recent article on Coding Horror that introduced me to Dan Pink and his ideas on what motivates people in their lives, and the surprising research carried out by a range of eminent economists that would seem to prove money as an incentive for work that requires even rudimentary cognitive skills actually acts as a hindrance.

His TED Talk is fast paced and amusing, though the white-board animated version of his RSA talk is just fantastic.

In the comments that followed the Coding Horror article somebody had posted up a long quote from Nietzsche, which, following on from my last post about how programming has been so intrinsically woven into my mind and life, would seem to describe this ‘character trait’ with no small degree of accuracy:

For [almost all men in civilized countries] work is a means and not an end in itself. Hence they are not very refined in their choice of work, if only it pays well.

But there are, if only rarely, men who would rather perish than work without any pleasure in their work. They are choosy, hard to satisfy, and do not care for ample rewards, if the work itself is not the reward of rewards.

Artists and con-templative men of all kinds belong to this rare breed, but so do even those men of leisure who spend their lives hunting, traveling, or in love affairs and adventures. All of these desire work and misery if only it is associated with pleasure, and the hardest, most difficult work if necessary. Otherwise, their idleness is resolute, even if it spells impoverishment, dishonor, and danger to life and limb.

They do not fear boredom as much as work without pleasure; they actually require a lot of boredom if their work is to succeed. For thinkers and all sensitive spirits, boredom is that disagreeable “windless calm” of the soul that precedes a happy voyage and cheerful winds. They have to bear it and must wait for its effect on them. Precisely this is what lesser natures cannot achieve by any means. To ward off boredom at any cost is vulgar, no less than work without pleasure.

Voila!  C’est bigfug!

From a fairly early age I’ve grown to accept that my noggin just doesn’t seem to work in quite the same way as most other people I meet.  Not that I consider myself close to either sane or insane, or more or less intelligent; these being comparative terms that are of little use to me or others; rather my priorities in life seem a bit skewed from the normal axis.

People groan when you talk about being ‘normal’, as though it denotes being boring.  To me, normality is having the same common basic life priorities as everyone else.  In his TED Talk, Tony Robbins (love or hate the dear chap) talks about this: that we all generally share a few needs that build on top of each other.  Once these are mostly covered we can start thinking about aspirations such as houses and children and careers, or if you’re like me, doing wild creative and challenging nonsense at the expense of just about everything else.

This, then, is my brain’s departure from ‘normality’.  When people discuss house prices and football and two weeks in the sun for their holiday, I find myself with nothing to add other than a stream of concious adjunct babble making light of the fact that I want to hit myself in the face with a hammer rather than listen any more.

This is probably why I don’t get invited to many dinner parties.

Additionally, I feel unable in these situations to talk about what I do.  When people ask, I politely mumble something about programming and art.  This isn’t actually polite or useful and it annoys my friends who know the scope of what I do and my passion for it.

Well, not so much unable – perhaps a telling choice of words there – rather I recognise a powerful signal of caution and fear that I think stems from school.  As I intimated in my last post, I didn’t get on with school very well.  I was doing just fine and then I had a really horrible teacher for two years in primary school who was incredibly controlling, scary as hell, and had thin, pointy anger  lines on her face from all the screeching she did (not only to her class, I imagined she’d be standing on the church roof during a full moon berating her dark gods for hours and chewing live bats).

Basically, you toed the line or suffered some serious wrath.  For a young lad such as myself who loved everything creative and joking and performing daft little plays he’d written with his friends in front of the whole school (can’t imagine doing that now!), she was a gorgon who had no interest for understanding and nurturing the needs of any particular child that might be even slightly outside of the strict regimen of the school syllabus.

In yet another TED Talk, the fantastic Ken Robinson talks about this in a more generalised terms, that even now our school systems are orientated around the needs defined in the industrial revolution, where maths and English are still considered far more important than art or dance.

Even then, at the age of six, it seems I had already started down my path.  I was not some totally malleable mind to be shaped into a good school product.  Then, as now, I have little choice than to follow my creative proclivities.  What ever form they manifest they emanate from a burning core that wails day and night and fires off blue lightning if I do not relent to its desire to be heard.

Aged eight, I rebelled, discarding any respect for school forever.  Shortly after my ZX81 arrived…

Despite my rebellion, I realised I was obviously legally still required to go to school, and I did love seeing all my friends so there was little reason to act so badly that I would be expelled, rather I set out to accomplish the bare minimum in all subjects that did not interest me, and put all my effort into things that did.

This tactic required a certain grim determination.  Detentions featured regularly, including the laborious process of writing out lines.  Fortunately, the teachers often got bored and went to go sit in the staff room, at which point I would stick ten pens together with blutac so I could fill a side of A4 per minute.

School then became a place where my mind was almost always whirring away on other matters than the ones at hand, and despite my enormous enthusiasm for art and computers and engineering I never talked about it, rather keeping quiet to avoid detection and further ritualistic punishment and humiliation.

It wasn’t until I reached college and A-Levels that I believed I might finally find a forum for my excitement but within two weeks I’d pompously hauled all the art tutors into one room at the end of the day for a discussion following my realisation that we were still being taught to syllabus, rather than yet allowed off the leash, and how could this possibly be true to Art?

Also I didn’t turn up for the first year of my computer science course: they were busy learning binary, I was busy learning 68000 assembler instructions and C.

Yes, perhaps somewhat naive and arrogant but my disillusion with education was sealed and my silence gilded.

I should probably point out, just to be clear and also in case any of them ever chance upon this screed, that the teachers themselves were never the object of my disdain (apart from you, witch-face).  On the whole they were kind, patient, intelligent people, working under difficult conditions, and I liked a lot of them.  I profusely apologise for being such a little upstart – especially to the ones that tried so hard to bring me into the fold.

I mention all this to serve as illustration and demonstration of just one story of one mind, the background of further writing to come for the purpose of tearing down these old silent walls and finding the voice to tell you all, clearly and with shining laughter, of the wonderful things, and the excitement of years, so when someone asks what I do (and, to me, this question is effectively ‘who are you’) I will be not be able to hold back my delight and joy.

Not that I expect it to be any more acceptable or less bamboozling to my fellow human, rather I don’t think I care so much about exposing myself to ridicule so much any more, and besides, excitement and curiosity are boundless and  internationally recognised regardless of their origin; sharing this commonality has to be a good thing, no?

Still, not quite there yet; will muddle through for now…

Rambling through all this reminds me of the two hour talk I did in Farnham a couple of months back at UCA.  I spent the first hour giving an illustrated history of how I got to be doing what I’m doing.  It all seems rather self indulgent, although I hope my writing style at least gives it an amusing slant that will encourage readers to press on at the very least with a grim fascination to see what literary holes I can dig myself into.

I suppose what I’m trying to achieve by this is to work towards putting my creative output into some kind of context.

Recently I’ve realised that having now lived on the Internet for something like fifteen years, I have gotten far to used to seeing art, video, and software from around the world that I absorb quickly and move on, rarely spending any time looking into the background of the work or the artists and programmers that have devised it.

Facebook and Twitter really don’t help in this regard as there’s an almost constant supply of interesting new content being shared.  Perhaps you, or others are more in-depth than I, but it would seem a common trend given the proclivities of the YouTube generation to spend their time on that one site, creating ever more dense levels of meta content rather than reaching beyond it.

These online services, and many others before them, are merely loud-hailers, allowing us to pass knowledge of the existence of this work around though completely devoid of context or history.  There seems to be a growing body of study suggesting that ‘hyperlinks’ are evil (in terms of how they effect the brain’s ability to absorb information: linear text (hey, like this big post!) is better suited for understanding, sorry Wikipedia).

It is my desire then to reverse this trend in myself and look at less things and find out more about them.  Unfortunately this is not always easy.  It’s often been remarked upon that there is a lack of information and documentation on the Quadratura site, and I have to agree.  Unfortunately we tend to rush onto the next project without properly mopping up the last one and creating a satisfying online experience of our work.  I’m trying to get better at this.

Here, on (or as) bigfug, where I can drawl on as long as I like about anything I like, I suppose I’m looking to explain the background to the work that I’m doing now, both the work itself but also the underlying processes, but realising that yes, it does stem from events in my life many years ago, so, gentle reader, I feel the need to inform you of these.

Fortunately, now this part is out of the way, the next post will hopefully revolve around the intended subject matter.  Probably exploring the psychedelic world of programming exceptions and just how small good ideas can turn into big bad ones that brandish knives and upset your mum.

I thank you for your indulgence and time.

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • Technorati
  • Twitter

Programming: tales from the dark lands

11 May, 2010 (18:20) | Programming | By: Alex May

At the age of nine I was into riding BMX bikes, magic, Lego, and programming my ZX81.

As the years passed I stopped riding bikes, gave up the magic, passed on my Lego, but the programming remained a constant interest, although probably fixation would be a better word.

Almost thirty years later and I’m still programming pretty much every day, as I have for all these years, and more importantly, still learning, still refining and exploring this ever shifting digital world.  I am very lucky to have my vocation be my passion.

I’ve had the privilege to work on a diverse range of projects during my professional years.  So diverse that a few individuals have brazenly inferred that I’ve embellished or even made some of it up.  Actually, this isn’t even the half of it.

I don’t tell people about the time I modelled the solar-system in its relative real-time position, and utilised topographical data so you could fly around the sun and land on the top of Mount Everest (years before Google Earth), or the three years I spent deconstructing programming to the point of finally glimpsing it’s true face: that code and language is transitory and almost irrelevant, rather interface is everything.

I don’t tell people these things because they sound like weird telegraph messages from dark unexplored continents, and in reality that’s not so far from the truth.

Carrying on the explorer allegory, my intense preoccupation with travelling these lands of code means there are things in life that I have missed out on: school was an imposition, good friends have been ignored, loves have been lost, and finances have sometimes been rocky, but to close your eyes and see the entire crystalline structure of massive code systems in your mind, data as light glinting and pulsing along threadlike pathways, spun from so many years experience of trial and error, is a sight as beautiful as anything I have seen in this world.

Try telling that to someone in a job interview!

Or, in fact, just about anyone…

It may be a factor of age, since I’m going to hit the oft feared way-point of 40 in a few years, that I’ve been doing a fair bit of introspection and looking back.

I remember in my 20’s assuming that, given my intense propensity for coding, that I would reach programmer burn-out at around 30-35, and I almost did.

Those three years spent dissecting my craft near did me in as I reached a point of immobilisation where every line of code was analysed and broken apart.  Whereas previously I could be churning out hundreds of lines of code per day, at the end of that time I was down to less than 10, on average.  When I had come face to face with the knowledge that finally I knew what programming really was, and how incredibly difficult it actually is to do it “properly”, I teetered on the brink of giving it all up there and then.

Fortunately I clawed my way back from the edge and have managed to take some of what I have learned during that time and made it work without it being all consuming.

I also remember thinking that I probably wouldn’t be as good a programmer when I got older but this turns out to be untrue, unless my brain has softned to the point that I just think that it is untrue.  Certainly I can’t quite do as many 20 hour days of coding in a row as I used to; I’ve had to make some concessions there, but I know so much more, my vision is clearer, and my perception sharper.

It is from this looking back that I realise something about my long and ongoing travels that saddens me, namely that I rarely share the tastiest exotic fruits of my exploration.  I’ve released a fair amount of software and services in my time, written articles, a book, even given interviews and the odd talk here and there, but I’ve never felt that the point of all this has been communicated.

Not for one instance would I assert to being a great programmer; there are many smarter and more accomplished people out there than me, though I do believe I have a natural affinity with the processes involved, and a fairly unique set of experiences and interests, mainly born from the possibly worrying amount of time I have devoted to the study of these areas.

I guess it comes down to knowing what you want to communicate and that has always been unclear to me.  A great deal of programming is about specifics, solving the problems at hand while still (hopefully) keeping a watchful eye on the big picture.

I’m sure many fellow programmers have sighed deeply, as I have, at job interviews or questionnaires from agencies filled with queries about language syntax.  Strangely, these same people don’t take to well to being berated over the phone for 20 minutes about how pointless a strategy this is and how I refuse to take their test as I wouldn’t hire a programmer on the back of it even with full marks because anyone capable of reading could find the answer out on the net or via a book.  On high horse: check.

My point being that specifics are transitory and learned and then, more often than not, forgotten until the next time they are needed, at which point we learn them again.  Languages come and go, API’s come and go, platforms come and go, syntax changes; all that detail is shifting sand between tectonic plates.

So, it doesn’t feel right to try and communicate specifics, and besides, they are often only useful to a single programming language.

If we ignore specifics, then we are surely talking about higher level constructs.  I would like to be able to offer something that is just as valuable to a Python programmer even though I’ve never touched that particular dialect.

The frustration is how to usefully convert these constructs to something concrete and teachable.  I found it interesting when the whole agile/pair-programming/scrumm/etc work systems started appearing.  For me, I find them all annoying and trite, but I recognise and fully admire their common goal: to attempt to provide a working structure for less experienced programmers by more experienced programmers to guide them towards being good experienced programmers.

Also interesting is the growth of source control systems almost being work systems in themselves.  Despite their flexibility and different approaches, they still inherently dictate a certain way of working, which is why, it seems to me, there is so much discussion and heated arguments over which is ‘best’.  If we just wanted a system to store and track source code changes why would we have these competing systems?

And this guides us neatly to a fundamental point, namely that programmers love to reinvent the wheel.  ALL THE TIME.  I do it, you do it, we all do it.  ALL THE TIME.  There are countless algorithms that were devised and coded decades ago that continue to be reimplemented for each language, for each API, for each platform, for each operating system, and then multiple times for each.

Imagine, for a moment, a strange alien world where vast reams of code are written once, perhaps in some kind of weird meta language that can be recompiled for various hardware configurations.  Perhaps there are bugs, perhaps there are improvements in speed and accuracy that other programmers will fix and implement, but all programmers have full access to this repository and these weird beings all feed into it, freely reusing as much as possible.

How much more advanced would their computer society be than ours, if both worlds started at the same time?

There are many reasons we do not have, and will not have, this rather simplistic utopian vision within our lifetimes.  The commercialisation of computing is one of them, basic human nature is another, neither of which I could pretend to able to address, but there is something that I can pick up on, which is, possibly unfortunately, they very thing I found out at the end of my three year voyage to the ends of code.

Fundamentally, think about the interface to your code, not the code itself.  We know what the code has to do, whatever language it’s in, whether it does it correctly or not either from bugs or just plain errors in implementation.  The code can be changed easily, changing the interface is generally termed refactoring, and generally takes longer than you think.

Once you call either your own functions or others in the platform or API that you’re building against, you have created a solid dependency against that interface, both in data types and format, that may well propagate further up, inferring limitations on the interface to your code.  Like it or not, believe it or not, your code is locked in and is already ageing towards its inevitable expiry.

In some languages there exist constructs to address the data type issue, such as C++ templates, but they are processed at compile time, and while they can implement similar data type concepts, you can’t substitute any old combination. They just tend to lock your code in even deeper.

The question then, is it possible to break the inherent limitations of code interfaces while retaining good performance, thus making code reusable in a much wider scope, and this is what I explored.

To avoid keeping you on the edge of your seat: I don’t actually believe it is, at present, given the tools and underlying hardware at our disposal, but I did come up with (and implemented) a design that broke apart the idea of what an application is to a single, common bootstrap executable that would then load a version constrained hierarchy of libraries that provided all the functionality of the program.

There were still dependencies across libraries, but the depth of the dependency was limited to a certain version of a known interface from a library that is only concerned with one specific area of functionality within the program.  The key being that several versions of the same interface could co-exist within the same process, and more importantly, these interfaces could be usefully shared across different applications.

By following this design it helps focus your mind on creating interfaces that can be used in a much wider context than just the one program you’re currently working on.  It also takes a lot of time and care to plan the interfaces and underlying code carefully to avoid creating dependencies whenever possible.

It’s because it takes so damn long to work this way that I realised that what I was trying to do was not really what C++ or any other language (and I researched a whole bunch of them) is designed to do; I was imposing a system upon them.

While this may all seem like a somewhat fruitless endeavour, it taught me one important thing, it inferred a metric to judge my own code and that of others, namely: any programmer can write great code, it takes a great programmer to create a great interface.

Mine are pretty good, most of the time, but even after almost three decades still not great.  How’re yours?

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • Technorati
  • Twitter

Digital Economy Act: Response from MP Norman Baker

27 April, 2010 (12:45) | Uncategorized | By: Alex May

Last week I wrote to my MP, Norman Baker (LibDem, Lewes), asking him why he wasn’t present at the readings of the recently passed Digital Economy Act.

From my experience, Mr Baker is one of the good ones.  He works hard on behalf of Lewes, is active in the commons, always replies to questions that he’s sent (this is the second time I’ve written to, and had a response from him), and he gets my vote because of his continued diligence, rather than for the party he’s part of.

I explained to him that as someone who has worked their entire life in the ‘digital economy’, and had been directly subjected to the effects of both piracy and copyright infringement (with subsequent loss of earnings), I firstly didn’t see how the act would have helped me (as a small company/independent software developer), and secondly, that I would always much rather have a free and open Internet without centralised government control, despite these inherent side effects.

I believe that piracy and copyright infringement pale in light of the Internet being the most powerful communications platform since the invention of the printing press.  It’s importance is almost on a human evolutionary scale.

Well, technically yes, there has always been censorship and copyright/church/state control since day one of print, too.  Perhaps this is just a short, very special time we’re all living through with unprecedented freedom of communication (at least in parts of the world) and it’s an inevitability that we will slowly watch the Internet being fenced off and locked down before our eyes.  See, now I’ve both digressed and depressed myself.  Sorry, back to the point!

Today I received a signed letter from Norman Baker in the post: (formatting his, any spelling mistakes mine)

Dear Mr May,

Thank you for taking the time to contact my office with regards to the Digital Economy Bill, which has now passed into law.

I would certainly have liked to have voted on the Bill, but as I am sure you will be aware, both the Second and Third Readings were scheduled at very short notice, with the Third Reading in fact taking place at around 9pm on Wednesday 7th April.  Unfortunately, by this time I was already committed to a prior engagement within the constituency, so was unable to attend.  However, I would stress that the Lib Dem position has been far from simply reactionary to the Bill’s passing.  Indeed, my Lib Dem colleagues opposed the Bill, which was eventually passed by 189 votes to 47.

Furthermore, the government’s amendment to Clause 8, which gives it the power to block sites which are ‘likely to be used for or in connection with an activity that infringes copyright’, was vehemently opposed by Don Foster, the Lib Dem spokesperson for Culture, Media and Sport, and indeed the Lib Dem party as a whole.  However, Tory support for the government’s position allowed the amendment to be passed by 197 votes to 40.

Although my Lib Dem colleagues and I had felt that some action was needed to tackle illegal downloading in order to support the continuing success of our creative industries, and felt that it was important that many measures in the Bill that do not relate to illegal file sharing should go into law, we also held strong concerns, like you, that some aspects of the Bill would give too much power to the government to tackle copyright infringement.  In fact, at earlier stages of the Bill’s proposals (contained in Clause 17 of the original Digital Economy Bill) to give itself almost unfettered powers to act against copyright infringement.

Further, as a result of debates instigated and amendments passed by the Lib Dems in the Lords, the government’s original proposals relating to illegal peer-to-peer file-sharing were significantly improved.  As a result, no action to introduce “technical measures” (whether temporary account suspension, bandwidth throttling or whatever) can be introduced until:

1. soft measures (letter writing) have been used
2. an evaluation of their effectiveness has been undertaken
3. an evaluation of the need for, and likely effectiveness of, technical measures has been undertaken
4. further consultation has taken place
5. proposed legislation is brought before parliament for decision, and
6. there is an explicit assumption of innocence until proved guilty

However, we remain concerned that the amendment to Clause 8 will be too wide-ranging, and you can rest assured that we will scrutinise closely the application of this aspect of the Bill as it becomes law.

I enclose a copy of the contribution made by the Lib Dem spokesperson for Culture, Media and Sport, Don Foster at the Bill’s Second Reading on the 6th, which offers further elaboration of the Lib Dem position, and the concerns that were raised before the Bill’s passing.

I hope this is helpful.

Yours sincerely

Norman Baker

(Followed by a further 8 pages of House of Commons Debates about the bill)

So, it doesn’t quite address my original concerns, but I certainly appreciate the considered response!

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • Technorati
  • Twitter

Latest PatchBox Pictures: Geometry Shader Shadow Volumes

21 March, 2010 (03:56) | PatchBox | By: Alex May

I?ve been getting into writing CGFX geometry shaders!  The following couple of pictures are generated inside PatchBox by passing in a simple flat grid of triangles.  The geometry shader turns them into cubes and calculates the shadow volumes on the fly.  Perhaps not the fastest solution, though my (getting long in the tooth) 8800 can still animate 900 cubes at 60fps.

PatchBox-Geometry-Shader-Shadow-Volume PatchBox-Geometry-Shader-Shadow-Volume-02

These development pictures are rather lovely in themselves, and may end up being an installation, though I have further, much more complicated, plans for all this.

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • Technorati
  • Twitter

Source Code Layout

13 December, 2009 (15:25) | Programming | By: Alex May

There have been several attempts to standardise the layout of source code.  This is a good thing ? if everyone used the same style we would spend less time trying to figure out what a slab of code actually does, free of layout inconsistencies and interpretations (and besides, everything would be clearly commented anyway, wouldn?t it).

The fact that there are several styles to choose from is an immediate oxymoron.  Some styles were introduced because of limitations of the programming environment, such as writing code in 80×24 character screens ala DOS or Unix.  Given such limited screen size, it would seem like a good idea to ensure the maximum amount of ?code? is on-screen, rather than ?wasting? lines with single brackets and the like.

An example in C of ?The One True Brace Style?, a variant of K&R:

if (x < 0) {
    printf("Negative");
    negative(x);
} else {
    printf("Positive");
    positive(x);
}

According to Wikipedia, where this example comes from, both the Unix and Linux kernel are written in this style.

Now, I don?t have a problem with such styles per se, especially if they are born from visual limitations such as low resolution displays, but given that the majority of programmers these days, including myself, will be working with high-resolution monitors, such condensed styles seem visually anti-productive, as we shall explore.

It should be noted that other standards, such as K&R, Allman, KNF, and Whitesmith?s, provide a subtle range of more readable variations, though it is this programmer?s belief that they all still somehow miss a deeper level of visual presentation that can make code even more understandable and can be an actual aid to debugging.

What follows is a (somewhat terse) description of my own style of code layout that I?ve developed over the years.  It is very visually based, which tends to be how my brain works.  It?s also somewhat rooted in speed-reading techniques, where one develops the ability to take in large amounts of information without the struggle of reading every line of text.

It is also not without it?s own problems, as discussed at the end.

The standards mentioned above have generally been born out of the C world, however the following can be applied across a wide range of languages such as C++, PHP, Java, JavaScript, LUA, etc.

Indentation

Taking the C example above, we can re-write it like so:

if (x < 0)
{
    printf("Negative");
    negative(x);
}
else
{
    printf("Positive");
    positive(x);
}

As with Allman style, the curly braces are matched up with the control statements, which serves to provide a visual clue that there is going to be some kind of optional or repetitive action to be applied to the indented blocks of code.

We can see the two blocks are indented by the same amount and the ?else? statement is prominent between the two blocks, all clues as to the purpose of this code.

At a glance we can quickly summarise these lines like so:

if ( ... some condition ... )
{
    ... do some stuff ...
}
else
{
    ... do some other stuff ...
}

This trivial example introduces an important concept: if the control statements are obvious we can vertically scan the code quickly and get a feel for what it?s doing without needing to get bogged down in implementation details we don?t wish to concern ourselves with.

It is important then, to use braces even with single statements:

for( int x = 0 ; x < 10 ; x++ )
{
    printf( "x = %d\n", x );
}

rather than

for( int x = 0 ; x < 10 ; x++ )
    printf( "x = %d\n", x );

Whitespace

To further this concept, I tend to use whitespace very differently to any of the C standards.  For example, I?d write the original example as:

if( x < 0 )
{
    printf( "Negative" );
    negative( x );
}
else
{
    printf( "Positive" );
    positive( x );
}

If the control statements are can be scanned vertically, the actual statements should be able to be scanned horizontally.  By ensuring there is whitespace around every variable or value you make it easier on your eyes to pick out the parts of interest.

It is now also clearer that we are using the variable ?x? in the negative/positive function calls.  By introducing whitespace we can see what values look visually alike rather then necessarily having to read them.  If I had accidentally typed ?negative( y );? instead, it would be much more obvious than if it had been all bunched up as in ?negative(y);?.

You may also notice I removed the whitespace after the ?if? statement, for me this ties the horizontal bracketed condition to the ?if? rather than leaving it floating unconnected.

Changes in Language Style

The above guidelines work well for most general code but these days I?ve been encountering some challenges to my carefully honed model, especially within PHP and JavaScript where anonymous functions or large arrays of information need to be passed to other functions or methods.

Take something like this, from Symfony?s form system:

$this->setValidators(array(
    'name'    => new sfValidatorString(array('required' => false)),
    'email'   => new sfValidatorEmail(array(), array('invalid' => 'Email address is invalid.')),
    'subject' => new sfValidatorChoice(array('choices' => array_keys(self::$subjects))),
    'message' => new sfValidatorString(array('min_length' => 4), array(
        'required'   => 'The message field is required',
        'min_length' => 'The message "%value%" is too short. It must be of %min_length% characters at least.',
    )),
));

If we are to apply a similar layout as described above, it will end up as something like this monster:

$this->setValidators
(
    array
    (
        'name' => new sfValidatorString
        (
            array
            (
                'required' => false
            )
        ),
        'email' => new sfValidatorEmail
        (
            array
            (
            ),
            array
            (
                'invalid' => 'Email address is invalid.'
            )
        ),
        'subject' => new sfValidatorChoice
        (
            array
            (
                'choices' => array_keys( self::$subjects )
            )
        ),
        'message' => new sfValidatorString
        (
            array
            (
                'min_length' => 4
            ),
            array
            (
                'required'   => 'The message field is required',
                'min_length' => 'The message "%value%" is too short. It must be of %min_length% characters at least.',
            )
        ),
    )
);

This introduces are mildly unpleasant side-effect where functions, constructors, and arrays are being laid out like control statements.  Also, nine lines of code now take up almost a whole page! Now I?ve come full circle, back to needing some hybrid condensed version to adjust the code to layout on-screen ratio.

Oh, what to do?  Perhaps a bigger monitor?

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • Technorati
  • Twitter

LambdaMOO data structures in MySQL

23 November, 2009 (16:30) | Programming | By: Alex May

Now and again I get entirely sidetracked from my usual day to day programming madness into some other temporary realm of programming madness.  I find it good for the soul.

There was a good reason behind my most latest foray, however: I wanted to take a quick refresher course in the latest PHP, Symfony, and MySQL updates to keep my hand in.

So I thought I?d set myself a little project.  Which quickly got out of hand.

There?s a couple of games from the old BBS era (hence the spawning of the last post) that I actually miss playing, the main one called ?Hack & Slash?, written by Robert Hirst, although he?s ported it to Unix and it?s now called RPGD).

I thought it could be fun to port it to a web based game, so I sat down and started hacking away.

After a day of frenetic keyboard abuse, I had a Symfony based Finite State Machine, the character classes, monsters, and game objects in place, and the mechanics of fighting (albeit without magic spells, for which I wanted to introduce a new class hierarchy for) and things were progressing rather well.

The way I was writing the interface was very much mirroring the original game just with clickable links rather than needing to type in instructions.

My aim of spending a weekend getting some kind of proof of concept out of the door was then flummoxed by another, stronger train of thought.

I?d got the basic menu structure in place, which in part kind of models a small village (with shops, a fighting arena, and the like) that you can ?walk? around and buy things and generally supplement your character.  I started to imagine what this village might look like, and whether the layout in the game would be at all like how a real village might organise itself as it grows organically.

Of course nothing good can come of thinking along such lines but I continued undaunted with a cup of tea and a pad of graph paper.

MOO Time

What I realised is that I wanted to be able to create and add features to the game over time, rather than having to write the whole thing before putting it online.

There is a well established model for this type of game.  It is called a MOO (or multi-user dungeon, object-orientated) of which one of the most developed and long running is LambdaMOO ? you can still play it online.

A MOO shares the same text based interface as RPGD, though the user can enter freeform commands rather than being limited to a small list of commands.

I started thinking about how both systems could be combined, and it seemed feasible to create the game-play of RPGD within the structure of a MOO using its internal programming language, while also gaining the ability to build the village on the fly as and when I found a spare 15 minutes.

And, let me just mention at this point that I have no reason to believe anyone might actually play this game, I?m just enjoying the mental challenge of designing it :)

It would also be very interesting, I continued to muse, if that rigid interface structure could be broken up further from a single session (both games assume a user is connected via telnet or similar) to a state based game, and utilise a database as the backend storage (LambdaMOO keeps the whole world in memory, RGPD keeps all the objects of the users session in memory).

This would enable web, telnet, or even mobile access to the game world, and create a nicer server application that could be written in something like PHP and be deployed on a standard web hosting package, rather than needing to run a server side program (as both games required).

There was some further thinking about completely redesigning the web interface to something very flashy and dynamic to replace as much typing with clicking as possible, but that?s for another time.

Let?s Hurt Me Some MySQL

Leaping back on the keyboard, I started to create a database structure that very closely mirrored LambdaMOO?s internal structures.

I quickly came across the rather unique requirements that the MOO required for its world:

  • Everything in the world (including players) is an object and is descended, except for the top level object, from a parent object
  • Each object has properties, either inherited from its parents, or defined on this object
  • Each object has verbs (or actions), also inherited or defined

Each object, property and verb also has a set of permission bits that control how properties and verbs can be controlled on objects, and how objects themselves can be structured and controlled.

While each object having a parent is obviously a simple foreign key, the inheritance model proved to be a little more complicated.

Remember, the original system stores the entire world in memory so it can quite easily dance through its internal data structures with simple controls on locking parts of the object tree to avoid more than one thread changing things at the same time.

We could of course use table locks in MySQL for similar control, but it was my intention to create an atomic system that could be quickly and safely updated from a request session.

Bad Programmer, go to your room!

Now, I like to think of myself as quite a good programmer, but sometimes I get it quite, quite wrong and I?d like to share this with you now.  As they say, success is a lousy teacher.  (This doesn?t follow that a lousy teacher is a success, unfortunately, badoom-tish?)

I thought a good idea would be to duplicate all the properties and all the verbs on each descendant object.  The reasoning behind this being that SELECT?ing an object should be fast as it would happen ofter, whereas object/property/verb creation and destruction would happen much less often, and by duplicating all that data, it would be a simple join between the tables.

To facilitate the inheritance, each property and verb would have:

  • An object id, the object whose property this instance belongs to
  • A parent id pointing to the same property/verb in the object?s parent
  • A source id pointing to a parent property/verb that actually defines the property (explained below)

So, if we had a very simple structure like this:

Object #1 (has a property called ?foo? that is equal to ?bar?)

|

Object #2 (has a property called ?spa? that is equal to ?fon?)

|

Object #3 (has a property called ?foo? that is equal to ?notbar?)

The properties for each object would be like this:

  • Object #1
    • foo = bar (object = #1, parent = null (no parent), source = null)
  • Object #2
    • foo = bar (object = #2, parent = #1, source = #1)
    • spa = fon (object = #2, parent = null, source = null)
  • Object #3
    • foo = notbar (object = #3, parent = #2, source = null)
    • spa = fon (object = #3, parent = #2, source = #2)

Then reading an object and its properties is simply:

SELECT * FROM objects, properties, verbs WHERE properties.object = objects.id;

Nice.  Then to update a property (on Objects #1 and #2, Object #3 still overrides)

UPDATE properties SET value=?foo? WHERE source = #1

This is all going swimmingly.  But what about adding a new property or deleting properties, or even adding objects.  Well, then it all goes a bit wrong as you need to INSERT or DELETE instances of all the properties and verbs from all the parent objects, and possibly the descendants too.  It gets very messy and is certainly not very atomic.

Building The Nest

So I had a break, another cup of tea (I am British, don?t you know), and a meander around the InterWebs to see if there was a better model I could utilise for my own devious ends.

I found a good one, first described by Michael Kamfonas, and later coined as ?nested sets? by Joe Celko.

There?s a nice article with lots of example code on the MySQL dev site.

Go on, read the article, I?m not going to describe it here and if you don?t know the technique, you should!

Welcome back.  So now I have a structure that looks like this.  This schema is in Symfony format but should be fairly simple to understand by all (apart from the word wrapping, sorry):

rpg_object:
  _attributes:   { phpName: rpgObject, package: lib.model.rpg }
  id:
  parent_id:     { type: integer, required: true }
  left_id:       { type: integer, required: true }
  right_id:      { type: integer, required: true }
  scope_id:      { type: integer, required: true }
  owner_id:      { type: integer, foreignTable: rpg_object, foreignReference: id, required: false, onDelete: cascade }
  name:          { type: varchar(30), required: true }
  location_id:   { type: integer, foreignTable: rpg_object, foreignReference: id, required: false, onDelete: setnull }
  programmer:    { type: boolean, required: true, default: false }
  wizard:        { type: boolean, required: true, default: false }
  r:             { type: boolean, required: true, default: false }
  w:             { type: boolean, required: true, default: false }
  f:             { type: boolean, required: true, default: false }
  is_player:     { type: boolean, required: true, default: false }

rpg_prop:
  _attributes:   { phpName: rpgProp, package: lib.model.rpg }
  id:
  object_id:     { type: integer, foreignTable: rpg_object, foreignReference: id, required: true, onDelete: cascade }
  owner_id:      { type: integer, foreignTable: rpg_object, foreignReference: id, required: true, onDelete: cascade }
  parent_id:     { type: integer, foreignTable: rpg_prop, foreignReference: id, required: false, onDelete: cascade }
  source_id:     { type: integer, foreignTable: rpg_prop, foreignReference: id, required: false, onDelete: cascade }
  name:          { type: varchar(20), required: true }
  r:             { type: boolean, required: true, default: true }
  w:             { type: boolean, required: true, default: true }
  c:             { type: boolean, required: true, default: true }
  value:         { type: longvarchar, required: false }

rpg_verb:
  _attributes:  { phpName: rpgVerb, package: lib.model.rpg }
  id:
  owner_id:      { type: integer, foreignTable: rpg_object, foreignReference: id, required: true, onDelete: cascade }
  names:         { type: varchar(255), required: true }
  r:             { type: boolean, required: true, default: true }
  w:             { type: boolean, required: true, default: true }
  x:             { type: boolean, required: true, default: true }
  d:             { type: boolean, required: true, default: true }
  arg_preposition:    { type: tinyint, required: true }
  arg_direct:    { type: tinyint, required: true }
  arg_indirect:  { type: tinyint, required: true }

With this structure we can defined properties and verbs on objects and get the whole cascading, inherited tree with a single MySQL query.

Also, within Symfony, there?s a plugin to handle nested set records.

We can add and delete objects quickly, change their parents, and we don?t need to copy verbs and properties (and cascading will delete the properties and verbs on any object).

I should probably give some examples but this post is getting quite long already and I?m really jonesing for another cup of brown joy.

So, where?s the game, you ask!

Well, it was coming along but then I started writing an interpreted JavaScript type language within PHP to handle the MOO scripting (and that?s for another post) and I just plain ran out of time.  Anyway, the nested set thing is the important bit!

Ah well, some fun, but back to the day job!

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • Technorati
  • Twitter

Revisiting the Bulletin Board System from a local community perspective

23 November, 2009 (14:46) | Programming | By: Alex May

As you may know, I have a bit of a history with text based online services (writing Zeus BBS amongst other things) and I?ve been sporadically re-investigating that world over the past few months to ascertain whether there is any aspect that has relevance in today?s Internet enabled society, other than a heady nostalgia trip.

Most of the key features of bulletin board systems have indeed been entirely replaced.  For example:

  • The provision of local downloadable files has been entirely surpassed.
  • Messages (local and FidoNet technology distribution) have been replaced by email, online bulletin boards, newsgroups, mailing lists etc.  The ability to replicate messages across a network and for a BBS to provide an access point to those message bases would seem to have use within linking intranets or other closed systems but has little relevance in the wider public environment.
  • Some games, and other online ?doors? still have an active community using them, though any that are actively developed seem to be moving towards web or custom client interface rather than a text based one and who can blame them!

With just those top-level points I was able to write off all of the three years work I had put into Zeus, let alone the fact that it was written for the Amiga and the work involved in porting it (yes, I considered it), even if there were any interest in such a thing, would really not be worth the effort.

That was a bit sad, but hey, suck it up and let?s move on.

I did however uncover one aspect of running a BBS that has not quite been explored or exploited as fully by the nebulous Internet: leveraging and enhancing local community.

This is a bit of a sweeping statement but allow me to expand on it with a bit of history:

Because of the phone call pricing in the UK when BBS’ were in their heyday, it was only realistic to call local systems after 6pm.  During the week much higher rates applied in the mornings, dropping down a bit in the afternoon, and then cheaper still between 6pm and 7am (could be wrong, haven?t checked), with weekends being at the lower rate all day.  Also, to complicate matters further, calling local numbers (within a certain distance) was cheaper, and beyond that distance it again got much more expensive.

There was many a case (myself included) of people being floored when receiving their phone bill for the quarter after discovering the world of BBS?.  I think my first bill was about ?400.  Ouch.  Stories of people receiving much higher were commonplace.  How we all loathed BT.  And Americans (only because they got free local calls in the US, lucky buggers!)

Once the pain of that initial shock had worn off, and if you (or your partner/parents) hadn?t thrown the modem out of the window vowing vehemently never to use it again, it was a case of finding the local BBS? and limiting most of your activity to those, with only the occasional visit to systems running in distant and exotic locations.  Like London.

It should be noted that some unscrupulous types actually did manage to get free phone calls using a technique called Phone Phreaking but they?re obviously evil and we won?t dwell on them.

This imposed costing structure actually had quite an unforeseen benefit to UK BBS? on the whole.  While we wouldn?t receive as many callers as our state-side cousins, the ones that we did tended to be from the immediate local area, which meant that communities developed both on and off the BBS.

It was a grassroots type of community that was happening all around the world.  There were local meetings (invariably down at some backwater pub), regional meetings (again, usually a pub) and even international meetings (never went to one but I assume it was at a big pub)

And, to finally rejoin the thread of my initial statement about local community, it has not yet widely been accomplished via the Internet, for two reasons:

  1. You can (generally) access any site in any part of the world instantly and, on the whole, anonymously (most BBS? required that you registered before you could access them)
  2. ?Social Networking? sites, or most services run by large companies approach community on a top-down model, which is fine ? to a point ? but doesn?t create the same experience as a bottom-up community such as BBS? had.

As an example of this second point, take Facebook for instance.  It?s all about your personal network.  Well, it seems you have a choice: either to restrict it to people you?ve met (which is how I prefer to use it) or else gather as many ?friends? as possible for whatever personal or business reasons you may have for doing so.

Now, there is a general Brighton page/group for all the people who say they live in Brighton (I don?t, but Lewes isn?t an option so Brighton is my closest choice ? that?s a big fail right there for me).  But that?s it.  There?s no structure beyond that within that single grouping.

Ah, but Alex, says you, there are lots of other pages and groups that you can join for your specific interests, or create your own and stop whining.

But, says I, these are all first-class pages and groups that have absolutely no relationship to each other so there are competing groups on the same subjects and who knows what fevered ego?s lurk in those admin positions.

This isn?t common to Facebook either.  The top-down model of a community can only go so far.

By now, you?re probably waiting for some grand payoff after reading this long article but sadly I don?t have one for you.  Sorry.

I am however still ruminating on this issue and perhaps it will spark a bit of discussion.

I think there are still important insights to be squeezed out of user interaction in the BBS age.  These people put up with fairly basic interface and (some, not all) got a lot of rich life experience out of it (I saw this again in even sharper focus when working on Wapscallion, an even simpler interface!)

Anyway, this wasn?t the post I started writing!  On to that now?

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • Technorati
  • Twitter

Twitter Updates for 2009-11-22

22 November, 2009 (11:21) | twitter | By: Alex May

Powered by Twitter Tools

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • Technorati
  • Twitter

Twitter Updates for 2009-11-15

15 November, 2009 (11:21) | twitter | By: Alex May

  • Up 'til 5am 3D scanning/projecting (added framing, inpainting, and smoothing – real tasty!) and woke with a bit of a cold – great reward #
  • All booked in for my little sojourn down to Bath tomorrow. Hurriedly finishing off the video displacement software I'll need! #
  • ffmpeg is pretty nifty. Just run up a cross-platform audio/video processor for video displacement in few hours. #
  • Back from a successful, two day, 3D scanning session at Threeways School in Bath! Is a little early (but dark) – think I've earned a pint! #
  • Quadratura's lovely new show-reel: real-time interactive video art – having an event/party? You need this: http://bit.ly/40Bg6w #
  • Mandelbulb: The Unravelling of the Real 3D Mandelbrot Fractal http://bit.ly/1Hpx1r (pfft, "mandelbulb"…) #
  • @ianvisits Google bought FeedBurner, didn't they? in reply to ianvisits #
  • @nlomioni Yes, am on wave but it's pretty much like this at the moment: http://bit.ly/FMr2K in reply to nlomioni #
  • Awoke with 'Catch The Sun' by Doves and The London Bulgarian Choir stuck in my head – first choice on today's jukebox: http://bit.ly/42Jncx #
  • Frantically trying to turn the tide of email. Also looking for venue in Brighton to show our interactive video art. #
  • While everyone is playing Call Of Duty, I'll be playing this: http://bit.ly/4hcTUp #
  • @Escapation Would love to. Any suitable events coming up? in reply to Escapation #

Powered by Twitter Tools

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • Technorati
  • Twitter

Twitter Updates for 2009-11-08

8 November, 2009 (11:21) | twitter | By: Alex May

  • About 60% through shifting the fugStreaming code base over to using Boost – simpler code and more cross-platformy (also added compression!) #
  • fugStreaming: memory/UDP streaming code ported, just the receiving side of TCP to redo #
  • Four types of background subtraction implemented – should be enough to cope with most lighting conditions, I hope! #
  • Could still use a high resolution thermal camera or one of those nifty depth cameras. If anyone wants to give me one, thanks :) #
  • On track for our interactive mini-exhibition on Wednesday. Possibly even a little ahead of schedule! May have rest of the evening off, yay! #
  • @AXEL2200 Yep, I'd like a wave invite, if you'd be so kind. #
  • @dylanparrin A wave invite would be lovely, if you have a spare one #
  • @dylanparrin Lovely, thanks very much! in reply to dylanparrin #
  • Disappointed with the results of trying to stream 720×576 uncompressed video over UDP *locally* – was easier when we all used 320×240… :) #
  • @alpaykasal Oh, really? Well, I think I just messed up the code by making it cross platform <sigh> back to testing… in reply to alpaykasal #
  • @collada Simplygon 2.8 – simplify and optimize complex 3d COLLADA meshes – http://tinyurl.com/yb6zt7s – WANT! in reply to collada #
  • Feel a bit crap. Too many 16 hour days in a row. When did I last have a day off? My fingers are actually tired. Come on Al, keep it together #
  • Writing the copy for tomorrow's handouts. Time to stick on some Philip Glass starting with Kundun, then Koyaanisqatsi. Biddily-biddily… #
  • Copy for the handout is written and off to Martin for a peruse. Time for a cup of tea, bit of toast, then serious multi-projector testing! #
  • @FabricaGallery Creepy… Do you think they're trying to form a simple conciousness? You may want to have your hand near the power switch! in reply to FabricaGallery #
  • @DAVID_LYNCH This weekend I built a video installation with thousands of falling points of light you can catch in your hand. 0 LOP albums :) in reply to DAVID_LYNCH #
  • Nice: 90 Year Old Example of Forced Perspective Photography – http://bit.ly/EUDhL #
  • All five of the interactive video pieces are done, tested and optimised. Now down to PatchBox to perform it's special magic! #
  • @nlomioni Or send them to me – I think you've had enough… in reply to nlomioni #
  • Hey kids, you know what you need when one homography just isn't enough? That's right – A DOUBLE HOMOGRAPHY!!! Larks… #
  • Great, another 4am finish. Had some issues with trying to do weird things to homogeneous coordinates. Bypassed for now. All works. Sleep… #
  • 4.5 hours sleep but adrenaline is running high: tonight we d?but our new interactive video wonders. Time to pack gear and head to London! #
  • Last night was excellent! World, you have *got* to see this stuff… #
  • @Escapation Heh, on the train with 2 hours of footage. Should have something up in a few hours! in reply to Escapation #
  • Since my last tweet I have fallen very foul of Lewes Bonfire. Currently wearing a black suit, 3/4 length burgandy coat, and lipstick. #
  • Right, back in the real(ish) world. Got my Google Wave invite today, no time to play right now, unfortunately, got video to edit! #
  • One of Quadratura's new interactive video art installations with Laben dancer Marja Koponen – http://bit.ly/1pitk7 #
  • @awhillas Yeah, it was lovely to watch – the whole gallery fell silent during this one :) in reply to awhillas #
  • Ah, finally Friday evening. Time for a little relax, a little beer, a little snack, and a little TV. Quiet one tonight, worky weekend ahead. #
  • Nice long sleep, cup of tea, then to work! Editing the full showreel from Wednesday's event. #
  • Another 'vote everyday' annoyance: Quadratura is entered for the Metropolis Art Prize 2009 – http://bit.ly/4vGv3y #
  • Had a short lived moment of joy where I'd reached 100 followers, then someone left and it's back to 99, ah well, showreel now encoding… #
  • New interactive showreel uploaded – should be available tomorrow. #
  • Ah, Sunday. A nice quiet day of geeking around with PatchBox's 3D scanner in preparation for an upcoming job this week. #

Powered by Twitter Tools

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • Technorati
  • Twitter

Page optimized by WP Minify WordPress Plugin