Modern Programming

Ye old blog has been quiet because I’ve been occupied the past few days with a fun little project.

You see, every so often Apple releases a new OS version. In this new OS version there’s always all kinds of cool technologies and goodies that makes easier the lives of us software developers. I remember when Apple released Core Data in Mac OS X 10.4 (gory technical documentation here) and what a boon that was for object graph management and being able to work with more complex data structures and files right out of the box instead of having to invent your own management system. Quite a boon. However, we (me and my team) were unable to take advantage of it when it first came out. I’m a commercial software developer and we’re driven by the market… especially what OS version our potential customers are likely to use. Thus if the new technology is only available in some particular OS version we have to wait until that’s our minimum supported OS version. That could take us a couple releases or years before that happens. Thus, we’re always way behind on adopting cutting edge technology.

I totally understand this situation from a market and sales perspective. But as a geek it always pains me because I don’t get to play with the new goodies. 🙂  By the time I get to play with them, I’m way behind the curve. In a sense that’s good because kinks get worked out, maybe Apple has updated the toolbox and filled in the holes. But it’s just not exciting to the geek in me.

Right now I’m working on implementing a new interface for the application I work on. We’re going to have to support Mac OS X 10.4 (Tiger), and that was really paining me because we’re wanting to modernize the look and feel of the app, but so long as we’re tied to 10.4 that really hampers things. Eventually we were able to come up with a strategy to give the 10.4 users one look and feel, but for users of Mac OS X 10.5 (Leopard) and beyond? They’re going to get something really new and snazzy. The cool part is I get to work with some modern technologies, like Core Animation and Core Image. I know that doesn’t mean much to you non-Mac-programmer types. Just know that a lot of the slick stuff about the Mac OS X graphical user interface comes from these. No, I don’t want to get all eye candy just for the sake of eye candy: form must follow function. But it will allow for a much more modern interface and I don’t have to wait another year or two before I can do it.

I’ve been reading documentation, experimenting in a test bed, and working to come up with a good prototype. It’s just been exciting and I haven’t had this much fun programming in a long time. I’m a kid in a candy store! So I’ve just been head-down in it. I’d love to show you what I’ve been doing but I can’t. Sorry. If you want a vague idea, if you’re a Mac user just invoke Front Row. It won’t be exactly like that, but all that behavior and effect? Core Animation, Core Image, Quartz Compositioning, all make that go.

Car Code

I figured with the growing amounts of electronics in cars that there must be a lot of code behind it, but I didn’t realize just how much code until I read this article.

Speaking as a software developer, that is massive amounts of code. Huge. Trying to maintain that would be a bear. Furthermore, trying to ensure it’s error/bug-free? A monumental task, edging on impossible.

I don’t know how the automotive industry works in terms of producing this software, but if it’s anything like most commercial software companies then lord… it makes me want to drive a Model T, that’s all mechanical and easy to fix. All I can do is hope they have a good understanding of proper software development process and are not willing to sacrifice solid reliable code because they need some new feature and needed it yesterday.

I also hope they understand how simple is better. All those millions of lines of code? Gosh… if they can take the time to simplify and trim that down, so much better in the long run. More maintainable, less chance of errors and problems and risking catastrophic failure.

Gosh I hope they do things right.

Of course the geek in me wants to know nitty gritty details now like the language they’re using and the toolset. 🙂

-[NSTableView setDoubleAction:] not working?

This is documented but in a subtle way, so I thought it’d be worthwhile to mention in a more obvious way.

If you are using NSTableView’s -setDoubleAction: method, the action is only invoked if the cell or column double-clicked upon is uneditable.

Thus, it may not be enough to go:

[theTableView setDoubleAction:@selector(myAction:)];

You may also have to do something like:

[theTableView setDoubleAction:@selector(myAction:)];
[theTableColumn setEditable:NO];

I ran into this just now because I had a single-column table (just a simple table to display a list of stuff, thus the user wasn’t allowed to edit anything) and I wanted to allow a double-clicking on the item (row/cell) to advance the user to the next stage of things (they could also single-click to select the item then click a “Go” button… double-click would just be a shortcut). It actually was working fine under Mac OS X 10.6 Snow Leopard, but the double-click was failing under Mac OS X 10.4 Tiger. Once I made the table column explictly uneditable, it started working and the table received the clicks, the clicks didn’t fall through to the table column.

@compatibility_alias

Apparently there’s an obscure gcc compiler directive to help resolve Objective C namespace conflicts.

It’s called @compatibility_alias.

JongAm has the skinny.

Never knew that, and so far I’ve been fortunate and haven’t encountered many conflicts in my career (had a couple, easily remedied). Neat.

Bummed, but making the best of it.

