Glitches

Mar 13 2012 Published by under Opinion

It started with this image. Or rather the glitch that you can see in the middle of the screen.

It’s one of the screens in a new app that I’ve been developing. There’s lots of hard stuff in there but this is the first problem that has really stumped me. What it appeared to be was this: a text view (UITextView) on a table (UITableView) showed a nasty glitch when you tried to place the curser in the text box.

First thoughts:

  • Transparency
  • Scrollview (UITextView) within a scrollview (UITableView)
  • Image background

So I switched off the transparency. (No effect.) I switched off scrolling while editing. (No effect.) I made the background boring. (No effect.)

I was stumped.

I showed it to some guys at the London iOS Developer Group meeting. They too were stumped. (This was a bit of a relief. It meant that I wasn’t doing anything completely stupid, which is always a risk.)

So I tried writing a question for Stack Overflow. And, as I often do, I stumbled across the solution.

Note that the text view has a small border and rounded corners? Yup, that’s the culprit. Or at least, some of that code is. Here are the two lines that do it:

self.layer.cornerRadius = 5;
self.layer.shadowOpacity = 0.5;

(There were quite a few other lines adjusting the layer too, which is what took the time to narrow down.)

It was nothing to do with the table view or the text view per se. It wasn’t even any of the visible transparency effects.

Of course, in the screen I have no need for a shadow, indeed you can’t even see one, so the solution was easy. Quite why this combination causes such a weird effect have no idea, but I’m glad that I found the solution.

