Monday, May 30, 2011

JavaScript, Functional Programming & UML?

I come from a Java background. As I have been learning JavaScript through my naked server experiment I find myself wondering more and more if "traditional" Object Orientation is the right approach to JavaScript. I now agree: JavaScript is the most widely deployed functional language.

When doing Java development we often share our thoughts via simple UML diagrams. They offer a nice visual way to share concepts and discuss ideas. They allow us to abstract the underlying complexity of implementation away. In short, to a Java developer, UML can be jolly useful.

But now I find myself wondering how I can use UML to describe any functional JavaScript that I might write. As a set of utility classes, perhaps? Regardless, it would seem that I am not alone.

In fact the kingdom of nouns extends far further than the shores of Java. It would seem that at some stage the software industry did truly believe the religious  decree that procedural programming was bad...

Tuesday, May 24, 2011

Mac sales: my curious lack of surprise

I've just seen that at this moment in time Macs are doing rather well: roaring ahead whilst PC sales are declining.

I normally build my own PC's, but recently decided that I want to change this pattern and actually buy one off the shelf.

My principle stumbling block is that I don't see why PC's have to come in big boxes: the last one I built runs dual monitors and fits in a shoe box.

However trying to buy a powerful compact PC seems to be inordinately difficult: the best that I have been able to come up with is either another Shuttle, pre-assembled, or the NRG Frost. Which now sadly seems to have been discontinued. Not helping in my quest is that I want to run some variant of Unix/Linux (Ubuntu preferably) on it, not Windows.

In short, here in Melbourne, Australia, I haven't found anything. Other than perhaps a new iMac. It's compact (beautiful), runs a Unix flavor, and comes with a "free" monitor: all for $1949, about the same as I was quoted for a headless NRG Frost.

The PC world seems to think that bigger = better, and that we all want to run Windows. With this broad stereotyping in play my next PC is most likely to be a Mac. So reports of Apples success don't surprise me in the slightest.

Monday, May 23, 2011

JavaScript notes: AJAX and redirects

More fun and games in my ongoing exploration of the world of JavaScript.

At the moment I am playing with AJAX, and found myself wondering how one would deal with calls from clients whose users were not logged in.

After a bit of experimenting I have found that if you do a plain redirect from the server, the browser happily follows it, but stuffs the result into the response passed to your beautiful AJAX code. So the user is left on the page that ran your AJAX, blissfully unaware of what is going on under the hood. This seems fair: the browser is leaving the decision making up to your AJAX code.

The problem being that if you write a nice filter to redirect all attempts to access protected content to a log in page, and your AJAX code is expecting a nice piece of JSON, there will be tears.

For my naked servlet experiment I have been forced to a slightly hacky solution: I have a created a servlet filter for JSON requests. If it finds that you are not logged in then it wraps the URL of the log in page in a piece of JSON and returns that. If the AJAX handler in the browser finds the redirectTo key in the returned object it promptly redirects the browser to the associated URL and does nothing more.

It would have been nice to handle the whole thing by popping up a log in dialogue (via an iFrame?) and not redirect the user to another page: but I am using Google App Engine as my servlet provider, and it would seem that the terms of service require me not to do this.

This doesn't seem very elegant. I am scratching my head to see if I can come up with a better way, but for the life of me, I can't see it. All hints and tips gratefully accepted!

Tuesday, May 17, 2011

How to learn a speech?


As a new Toastmaster member I have been troubled by the question of how to learn a speech. All of the other members I have seen talk seem blessed with wonderful memories, able to deliver impressive speeches flawlessly, without recourse to notes, powerpoint bullets, or any other apparent memory aid. 

I last gave memorised speeches at school – and I don't remember being particularly good at them, so I was worried about how I would manage.

But then a slow logical optimism through induction bit. The key word in that last paragraph was “all”. If every speaker was able to memorise their speech so effectively, then surely I should be able to as well? All that I needed to know was their techniques. Simple!

So I asked several of the speakers how they managed to learn their speeches. Dishearteningly, each person I asked gave a slightly different reply. “Repetition”, though, seemed to feature in every reply. They had practised those speeches a lot before actually giving them.

Seeking greater enlightenment, I turned to the Internet. It would seem that people deploy a wide number of techniques to learn speeches. There do seem to be some tried and true methods that shine through, though.

Joshua Foer, in his book, Moonwalking with Einstein, The Art and Science of Remembering Everything, describes one process, called “elaborative encoding”. Using this technique you would convert the paragraphs of your speech into a set of bizarre and engrossing visual images. Then you would order the images in a route through a familiar place, such as your house.

The images and the journey are far easier for you to remember. To you, your speech has just become a journey through Lewis Carroll's looking glass, rather than a pile of hard to remember words. This technique has been tried and tested through time. The Romans knew it as “The Method of Loci”.

Researchers have known since the late 1800's that spaced repetition leads to memorisation. They have shown that when we first learn something it is placed in the brains short term memory store. With time it either forgotten or moved to the brains long term memory store. The key to moving the material to the long term memory store, and to retrieving it from the long term memory store is repetition. Exactly what shone through from my earlier queries!

