Why I CAN test my own code

Once upon a time someone told me that programmers can’t test their own code. I can’t remember who told me this, but I’ve been repeating it ever since.

Most of the work I do is as a solitary programmer. This is true for my personal projects as well as work I get as a freelancer and almost everything I’ve done as part of a bigger team. In some cases I’ll have people who test for me, in others I have to organise testing myself.

This is the bit where I boldly state, “a programmer can’t test their own code,” and pass it on to someone else.

Now, you can write unit tests for some things, but when you’re dealing with a project which is mostly based on user interaction, you don’t get very far with that, and when you’re as heavily reliant on asynchronous HTTP calls as most javascript heavy web sites and server-communicating mobile apps are, then it becomes much more difficult to write automatic tests that capture the sorts of problems that real users will encounter.

So, we need a human tester.

Then I thought about it, why can’t I test my own code? The theory I had been working to was that I knew my way around the software, I would subconsciously avoid sections of the site or app or whatever that I wasn’t confident about.

Of course, this is the bit where the people who call themselves software engineers (or testers, but then that’s kind of the point of this post) rather than programmers will start screaming about test plans.

And they’re right, but if you can find me 1 solo programmer who has a comprehensive test plan for the project they’re working on, then I’ve already tripped over a hundred or so that don’t, yeah, this includes me.

Of course, everyone already knows this, I’m not writing anything new here, except of course that old refrain that I’d been hanging on to (and to which, I’m sure, cling many other programmers) needs to be changed, it’s really:

Programmers don’t want to test their own code.

Which has the sad implication for me that I CAN test my own code, I just have to put in the extra effort to do so.

Posted in iOS Development, Life | Tagged , , | Leave a comment

Poster for the Carrer Progrés Calçotada

The annual Calçotada in Carrer Progrés (in the Barcelona district of Gràcia) will be held this Saturday the 10th of March. The poster designed by Juanjo as always, is below.

You can also check out my photos from the Calçotadas in 2010 and 2011.

Posted in Life | Tagged , | Leave a comment

What being a native speaker means

One day last year, after the incredibly strenuous activity of standing up after cutting a bit of card with a stanley knife I felt a sharp pain a bit above my groin. It seemed like my hernia had opened up again.

After a few doctors visits and many months of waiting, I had a scan done today to see what’s really going on down there. The specialist who sent me to have the scan done told me it was a resonance scan.

I had no idea what a resonance scan was.

Like a lot of people I’m a fan of the series House, Hugh Laurie’s portrayal of an egotistic, but brilliant, diagnostician which is now into its eighth season. And, like a lot of those people, I have no knowledge of medicine whatsoever, but after so many episodes some of the words start becoming familiar.

So, today when I walked into the room to have my “resonance” scan and I saw the machine I thought to myself, “shit, I’m getting an MRI.” It’s a big machine which they stick you in and it does stuff with really strong magnets (good thing all my piercings are higher up).

Now, if I’d been in the health system in an english speaking country, I probably would have known what the test I was having done was before I got into the room.

I consider my spanish (Castilian) pretty good these days, I speak a lot more of it than english and I don’t often struggle to explain myself or understand others, but that’s all a long way from being a native speaker.

The difference is that I don’t have a lifetime of family discussions, watching television, reading books, and just general consumption of popular media behind me when I speak, I just have a few short years of practice, mainly speaking with people in reasonably similar fields with reasonably similar life experiences.

I’m not really disappointed by this, but it is worth remembering the difference between someone who speaks a language perfectly (and I’m a long way from this) and a native speaker.

Posted in Life | Tagged , | Leave a comment

The iPhone steering wheel

The iPhone has an accelerometer in it, which is a neat little bit of tech which has various uses. When your phone switches between portrait and landscape mode, that’s the accelerometer, and when you shake your phone, that’s the accelerometer as well.

One thing that I’m sure you’ve seen on an iPhone or iPod add somewhere is some sort of driving game where you hold the device on both sides and move it like a steering wheel to turn the car. I recently had an instance where I was asked to do this (although there are no cars involved).

It turns out that it’s a little bit more complex that you would imagine at first, but at the same time wonderfully simple once you’ve got it. In true hacker style I didn’t actually read any of the documentation for this, which probably would have helped. Once I couldn’t find anything useful on google I resorted to reverse engineering the values and inferring what was going on.

I wanted the device’s position, not it’s movements, so I started with some code from Apple’s developer’s centre which gives you the result of using a low pass filter on the raw accelerometer values. This means we get rid of the higher frequencies (movements) and just get more or less static values.

