Tag Archives: mac

My delicious.com bookmarks for June 2nd through June 7th

In with the new

MacBook Pro screen with bad pixels

It was nothing like as dramatic as my iBook dying one evening, but there was no getting around the fact that my nearly five year old MacBook was no longer up to the tasks that I was trying to throw at it. Developing applications, even for resource limited devices such as the iPhone, needs a pretty substantial piece of Mac software called Xcode. My photography pushed me towards getting Aperture to manage all my pictures. It’s great, but it did have a tendency to grind to a halt when it was least convenient.

Anyway, long story short I just got one of the shiny new MacBook Pro’s. I went for the 15″ since I have the iPad for portability and I liked the idea of a quad-core, eight-thread CPU and the discrete graphics card would be a good thing for Aperture. The increased screen resolution, for me, is just gravy.

I was a bit concerned about upgrading from my old machine. In the olden days you could use the Migration Assistant to copy files from your old machine (put the old one in “Target Disk” mode and plug the machines together using FireWire). These days there’s an added complication, in that you can also use a Time Machine backup. Which is the best, quickest option? I didn’t get a great answer from the guys at the Apple Store but in the end I had to use the Time Machine since I don’t have a FireWire 400 – 800 cable.

I picked the default options and I was pleased to see that it was pretty quick; only a couple of hours. It dropped me into a very familiar looking desktop (my old one). Upgrading a Mac can be so much of an anti-climax — everything the same but faster.

Things changed after that. I clicked on Tweetie in my Dock. Nothing. The same with Aperture. Activity Monitor did start, but it just told me that the other two apps were not responding.

I decided to go for the Windows solution and rebooted. Not, it turns out, a good idea. I got the white screen with the Apple logo, a pause and then a black screen. The sleep light came on.

Um, hello?

I think what happened is that it restored a little too much from the Time Machine backup, over-writing some video drivers perhaps. I reinstalled the OS and all was good in software land.

I played around for a while and was very happy with what I found. It really is very much quicker. iTunes actually launches fast enough that I don’t think twice any more. Aperture doesn’t stutter. And the geek in me loves to see a build in Xcode using all eight (virtual) CPUs. I kept Activity Monitor running for a couple of days just so I could see what it was up to. It really is a thing of beauty in hardware terms, too. I’ve poked around with the unibody models in the Apple Store before but even there you don’t get the impression of just how solid they feel.

Eventually the high — maybe it’s the chemicals in the incredibly minimal packaging — started to wear off and I began paying attention to some of the details. Such as, well, take a look at the picture above. There’s a horizontal line of non-operational blue pixels all the way across the screen. One row higher and I probably wouldn’t have noticed and, even now, it’s quite subtle. But now I know it’s there I can’t not see it.

I think this is the first Apple hardware product that hasn’t been perfect out of the box (not including some of their software!) so, while disappointing, I’m confident they’ll replace it and I’ll get a good, fully working model without too much fuss. And if that lasts as long and works as well as my old MacBook, I’ll be very happy.

My delicious.com bookmarks for February 10th through February 14th

  • The Mac App Store: It’s an honor thing – "Apple’s approach is simple. It’s an honor thing. The company believes that, given the choice, people will do the right thing. It also understands that anti-piracy techniques don’t stop pirates, but they do get in the way of honest users."
  • Nokia’s 15-year tango to avoid Microsoft – "[PC manufacturers] found it wasn't worth the effort to differentiate their PCs from the competition, in what had become a commodity business." The reason's behind Nokia's original decision not to licence code from Microsoft in the nineties hasn't really changed, which makes today a sad day.
  • Doctor Who Infographic – Everything you ever wanted to know about Dr Who but were too afraid to ask…

Programming Is Hard

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.