Distressingly, the timing of the repetition is important. For best effect you have to repeat the learning just as you about to forget it! The time between each “about to forget” moment grows with repetition. This is termed the “spacing effect”. What makes this distressing is that we each appear to have our own optimal intervals of learning. So we have to somehow work out what our own optimal intervals of learning are!

Research also shows that cramming does appear to increase our understanding of a topic – but it really doesn't help us remember what we understood.

All this repetition seems like hard work. But then, know that the harder you work to remember something, the more it will be sealed in your memory. Also note that you can't take current performance as an indicator of your future performance – you might have left that future repetition too late!

One suggestion for easing the hard work is to record back to back copies of your speech. Then simply play them as you fall asleep. On awaking replay the recordings of the speech. And there, voilĂ ! The speech, she is memorised.

For my icebreaker speech I used simple repetition to learn the speech. It worked well for me. In hindsight I need to work on determining my optimal spacing. For my next speech I am going start with the method of loci, and then switch to hard repetition. I might even try using headphones!

My unexpected takeaway from researching how to memorise a speech is that if we manage to become an expert at something, it's not because we remember our lessons or readings on the subject: it's because intense practice in that something keeps our memories fresh.

Monday, May 02, 2011

My sunny optimism...

A speech I recently gave:

I can do anything.

I honestly believe that with a little education, a little time and quite some practice, I can do just about anything a human is capable of.

I am no super man. This is simply an attitude. An attitude that I have eventually realised to be both a blessing and a curse.

A blessing because I have never had to rely on anyone one else when I need to get something done. I research, learn and just do it.

A curse, because I have never had to rely on anyone else when I need to get things done. So I have never had to learn the skill of motivating others – of getting them to help me achieve my goals.

I also have a deep desire to question and understand anything I use and play with.

For example, I can't just get into a car and drive it. I have to know that the wheels are connected to a drive shaft, that that's connected to a gear box, connected to a crank, moved by pistons. Powered by small explosions, created by a spark applied to a petrol and air mix, adjusted by pressure applied to the accelerator.

This need to question and understand is also both a blessing and a curse.

A blessing because if anything goes wrong with the things I use and play with I can fix them.

A curse, because I find it hard to let others fix my broken toys.
“You want to charge how much to repair this? Never mind, I'll do it myself!”

I also spend an inordinate amount of time trying to understand how things work.

These are my dominant characteristics. Oh – I also talk to myself more than I should.

How did I grow to be this person?

I believe that, like an insect trapped in slowly hardening resin, we are largely defined by the family and culture that we grew up in.

Let me describe my formative years and you can get a better understanding of the forces that have shaped me.

I was born in colonial Africa. My father, a structural engineer, was building bridges for the empire!

When I was very young, worried about the changing world around him, my father moved the family to the apparent security of South Africa. In hindsight, I wish he had just kept right on moving!

As I grew my father used me as his cheap labour. Under his direction, I restored cupboards, built sheds. I mixed cement, I laid bricks. I painted, I cleared drains. When I was a teenager I helped to renovate the family home, from the bottom of the foundations to the top of the roof.

My father was a practising Hindu, my mother, a Scottish Presbyterian. They elected to bring me up as a Roman Catholic in a country ruled by Dutch Calvinists.

Once week my father would gather the family in the lounge, and we would discuss religion and philosophy. From this religious cacophony I learned that there was no one truth. That we should question everything. That nothing is as it might seem.

My mother made sure that I had a constant supply of wonderful magazines. "Eagle" - who could forget Dan Dare? “The World of Wonder” “Tell Me Why”, “Look and Learn”, “Speed and Power” - They served as an antidote to the philosophy, bringing certainty to my world, explaining, sometimes in great detail, how things were made, and how they worked. I read my way through all of them, greedily.

It was only natural that at University I received a degree in Physics and Computer Science. In physics we continually strive to understand by building models of the universe, and then try to destroy the models, to prove them wrong. I loved Physics, but wasn't very good at it, so I became a software developer on graduating.

The apartheid regime that I grew up under forced compulsory national service on all young “white” men and so I served two years in the army.
When I idly mentioned this to someone in New Zealand they looked at me, gasped and backed away with "You're a trained killing machine!”

“NO!”I started to tell him. “ That's not me...” when I realised that I may just have missed the point of national service.

During that national service I spent a year patrolling the Namibian bush, keeping it safe. During the day I walked. At night I slept under the stars. With no mattress. No laundry. Carrying all I needed on my back. Occasionally meeting at pre-arraigned points to pick up food and ammunition.

That's were I first started to talk to myself. To give myself company out in that vast, lonely, veldt.

So like this insect trapped, my formative resin has now turned to amber.

I have to question and understand the tools and toys that I use.

With that understanding, given enough time and practice, I believe that I can do almost anything a human is capable of.

And I know that this, my sunny optimism, is both a blessing and a curse.