So, once I worked out which value I wanted to use, I could calculate the angle of the device when held vertically in landscape mode (image to the right).

All I needed for this was the inverse sine of the y-axis (green) value. The y-axis is the one that runs from the speaker end to the microphone end of an iPhone along the long edge of the screen. Piece of cake.

Because it’s easier to work with degrees, I did that rather than sticking with radians, so my equation came out as

180sin1(y)π.

This is where it gets tricker. The accelerometer relies on gravity to take its readings on position,  the values you get out of (for instance) the low-pass filter are the sin() of the angle between that axis and the horizontal.

This means that the accelerometer isn’t able to distinguish positions which only differentiate by a rotation around the vertical. To bring this back to our steering wheel concept, you can’t steer like a truck driver (image to the left).

This also presents another issue, since the accelerometer effectively measures angles with respect to the horizontal, you can’t use the same function to get a steering wheel rotation when the device is tilted towards the user – or away from them, but who would do that?

When the device is tilted toward the user, the y-axis will still be parallel to the horizontal when it’s not steered to the left or right, but it will never make it to a full 90 degrees from the horizontal (e.g. vertical). In this case I needed to know that, from a steering point of view, the device had been rotated the full 90 degrees.

This can be done using an axis which measures tilt towards or away from the user, I used the z-axis (blue), although it would be possible to use the x-axis (red) instead. The z-axis is the one coming straight out of the screen, horizontal to the plane of the device.

So, now we create our z-modifier, in order to avoid unnecessary conversions, this was left in radians (and it cancels out a bit better later on). What we need is a value that will leave our y-axis angle as is when the device is in landscape mode, but increases the reading on the y-axis angle when the phone is tilted. This works out as

\begin{aligned} \frac{\pi}{\pi – 2 \cdot |sin^{-1}(z)|} \end{aligned}

So, we multiply them together, cancel a couple of instances of pi and we’re left with

\begin{aligned} \frac{180 \cdot \sin^{-1}(y)}{\pi – 2 \cdot |sin^{-1}(z)|}. \end{aligned}

(180 * arcsin(y))/(pi – 2 * |arcsin(z)|)

Of course, what every programmer wants is the code, and it does turn out to be dead simple. Start with the filter class from Apple’s Accelerometer Graph sample code and just add the following method to the filter.

[objc]
– (double)steeringAngle
{
if ((M_PI-2*fabs(asin(self.z))) == 0)
// The device is horizontal, we’ll just set the angle to 0 by convension:
steeringAngle = 0.0f;
else
steeringAngle = (asin(self.y)*180/(M_PI-2*fabs(asin(self.z))));

return steeringAngle;
}
[/objc]

Posted in iOS Development | Tagged , , | Leave a comment

Coffee, Coffee

I bought an espresso machine on the weekend, so here’s a photo of my very first coffee from it. And another of the machine itself.

I grew up on plunger coffee and continued to drink it when I left home, however long black coffee in Spain tends to be average at best, so I switched to drinking espressos when I’m out. When I moved into the apartment in Carrer Progrés there was an espresso machine there, and since then I’ve mainly been drinking espressos at home as well.

Writing a post once a day for a month is all well and good, but Sundays aren’t really days, just kind of blank spaces between weeks. So Sunday posts will be late and/or something simple.

Posted in Life | Tagged , | 2 Comments

What you could see if you looked

I was talking to a friend last night who was at the protest in Plaça Catalunya last Wednesday. He was differentiating the protest from what normally happens in Greece.

The long and the short of it was that the protests in Spain (we’re going to generalise here) are less violent and that the violence that inevitably occurs has far less support from the majority of the protest.

He spoke of how, in Greece, when part of a protest go and smash up the foyer of a bank, the bulk of the protesters are generally supporting the actions, even if they aren’t participating.

Yet one thing remains the same, police beating up protesters, peaceful or not. I think that some of the actions of the police caught a lot of american’s by surprise during the Wall Street protests last year, but from speaking to people from around Europe, it seems to be pretty much par for the course here.

Of course, these days everyone carries camera phones around with them and so there is much more proof, or at least something close to it. Yet, despite police brutality probably being a hit with media audiences, there seems to be a blind eye turned when the victims are smelly, badly dressed protesters.

These days, media pressure can achieve just about anything in politics, there are enough people willing to believe the their media’s version of the story that the right media outlet can force issues that would otherwise remain untouched.

