the awe of programming

“A few weeks into the class, there was a moment where I finally understood recursion. It felt so satisfying that my next thoughts went something like: ‘Wow, that’s awesome. I like that. I think I like computer science.'” – from betabeat.com

I can tell you that I know /exactly/ how she felt. I first “got” recursion (a programming method) after a summer scholarship in DCU, waaay back when I was in secondary school. It was really an awesome moment – understanding the possibilities of it felt like becoming one with the universe. It /really/ felt like that.

It felt “awesome”, and I mean that literally; I was in awe that such a simple concept could create such amazingly powerful solutions.

I’ve used recursion quite a lot over the years. In fact, only yesterday, I wrote a TSP algorithm that uses depth-first recursion to find the shortest distance between a number of points on a map. I’ve also used it for generating flow charts for food industry applications, creating breadcrumbs in website navigation, and for solving other seemingly unrelated problems.

As a father of two kids, I would love to have them take up my own path and become programmers, but I also know that you can’t “teach” the feeling of satisfaction/enlightenment that you get when you finally solve a tricky problem, and that feeling is very important to get early on if a child is to feel an urge to carry on.

Jareth (my son) doesn’t know it yet, but he’s getting Lego Mindstorms this year for Christmas. I already know he’s going to be a good programmer, based on his problem solving skills in some games, and some of the technic creations he’s built. Hopefully Mindstorms will let him have his own “ah hah!” moments early on, encouraging him to go deeper into programming as he gets older.

aw man…. 7 things

I thought I’d escaped this one. Everyone in the PHP world appears to have been “tagged” by now. Ken passed the buck to me, though, so I guess I’d better play.

Hmm… 7 things that people don’t already know about me? Hard task…

  1. I used to be into piercings, and if the piercing was common, then I wasn’t into it. Mostly, I was into surface piercings, and had a number of them down my sides and arms. I had planned on building a platform for a watch which would then be “embedded” in the arm, but never got around to it.
  2. I used to do “side-show” tricks, and have performed them on stage. This includes tricks such as “skewer through face” (horizontal – never got around to learning vertical), “human blockhead”, “face in glass”, eating glass, fire-eating, fire-blowing, and other weird stuff. Each of these is surprisingly safe when you know the trick.
  3. My first computer was a Commodore Vic 20 which I got when I was possibly 7 or 8. The highlight of that machine was writing (in BASIC) an animation of a bird which flew across the screen and “pooped” on a tank. I didn’t really consider that as “programming”, though – just playing. That machine was followed a year or two later with a Spectrum 48k+, which is where I really started – with 3d wire-frame graphics and text adventures. My first “real” computer was an Amstrad PPC640, where I learned QBASIC. My first CGI experience was writing applications (forums, etc) in C. That was followed by Perl, and finally I started writing php in about 1999 or so. Now I’m secretary of the Irish PHP User’s Group. Yay me! Oh, and Go Linux! I’ve been using Linux as my main OS since the 20th century as well.
  4. I can play a number of instruments. I played violin (rather, fiddle) for my school in a number of Feis Ceoil events and still have an electric violin that I pick up every now and then. I played Bagpipes in two separate pipe bands in Dublin – anecdote: in school, a music teacher was evaluating our playing of the tin whistle, and when he came to me, he saw immediately from the way I was holding it that I had training in a “pipe” instrument (uillean pipes and bag pipes are fingered similarly). I’ve played guitar in a few bands and like to get on stage at the Monaghan Blues Jam whenever I can (last compliment I got at one of them was “I like your playing – it’s /clean/ – very 70s”). I am looking for a classical guitar teacher at the moment. I also play keyboards, and have written music before (example).
  5. I’ve been vegetarian for more than half my life. This is not because of any hippy feelings towards animals. The two main reasons are 1) it’s disgusting to put dead animals in your mouth, and 2) it’s illogical, inefficient and cruel to kill animals for your food when you really don’t need to. I have no problem with people eating meat as long as they have no problems with me (and my family) not eating meat.
  6. I believe that the universe doesn’t really exist, but is a sort of shared illusion (look, it’s complex, ok!). Basically, it works like this – if the equation 2x-2x=0 is true, then you might consider that ‘x’ is a “real” object even though the sum of the equation is ‘0’ (ie; from nothing, comes something). This maps onto reality if you swap ‘x’ with ‘particle’, and ‘-x’ with ‘anti-particle’. I am always coming across situations where physicists discover this is true. Hawking radiation, for example, is an example of energy/matter spontaneously bursting into existence,, and is an exact analogy because you end up with ‘x’ (the radiation coming out of the black hole) and ‘-x’ (the radiation going into the black hole). Oh, and if you’re thinking it’s mad to think that ‘x’ could be real… in a computer game, all characters are “real” to each other, but not to an outsider looking in. In our case, we are those characters, and in an equation, each element is one of those characters. In the context of the equation/universe, all parts are real relative to all other parts, even if from the outside, they’re not.
  7. I used to do contact juggling. In fact, I founded the biggest contact juggling website. My son, Jareth, is named after David Bowie’s character from The Labyrinth where the goblin king (with the help of Michael Moschen) does some contact juggling (called “crystal ball manipulation” in the credits). I even wrote a book on the subject.
  8. Everyone in the world appears to have been tagged for this already, so I won’t bother tagging anyone.
    edit: suppose I’d better…

    1. Conor Mac Aoidh – local chap. Bright and enthusiastic. I feel that he’ll be producing sterling work soon and will be a credit to the Irish PHP community.
    2. St̩phane Lambert Рtireless compiler of PHP Whitebook trivia, and host of a damned good neo-classical metal radio show.

    I can’t think of any other PHP developers that I know that haven’t already been tagged. Really! Now go away and read something else!

    Rules

    • Link your original tagger(s), and list these rules on your blog.
    • Share seven facts about yourself in the post – some random, some weird.
    • Tag seven people at the end of your post by leaving their names and the links to their blogs.
    • Let them know they’ve been tagged by leaving a comment on their blogs and/or Twitter