(I raised a bug report with Apple: rdar://11041657.)

No responses yet

My delicious.com bookmarks for February 8th through February 20th

Feb 20 2012 Published by under Links

  • An Attribution Failure Theory – "Credit is easy. Well, mostly easy. It might have been hard to get the format of citations right at first in school when we were writing papers, but the act of citing is easy. You just do it. Yet, people all over the Internet don’t."
  • You Are Not Ruthless Enough – "Here’s the thing: you are not ruthless enough. You are certainly not ruthless enough to your objects, and you probably need to be more ruthless to yourself." Programming Is Hard, Part 381.
  • You Will Never Kill Piracy, and Piracy Will Never Kill You – "The seven step, ten minute download process (which will be about ten seconds when US internet speeds catch up with the rest of the world) is the real enemy the studios should be trying to tackle."

Comments Off

My delicious.com bookmarks for October 21st

Oct 21 2011 Published by under Links

Comments Off

Programming Is Hard

Jan 18 2011 Published by under Opinion

It’s hard to explain to someone who is not already a programmer the kinds of things that you have to do when building an application. The thing you’re trying to explain is often very abstract and the answer frequently would involve lots of code.

That’s why I thought this particular problem might make an interesting discussion. In talking about this very simple problem we can talk about the things that developers deal with every day and, hopefully, the process can be followed by most people who have used an iPhone (or, actually, any computer). You won’t be a programmer at the end but you might have a greater appreciation for what happens behind the scenes.

The basic problem can be seen in this screen shot.

The login button is a toggle. That is, if I’m currently logged in it says “Log out.” And when I’m not logged in it says “Connect,” which is “log in” in Facebook parlance. A subtlety that you might not ordinarily notice is that when the user clicks the button, the keyboard should move out of the way when it’s not needed and come back again when it is.

There are two basic cases to consider:

  • When I’m not already logged in. In this case pressing the button opens the login screen and the keyboard should shift out of the way.
  • When I am logged in, pressing the button just logs me straight out. In this case the keyboard can stay where it is.

Easy, eh? (That’s what I thought when I started, too.)

Let’s sketch out the code.

when the button is pressed
  if I'm not logged in then
    make the keyboard move out of the way
    log in
  else
    log out

This is called pseudo code because while a computer can’t actually execute it we’ve broken down the processing into the required basic steps. You’ll have to trust me when I say that the real code (called Objective-C) isn’t terribly different.

Not so hard.

Except… you didn’t really think it would be that easy, did you?

It turns out we’re missing one important detail from our algorithm.

One thing we do a lot when programming is use pre-existing components (standing on the shoulders of giants as Isaac Newton, or Oasis, would have it). When you write a component you’re going to come at the problem with some specific ideas of how it’s likely to be used. Hopefully these ideas are the most common ones as this will make everyone else’s life significantly easier.

In this case, our button — a pre-existing component that I didn’t write — is a clever one. It already “knows” how to log in and log out of the service. This sounds like a great time saver and it simplifies our algorithm to just this:

when the button is pressed
  if I'm not logged in then
    make the keyboard move out of the way
  else
    do nothing

Only, it turns out that that doesn’t work.

Why not? Well, the implicit assumption in the above pseudo-code is that it is run first, that is, before the instruction to log us into or out of the service. But if the button logs us out before any of my code is run then no matter whether I was logged in or not before I pressed the button, the above code will find that we’re logged out and move the keyboard out of the way.

When you’re writing a user interface you find dozens of these tiny little details getting in the way of what you’re trying to do. Any non-trivial screen will have lots of these little problems, and the worst thing? No-one will ever know. If you do your job well no user will ever see these little glitches.

Talking of which, how do we eliminate the anomaly that we’ve just found? The solution is pretty simple. At the moment we’re trusting that the button “knows” whether we’re logged in or not. Instead, we’re going to have to take responsibility for doing that as well. That adds a little bit of complexity but isn’t too scary:

  • When the screen opens we need to check whether we’re logged in or not and remember that. In Objective-C we call that a “variable,” but really that just means something that we’re going to store and access again later
  • Later, when the button is pressed we can use the following pseudo-code:
    if the value I saved says that I'm not logged in then
      make the keyboard move out of the way
    else
      change the stored value to "not logged in"
    

  • When I’ve finished logging in — remember I could press the cancel button in the log in screen — change the stored value to “logged in”

And that’s it, we’re done. We have a working version of the log in button.

The final point I’m going to make here is that I ended up discarding all the code above. It just didn’t work as well as I wanted and I ended up implementing it in a completely different way. And this really is the kind of detail that you never notice. A good chuck of any programming project is prototyping, building mock-ups and other activities that don’t directly end up in any shipping product. All this discarded work — which does, at times feel like a waste of time — is designed to make the product better.

Some people who have never programmed say things like “there’s nothing complicated there” or “it’s only a button!” Hopefully this post has shown that even a simple button can be far more work that it initially seems.

No responses yet

My delicious.com bookmarks for October 17th through October 18th

Oct 18 2010 Published by under Links

Comments Off

My delicious.com bookmarks for February 15th through February 26th

Feb 26 2010 Published by under Links

  • Tits and Apps – About most of the 'sexy' iPhone apps being pulled last weekend: "What developers see is that the App Store is a shaky foundation upon which to build a business. One day you’re prospering, the next day your app is gone. There are awesome iPhone OS apps that aren’t being built because developers don’t trust Apple not to yank the carpet out from underneath them."
  • Infer.NET – Seen at the BCS/IET Turing Lecture by Chris Bishop. Looks interesting.
  • Sources offer peek at Adobe Creative Suite 5 for Mac – PhotoShop CS5: what do you do to the app that has everything? Not a lot, visually at least…

No responses yet

My delicious.com bookmarks for November 6th through November 10th

Nov 10 2009 Published by under Links

  • News Corp to Offer Plaid Stamps! – "Giving Murdoch the benefit of the doubt, then, I’m guessing he simply doesn’t mean what he said. Perhaps he just wanted to sow a little confusion, get some publicity and maybe a concession or two from Google."
  • The night the Berlin Wall fell – "For me it was that rare occasion when a story was unqualified good news. After years watching the way communism was practised, I felt no need to mourn its collapse. Whatever came next had to be better." Twenty years since the fall of the Berlin wall.
  • OMG Ponies!!! (Aka Humanity: Epic Fail) – "The real world has failed us. It has concentrated on local simplicity, leading to global complexity. It's easy to organise a meeting if everyone is in the same time zone – but once you get different continents involved, invariably people get confused. It's easy to get writing to work uniformly left to right or uniformly right to left – but if you've got a mixture, it becomes really hard to keep track of. The diversity which makes humanity such an interesting species is the curse of computing."

No responses yet

My delicious.com bookmarks for May 8th through May 18th

May 18 2009 Published by under Links

No responses yet

My delicious.com bookmarks for April 28th through May 3rd

May 03 2009 Published by under Links

No responses yet

Professionalism

Mar 24 2009 Published by under Opinion

A few years ago I was subcontracted to one of the large consultancies. I was taking over from someone who was, supposedly, quite senior and the task at hand, I was told, was very hard. I should take copious notes as she wouldn’t necessarily be around afterwards to help me. Making a mistake or missing out any one step could be disastrous to the whole process. If I did everything properly each new installation would take about a week.

This turned out not to be entirely correct.

After sitting through over a week of her spelling out each and every step in excruciating detail — much of which I don’t think she really understood — I spent three days writing a shell script to automate over ninety percent of the process. I don’t mean a quick, shoddy hack either. I spent the time to gold-plate it. It was a work of art. I set it up so that you only needed to copy the one file and allowed for the user forgetting to switch FTP into binary mode1.

In the end, my three days of work reduced the week long process to about an hour, and most of that was waiting for the file to transfer over the network.

I say all this not to show off. I think any engineer would have thought to do this. I note the extra refinements so you realise that it could have been done in much less than three days had I not wanted to practice my Unix-fu.

Result: I was heavily criticised for not following the proscribed process. I pointed out that my new scheme was quicker, easier and less error-prone. They countered that I had been unprofessional to begin a “development project without authorisation.”

What does “professionalism” mean to you?

Sometimes, I think, it’s used as an excuse to do or not do something in a particular way. “That’s not professional” is kind of a cop-out. In this case I can only assume that the real reason was that they wanted to bill a week of my time to the client for each installation. Of course they couldn’t say that.

Since then, every time I hear the phrase “that’s not professional” I try to drill down and find the real, underlying reason. I’m hoping that one of these days I won’t be disappointed with what I find. It hasn’t happened yet.

  1. I basically appended a tar’d and uuencoded file to the end of the shell script which it knew how to extract and decode. []

4 responses so far

Next »