So, walking home last night I was thinking about this, obviously the hundreds of videos of police brutality against protesters are doing the job. Of course, most are just as out of context as the news, you can’t say what happened before the video started, just cause and the police being provoked could easily be claimed.

Yet, imagine if you could get video cameras, always on, strapped to the front of the shoulder of a reasonable number of the protesters. Hook them up to run constantly and then synch them up afterwards.

Mulling this over in my head I decided that even this probably wouldn’t help, if there’s one thing that all civilisations are good at it’s not seeing what they don’t want to see. But it would make one hell of an interesting video if you tiled them across the page.

Posted in Life | Tagged , , | Leave a comment

Requisite rant about Apple’s approval process

I’ve finally been bitten by Apple’s App Store approval process.

An app I’ve develop for browsing, buying, and reading comics on iOS devices got rejected from the App Store the other week. The reason? They state that the app requires personal user information before providing its basic functionality, something which is outlined in their review guidelines.

Now, from my point of view, that’s fair enough. Except that it doesn’t require personal information. It requires a new user to create a free account (within the app), which requires no personal information, just a username and password. So obviously I disputed this.

After a week or so they got back to me, and after someone tried to phone me and couldn’t (not sure why, but anyway) I got on to him and was essentially told that the app was rejected and that’s it.

I pointed out that the app doesn’t actually require any personal information, that didn’t save me.

I pointed out that there are other apps in the same category (for example, our direct competitors) who not only require registration, but require a valid email address before allowing you to download even free titles. Their response to this was that it didn’t matter what else was in the app store, this was about our app.

I pointed out that one of our own apps has the same functionality, which we changed after a similar (but in the first instance because we requested an email address, correct) complaint, after which I changed to the mechanism and it got approved. I got given the same excuse as to do with other apps.

At some point in all this, the real reason came out. They didn’t think it was a good user experience. So all this garbage about their review guidelines and at the end of the day, they just didn’t like the way our app handles.

I understand the guidelines which Apple set out, even if I don’t agree with all of them, and I feel safer buying apps from the app store for them. However when I get an app I’ve made rejected for behaviour that isn’t against their guidelines, that’s a bit upsetting. When a direct competitor to my app is breaking the guidelines and don’t seem to have any problems (probably since they’re making more money for Apple than we are), well that just seems like bullshit to me.

Posted in iOS Development | Tagged , , | Leave a comment

Start your keyboards

So, I read a blog post I found on Hacker News by someone I don’t know. The content is interesting, but entirely unrelated to the rest of what I’m about to say. Turns out the guy had just started blogging as part of the blog a day in March challenge made up by some other blogger I don’t know (I love the internet).

I thought, I can do that.

So I am.

It was actually the second post on the blog I found via HN, but it looks like that guy’s in Australia (mentioned his scary HECS debt), and it’s still the 1st of March here in the old world, so I’m in.

This, of course, counts as my first post of March – we’ll see how far I get before missing a day.

The article I originally read on HN is interesting too: What I learnt pretending to be a programmer.

Posted in Life, Web-site | Tagged | Leave a comment

Gloves for the cold

Last weekend Andrea and I went to Belgium for a short break (otherwise known as an authentic Bridget Jones mini-break). We had a great time, but it was incredibly cold.

I made a pair of fingerless gloves (one day I’ll work up the courage to make gloves with fingers, but they look so fiddley) to take.

I still haven’t gone through the photos, but for now, here are the gloves.

Posted in Life, Wool | Tagged , , | Leave a comment

Christmas in Granada

I spent Christmas and the New Year in Granada with Andrea’s family again this year. It was a wonderful chance to relax, eat lots, and generally do christmasy type things. Although I did spend a fair portion of the time I was there knitting.

The spanish do their gift giving on (Three) King’s Day, the 6th of January, which means that there’s plenty of time after la Noche Buena (Christmas Eve) to organise gifts. I received, amongst other things, a set of fantastic Sony headphones to use at uni, a belt, a face cream (to keep me looking young and beautiful), and a jumper.

Andrea’s nephew Bruno is getting bigger all the time, in fact it seemed he grew substantially while we were there, must have been all that good food he was eating. He was doing his best to sit up (e.g. stay balanced) and is at that stage where he’ll put anything in his mouth, of course he also seems to have a good stomach as he’s quite happy eating just about any adult food he’s allowed to try.

I made my traditional christmas cake again this year, complete with red royal icing, which I put on before we left, and a scene with the three kings arriving in Granada, which Andrea and I made when when got there.

You can see it all, and more, in the photos I put up last week.

Posted in Life | Tagged , , | Leave a comment