Boann’s second birthday

It was my daughter Boann’s second birthday yesterday. We had a lot of friends and family visit. Thanks especially to my sister Tarynn and brother Michael and their families for making it all the way up from Dublin!

Boann and Jareth both had a great day, which is a big change from Jareth’s other birthday experiences! Jareth’s own second birthday was spent hiding from everyone. Boann is the exact opposite – loves to be the centre of attention.

The rain fell sporadically throughout the day, but that didn’t stop the kids from running around like mad things. After everything was done, Bronwyn spent a while sweeping grass trimmings out of the house.

That night was the first that Boann was to spend in her own room. Up until now, she slept in a bed in our room, and sometimes in our own bed.

We moved that bed into a new room and decided to try put her into the same routine that Jareth is in – every day, we put Jareth up to his room at 8pm. It doesn’t matter to us whether he goes to sleep or potters around in his bedroom for hours, as long as he stays up there!

Anyway, last night at eight, I brought them both up. I spent a few minutes with Jareth getting him ready for bed. When I went into Boann’s room, I found her on her bed already half-asleep!

It didn’t last, though. Throughout the night, Bronwyn and myself spent hours reminding her that she now sleeps in her own room. Between us, we got 6 hours sleep (11-5), with us taking turns to stay in there with her.

Hopefully things will turn out better today!

book review: Learning PHP Data Objects

Overview: Learning PHP Data Objects, by Dennis Popel, is an introduction to PDO, which walks through the building of a believable test example – a library manager for your home library. Each chapter introduces a new facet of PDO and shows how to rewrite the appropriate parts of the application to slot the new ideas in. Very clear and easy to read. Non-PDO subjects are appropriately kept to the appendices.

I really couldn’t find very much about this book that I didn’t like. Ignoring the appendices, the book is 154 pages purely devoted to teaching PDO through examples, including error handling, working with BLOBs, even the creation of the M in MVC (Models).

I mentioned MVC there. One of my gripes with most tutorials of MVC is that they introduce the concept simply, then provide pages and pages of code with the end product which is “hello world”. Why I should go to all that trouble instead of simply writing <php echo 'hello world'; ?> to the screen usually escapes me. Dennis, however, concentrates solely on the Model and shows exactly why it’s a great idea. I think some more separation of concerns would have been better (don’t mix Author and Book SQL in the same object, for example), but the ideas were all good.

I think that if Dennis was going to show how the Model works, he should also have gone a little further and showed an example of an Active Record pattern as well. But I guess the point of showing MVC was more to show /an/ example of abstraction of the DB code, and that was sufficient.

The book covers a Library manager application all the way through from conception to implementation, demonstrating at all points that the code works with SQLite and MySQL (and by implication, all other DBMS’s) with a change of only the connection string.

Possible problems are explained clearly and solutions are provided. For example, Dennis explains why, after you compile the query select * from books, PDO (and indeed the database itself) does not know how many rows it will return. A solution, in the form of a very smart getRowCount() function shows a query-agnostic method for counting results of an arbitrary line of SQL.

Other areas that are covered in the book include error-handling, prepared statements and transaction-handling.