Work ran long today. I was determined to finish the compliance with the new open source software usage policy, so I could get back to more creative endeavors. I’m all done save hearing back from the CTO on a couple things.

Consequently I missed my martial arts class tonight. Bummer too, as it’s weapons night.

Tonight is also the sparring class. If all goes well, I’ll have something from the UPS man in a couple days that will make that class finally happen. Details will be posted after Mr. UPS stops by.

In lieu of proper class, off to the garage I go. Going to work out on the DIY mook jong. I think I’ll stick my blue gun in the holster too for a little “cross-training”. And on all that knife blarg I’ve been writing about lately? That is one benefit to the Delica: there’s a trainer version. Hrm.

Writing PackageMaker (Installer) Plugins

I’ve never written an installer with Apple’s PackageMaker. Never had a need to.

However, the day job has recently required me to write a few custom plugins to customize how some installers work.

I was amazed at how easy it was. The InstallerPlugins.framework is very simple and well-constructed. Sure you can’t do everything you need with it, but you can do most and then write scripts and other things to customize it to your heart’s content.

The thing that gets me? There’s almost no documentation on it. Apple provides the InstallerPluginSample code, and really in a lot of ways between that and reading the InstallerPlugins.framework headers, that’s about all you need. It’s that simple and well-written of an SDK.

Still, some things came up while I was working that I couldn’t find an answer to. For instance, I was instructed to create a “display license” panel that replicated the stock panel the installer provided but had a few customizations. The trouble with this? Anything outside of the content panel I couldn’t replicate, such as the “Print” and “Save” buttons. I was pointed to this resource and specifically this FAQ:

[Q] Can I add Print… and Save… buttons similar to the ones used in the default License pane?

  • You can do it through an undocumented and private method:
    1 Open the nib of your plugin project in Interface Builder.
    2 Add a custom view to the nib file.
    3 Add Print… and Save… buttons to this custom view.
    4 Create outlets in your controller class for this custom view and buttons and make the appropriate connections in Interface Builder.
    5 Add 2 methods in your controller class to be called from the 2 buttons and connect the buttons to these methods in Interface Builder.
    6 Add the - (id) bottomContentView; method to your controller class and make it return the reference to your custom view.

IMHO, using an undocumented and private method is bad and just asking for breakage and trouble down the line. But, some people are willing to live with that so tread accordingly.

Stéphane Sudre also provides this HOWTO on using PackageMaker. By the screenshots and some text I can see it’s old, so I don’t know how relevant it is to day’s PackageMaker. But there you go.

Code Practices

I’ve been developing software over 30 years, 15 of those professionally. I’ve learned a thing or two from the real-world trenches, one of which is that all code written must eventually be maintained… probably by you. The more you can do to ensure your code can be understood 6 months (or more) later, the better (your) life will be.

But this is hard.

Not just whining that it’s hard, but it is a difficult thing to do because who can know what exactly you’ll need to know or care about during maintenance. And while you’re in the heat of the moment writing code, you may not consider everything that needs to be documented. This is why the best you can do is strive to write simple code, well-factored, and as understandable as possible from the get-go. Premature optimization is the root of all evil. Simple is good; simple is best.

Via Slashdot I see this article on Coding Practices. He raises good points, but at least in my experience it doesn’t always work out that way.

Continue reading

How do you people do it?

I am a Mac user. In fact, I don’t just use Macs but I write software for Macs as my chosen profession. I’ve been writing Mac software for over 17 years. The first computer I owned (well, parents owned it… first computer in my household that I had regular access to) was an Apple //e. I’ve been working with computers for over 30 years, and for the most part yes it’s been Apple-based. Sure I’ve used other computers and computing systems, but Apple computers and Macs are my mainstay.

Why do I prefer Macs? Because they are elegant, beautiful, “they just work”, there’s a familiarness in their use and design. Like any good tool, the tool should enable and enhance your ability to get work done and should not get in your way. This is the Mac User Experience. Granted, it’s not always perfect. Apple themselves have changed and refined the OS over the years, with some stumbles but some great strides too. Certainly you encounter 3rd party software that can be wonderful to use, and some that can be amazingly painful to use. Usually I’ve found the painful stuff is written by people who think they’re just writing software and don’t fully grok the notion of “user experience” and what that means and why it matters.

That’s why I write today.

I’ve been temporarily reassigned to another project within the company I work for. This particular piece of software exists on both Mac OS X and Microsoft Windows. For the most part, that it exists on Windows matters not to me. However, I was just given a couple bugs (I didn’t write them, but I get to fix them) to investigate that necessitate the use of Windows.