PDO can handle Prepared Statements even if the underlying DBMS cannot handle it, so it is possible to write your code in a cross-platform way. Examples of why you should use this are provided. One of the examples shows an efficient way to handle insertion or updating of a table using the same parameters for both cases, with the row-handling function deciding whether to use update or insert based on whether an ID was provided.

I feel the Transactions section could have been expanded a bit further. It is not explained how PDO handles this for DBMS’s that don’t internally support transactions, and I wouldn’t like to assume that they work all the time, only to find after deleting critical data that it’s not supported.

Overall, I enjoyed reading this book. Dennis is a good writer and I think he explained his thoughts very clearly.

On an aside, my four-year-old son Jareth loves Packt Publishing‘s books. Sometimes when I go to read another chapter, I need to covertly steal the book I’m reading back from him. For a while, he made it a bed-time ritual to grab all the Packt books he could find around and bring them up with him to read in bed. I think he loved the screen-shots and the frequent code samples. He’s high-functioning autistic and likes literary constructs, and programming books are perfect for him in that regard. Thanks Packt, you’ve made my son (and therefore me) happy.

Autism

Today, I add a new tag to my wordpress collection.

Yesterday, Jareth’s psychiatrist, the jazz-playing Michael McDonough, verified that Jareth is autistic.

This was not a snap decision. Jareth has been in observation for over a year now. Almost every week, I’ve taken half a day off work to bring him to sessions at Enable Ireland. the Monaghan branch is very very friendly.

Some of the signs of his autism:

  • He will be four next month. He has not spoken a single sentence yet.
  • He expresses excitement by jumping up and down and flapping his hands
  • He has extraordinary sequencing ability – can write numbers from 0 to whatever, and letters from a to z. Also the reverse – z to a, whatever to 0.
  • His drawing ability is more complex than one would expect of a three year old.

There are more symptoms (see here for the more common characteristics), but they are not as visually obvious.

So why am I putting this in my blog? Surely one non-technical post this month is more than enough?

Well, if you are reading this blog, you are probably a technical person. And you probably exhibit those same characteristics. Are you very good in some areas (programming, for example) and other people think you are anti-social (even if you don’t think so yourself)? Do you fidget?

The reason I say all this is that I see myself in Jareth. As a child, I was always alone, I was nicknamed “Einstein II” because I had a great ability in maths and general knowledge (the maths ability stagnated as I got bored with school), I still fidget (rocking, finger tapping), people say I am antisocial and arrogant and even sometimes obnoxious although I really don’t see it at the time and am always surprised when someone says it.

Autism is about 80% genetic, and there is a 4.3:1 ratio of male to female incidence. this means that if Jareth’s autism is hereditary, then he most likely got it from me than from Bronwyn.

There is a plus side, though – I grew out of most of the symptoms, and I think he will as well.

Also, his abilities are perfect for the 21st century – his interests lie in areas that are perfect for engineering, programming, or other technical careers. I think he’ll go far.

Autism is not a bad thing. It is just another way of approaching life. There is no cure, but autistics say that they don’t want to be “cured” anyway.

My son enjoys his life, even if communication is frustrating, and I would not have him any other way.

jareth the artist

Jareth is always suprising me with his drawing skills. Usually, there is a point to them – he would draw a wineglass on a table with himself standing right next to it, looking at it. He draws all humans like Blue from Fosters Home For Imaginary Friends, except for his sister Boann, who he draws like a small sitting human. It’s fascinating.

Here are some of his recent creations.

  • Boann got a toy laptop from her uncle Mick (my brother). Jareth has drawn himself playing with it, in the hope that his drawing will come true.
    Jareth playing with his sister’s laptop
  • Not sure why the bowl says “Dog” – we have two cats, but no dogs. But impressive for a 3-year-old to do this anyway!
    Jareth feeds a dog…
  • He’s drawn a scene like this one a few times before. From left-to-right, it’s my fridge/freezer, microwave (with something cooking in it) and stove (with something cooking on it). I think it was a hint that he was hungry.
    cooking
  • His latest – looks like him riding a bike, but not enjoying it too much.
    riding a bike

Last night, I was considering whether to try interest him in architecture or engineering when he gets to that age – if he’s this attentive to detail at 3, imagine how he will be at 18?

update – 15:38

Just caught him in the act. Here he is drawing two people. I presume one of them is me (holding an umbrella???) and the other is Bronwyn.

p8080050.jpgp8080052.jpg

PS: KFM 1.0 was released over the weekend – get it!

moving and speaking and stuff, oh my!

Lots of news.

Jareth, my three-year-old mute genius, who can draw houses and write whole alphabets in lower case or upper case, and can also write “daddy”, “mammy”, “jareth” and “boann” from memory (as well as the word “color”, which we will forgive him for (he’s too young to know how wrong Merkin spelling is)) – has said his first word.

Yesterday, he said the word “Two”. And it wasn’t a fluke occurance. When asked what each of a group of numbers was, he would “um-hmm” for every one of them except 2, which he would consistently speak.

Yesterday as well, we got word that the sale for our new house has gone through, so we will be out of our present one within a few weeks. It’s a massive house compared to all the previous places I’ve lived – two storeys with a converted attic, making four bedrooms, and something like five toilets (one for each work day). It’s in a perfect location as well – well off any busy road, so it will be safe to let Jareth out playing in the summer.

location
we’re in number 16 or 17 or something
layout
two and a half floors of goodness

I bought Bronwyn a laptop, as she kept complaining when I brought mine to work, as she likes to sit in her armchair and read her Grahom Coxon and knitting forums. The machine I got her is twice as fast, and has more than twice the RAM and HD space as mine, and all she uses it for is her poxy forums! I want it! I could use the power!

Her machine has Vista on it as well. I’ll leave it on it to teach her a lesson… when the viruses start infecting her machine, I want her to appreciate it when I install Linux on it 🙂

After setting up her machine, I must admit, Vista is pretty polished-looking. Although – is that all?? After five years of development, you’d expect a bit more than just some glossy window decorations. After Bronwyn had gloated about how Vista looked, compared with my machine, I installed a Beryl theme which emulated the same decorations, but in a free and secure operating system.

Vista? Hah! We shall see… *steeples fingers*

this year so far

I’ve started teaching guitar. I think I have a pretty good method. My student is off work for about six weeks due to some back surgery, so I’ve made the assumption that he will have time to learn some theory, so I started off by explaining “power chords” (or “fifths” – made from the root note and the fifth note), and explaining how major and minor chords are made from the respective 1st, 3rd and 5th notes of the major scale (ionian mode) and minor scale (aeolian mode) from whichever root you want.

Instead of showing twenty open-string versions of chords and expecting to have to remind him of them all again the next week, I demonstrated only four chord shapes, A Am E and Em, and showed how barre chords can be used with those shapes to make any major or minor chord at all.

Hopefully, he has not run screaming for the hills already… I at least only show him songs he actually names himself. Last week, I showed him The Jam’s That’s Entertainment, and this week, I’ll be showing him Pink Floyd’s Wish You Were Here (which will be a handy introduction to open string chords G C and D, as well as hammer-ons and pull-offs).

On the work front, I’m currently working on some pretty significant improvements to our WebME engine‘s AJAX shopping cart. In the admin area, I’m working on allowing products to be created and dragged around categories as if they were files in a file manager. To manage this, I’ve ported my KFM project into WebME and converted the appropriate areas.

Robots… my mini-itx bot has served its purpose – I built it to see if I could, and I could, so it’s time to strip it down and reuse its parts for something else (files server, maybe). I’ll be building a few robots this year, using the Gumstix platform for the brain. This should allow for a much better battery life, as well as a much smaller body size.

We (Bronwyn and I) will be moving house this year. When we moved into our present house, we told the landlords that it would only be for a year or two while we looked for a permanent house to buy and live in. Bronwyn’s parents have given us an enormous boost in this – they found a two storey building with a converted attic, which is about the same size as our current cottage stacked on top of itself three times, and bought it for us. Of course, we’ll still need to pay off the mortgage, etc, but the gesture is definitely not unnoticed! Thanks, guys! More on that later, when details are more concrete.

My son is still a genius. Yesterday, at age 3.3, he wrote his name without prompting. He forgot the “T” in “JARETH”, but still – can your 3.3 year old son write his name? Of course, still not a word out of him yet, but he’s making progress in that as well – every night, he mumbles himself to sleep, trying out various sounds.

update: got a phone call earlier on to say that Bronwyn passed him while he was playing in the house, and she noticed he had written his name in total, not forgetting the “T”.

Boann is calming down a little – instead of screaming all day and night, she now only screams for a while, and I only spend an hour or so every night (usually some time between 1am and 3am) walking up and down wondering why she’s so wide awake at that unholy hour.

Life is getting slowly better.

I have a doctor’s appointment on Friday – I have a lump in a certain area since December, which may or may not be cancerous. We’ll see.