I haven’t had to run or really touch a Windows box in over 10 years. Oh sure from time to time I have, at a friend or relative’s house, but in general I just have no reason or need for it. Thankfully the company has copies of VMware Fusion and some pre-made “virtual disks” with Windows XP already installed. A few hours of file transfers later (the VPN is slow) and I was up and running with Windows on my MacBook Pro.

That’s where the pain started.

How in the world can you people use Windows? 🙂

Apparently the XP installs were fresh installs, so upon first login I get bombarded with questions. Little balloons popping up everywhere trying to be helpful but only serving to overwhelm me with a desire to put my fist through the screen. You close one and another one immediately pops up, again, and again, and again, and a-fucking-gain. Oh hey it noticed some sort of hardware, tho I don’t know what, and it’s trying to help me cope with it but doesn’t tell me what it wants to cope with. And the stream of dialogs and “helpful” things just keep coming like and endless parade.

MY GOD WILL YOU SHUT UP AND STOP TRYING TO BE SO FUCKING HELPFUL!

The thing is, I’m a computer savvy person so I understand a lot of what’s going on and why. But I step back and try to look at this experience from the angle of someone like my mother, and I just cringe. No wonder she has to take her computer into the shop so often. No wonder she spends so much time on the phone with tech support. What a nightmare! And all I’ve done so far is log into the machine!

Yes, I’ve been away from Windows that long. I wish it could have been longer.

The I run some installers and wow, talk about more unfriendly and bizarre designs. I know some of this is merely because it’s the devil I don’t know… because it’s “not Mac”. Ultimately however it’s not that. It’s about poor user interface and user experience considerations and design. Granted it is not easy to do, to make something so complex, so technical, into something that just anyone can use. But I do like to think Apple’s done a pretty fair job with that.

I just cannot see how people can use Windows and enjoy it. Most people have to use it because work requires it of them, and then they use it at home because it’s the devil they know. As well, I know most people just aren’t into computers as much as I am so it’s not something they think much about. Or the old stigma’s remain about Macs that keep them away. It’s all about inertia.

I have to use Windows for a little while to deal with this bug. Thankfully it’s only for a little while. 🙂

If you want to learn more about interface and user experience design, check out stuff from Bruce Tognazzini and Jef Raskin. In fact, here’s a great little article by Jef on Tog’s website, about “intuitive”.

Death March (software)

If you work in the software industry and don’t know what a “death march” is, you need to learn.

Check out Edward Yourdon’s appropriately titled book, Death March for more on the topic.

You can’t work in this industry and not read that book.

Better than setuid – BetterAuthorizationSample

While scanning my RSS feeds I ran into this post from JongAm. It’s in Korean so I really don’t know what he’s talking about specifically, but generally I can tell he’s writing about Mac OS X’s authorization mechanisms. (BTW, I love that URL’s and such don’t choke on Hangul).

There’s something at work I’ve been fiddling with the past some days. The issue is that something has to be done and that something requires authorization. Unfortunately, due to how things can work under the hood by the drivers and the OS interacting, it’s possible things could change and thus require the user to authenticate again. This is not a desirable user experience because the need to re-authorize is an under-the-hood detail, not something the user would be aware of. Thus to the user the user experience is randomly, or not, being asked to reauthenticate. Not good.

So what’s the solution? The original thought was to create a little helper tool app that would have its setuid bit set and be installed as root, thus the user would have to authenticate at most one time and the little helper tool would then be authorized “forever” to do the necessary voodoo. A reasonable thing. And setuid tools are not a new concept and are well-established, but still they’re considered tricky and risky because you’re still running code as root which opens up all manner of security issues.

As I searched around for information, I came across Apple’s BetterAuthorizationSample. Obviously written by Quinn (thus you know it will rock), it’s provided as a way to achieve the same results as a setuid tool but in a safer way by use of launchd. What’s even better is BAS provides a library and mechanism to make it easy for you to utilize this functionality in your own code. There is step-by-step documentation that walks you through the whole process, and of course a sample app to demonstrate various levels of complexity. For more information, read the ReadMe, the Design and Implementation Rationale, and the lib HOWTO.

Getting it up and running in my app wasn’t too difficult a task. Just follow the HOWTO guide. It does take a little bit to wrap your head around it all just because there’s a lot going on, but the documentation is thorough and complete. Just do as it says and you’ll be up and running. Works great in my app. I’m pleased.

I will note that if you don’t have an uninstaller for your application, this is one situation that might find a simple uninstaller to be a welcome thing. There are not only files in odd places to remove, but also you will need to unload the Launch Agent from launchd. There’s also the question of removing the entry in /etc/authorization but there’s really no good way to do that. Still, something you need to consider.

All in all a fantastic bit of sample code, and while not necessary for all authorization needs, if you are considering writing a setuid tool for Mac OS X, you should look at this mechanism instead.

Good stuff. Share and enjoy.