I emailed an old friend, who we had had a falling out with about seven years ago, over some stupid event that may or may not have happened when I was blind drunk after two bottles of vodka. He’s the piercer for a shop in Canada, and is apparently doing quite well for himself! Hi Andy! Bygones have become bygones, and hopefully, we’ll be able to sit down over a few jars at some point and laugh at ourselves.

Anyway… gotta get to work. It’s just past 9am, and I am officially into work-time now, so I’d better stop nattering.

my son, the genius

Jareth had a checkup with a paediatrician a few days ago. He’s three years old, and can’t speak, so we wanted him checked out.

During the checkup, the doctor wanted to check that his hearing and comprehension were okay, as a deficiency in either of those are the most likely reasons for delayed speak.

He was sitting in front of a small game which had a load of letters on it. “Where’s the ‘W’?”, I asked. He immediately put his finger on it. “Where’s the ‘X’?”. Again – instant correct answer. That clinched it – perfect hearing and comprehension. The doctor was surprised as well – apparently not many three-year-olds know the alphabet.

Yesterday, while helping him with his learning, I drew the letters “ABCDEFG” across the top of his writing board. I expected him to attempt to copy the letters. Instead, he wrote the letters “HIJ” immediately. I think he has trouble with ‘K’, but then – he’s three years old!

Want proof? Here’s a video of Jareth drawing H and I without being guided.

Today, I walked into his room, and came across this on the floor:

a load of letters, in the order they appear in the alphabet

At first, I thought “nice – organised”. Then I noticed that the letters are laid out in the order they appear in the alphabet!

My son Jareth is a bloody genius.

general stuff

workin’ nine to five

I’ve switched to a more “normal” 9-5 work routine, instead of the usual 7:30-4 routine I had before. I guess that leaving at 4pm makes me look like a slacker maybe.

I have no idea why so many people work a 9-5 shift. I mean, when I walk to/from work at 6:30am or 4pm, there is no fanfare – I get to /enjoy/ my walk and think about things as I walk.

If I leave at 8am/5pm, though, I can’t think clearly, as I am surrounded by cars and people.

I think it’s quite funny really, to see people navigate through towns in cars. An example in case: my boss gave me a lift part of the way home. I got out in Monaghan town. He asked me to post some letters while I was there. It took about ten minutes to go to the post office, post the letters, then walk along my route until I got to the cross-roads by Dunnes Stores, where I overtook my boss who was still driving through town. Hilarious!

kfm

On the KFM side of things, I’ve slowed down substantially, as my daughter demands quite a bit of time (I got home yesterday – me: “hi”, Jareth: “mm!”, Boann: “wah!”, Brownyn: “here you go. take her”).

I’m working on a small problem at the moment, which I’m taking my time over. The problem is that “:hover”, the CSS selector which allows you to style the element that the mouse is over, does nothing if the mouse is dragging when it enters the element.

The obvious and computationally expensive solution is to check each element whenever the mouse moves, to see if the mouse has entered it.

I’m mentally constructing a more efficient method, but it will take a little time to come out of my head (I’m not concentrating on it fully – got other stuff to do).

What I have so far, though, is:

  • action: mouse moves, calls function getContainer(mouse_position, elements_to _check, clear_afterwards)
    • get cached array of elements to check
    • if no cache exists, create it, populating it with every element that needs checking
    • check through list of elements to see if mouse is contained in them. if so:
      • if clear_afterwards is set, clear the cache
      • return the element
    • if the number of elements is greater than 2, try to group elements that are in the same area together in an object (this bit is tricky) and edit the cache accordingly
    • return null

The part that I’m mulling over is the bit marked “this bit is tricky”.

The idea is that if you have four objects with positions and widths, a[0,0,1,1], b[4,0,1,1], c[0,1,1,1], d[4,4,1,1], the element check could be reduced a bit by creating new container objects e, f containing the first four, geographically segregated: e[0,0,1,2,contains:a,c], f[4,0,1,5,contains:b,d]

With the above, the position check would be vastly quicker, when huge numbers of elements are checked, especially if the segregation is recursive; ie, each container object contains sub-containers, etc, until no container contains more than two objects/elements.

I think you can see why I think this is tricky 😉 writing the position-checking algorithm is very simple, but deciding how which elements get segregated from which others is complex.

Maybe this has been solved before by other people? I don’t know. I’ll check my Bumper Book Of Algorithms when I get home.

other stuff

em… dunno

oh – here’s one: why is it that you get a voltage difference when you measure both sides of the same battery, but not if you measure the plus of one battery versus the negative of another? In other words, if one side of the battery is like a tower of water, and the other is like an empty hole, then why do the electrons prefer one hole over the other?

nyeh, I say. nyeh.