Public Transit ain't that great

A couple of weeks ago, there was a puff piece in the local newspaper about a guy and his wife (and teenaged daughter) don’t drive, don’t even have a car. They catch public transport everywhere, and it works for them.

Adelaide is a funny place. It’s not really densely enough populated to have a first-class transit system, and because it isn’t really that good, not many people use it. This is possibly also in part due to how easy it is to drive everywhere in Adelaide, including into the CBD.

I’m a big fan of public transport, it just isn’t working that well here right now.

I used to work in the CBD, and if you live/work/play/study in the CBD, then Adelaide’s public transport is fine. I used to be able to stagger up the hill to the nearest (well, second nearest, as they closed the nearest) railway station, and as long as I was there by 8:02 am, I would be in time for work. Unless a freight train happened to come along at 8:01am, and I wasn’t able to cross the tracks until too late to catch my train!

I had another option, which was to wander a little bit down the hill, and catch a bus. But buses are much less reliable (yes, even than our pathetic train system here in little old Adelaide). Since I am near the terminus, then theoretically, the buses shouldn’t be late, unless the previous bus was so late that it made this run late. Which happened about 50% of the few times I caught the bus into town. The train was more convenient anyway, since it (usually) stopped closer to my work.

This year is a different matter. I am studying at the University near my house. It takes about two “three-minute pop songs” to get there by car. Seven minutes. And that’s from my driveway, to the carpark that is a one-minute walk from my building. Meaning I can leave home at 8:50, and even if the traffic is slow, still make it to a 9:00am lecture on time. If I’m going to a 12 noon lecture, I need to leave earlier, since there is never enough parking, but that is another matter.

Actually, I guess it’s related to what I’m about to rant about.

If I catch the bus to said 9:00am lecture, guess what time I need to be at the bus stop? Remembering that the transit time for a car was 7 minutes.

I need to be at the bus stop a full hour before my class starts.

One hour.

If the bus is on time, which is unlikely, then I’ll be early for my class. If the bus that is scheduled for half an hour later was on time, then I’ll arrive just in time for class. However, the buses are never on time. I don’t know if they are early or late, as it’s hard to say whether the bus that actually arrives is 3 minutes early, or 27 minutes late. I have had instances of me having been at the bus stop well before the due time of the bus, and having had to wait 45 minutes.

Now, this bus is traveling against the “peak” flow of traffic, and it is still managing to be off schedule.

I used to live on a bus route that was better serviced, but then I was traveling into town, but more importantly, it was a “smart” bus stop that told me how long it was before the next bus was coming. This would be useful for me now, since I can walk 10 minutes down the road to another bus route (but, let it be said, that doesn’t seem to make any difference to my travel and wait times, as the buses all come at the same time!) However, since I am going “against the flow” in terms of my direction, it is likely they wouldn’t even bother with e-boards on my side of the road.

I think one of the problems is that the transit authority in Adelaide don’t like to change timetables. They see this as a big issue, and will only change timetables about once or twice every three years.

Traffic conditions change much more regularly than this. I’d like them to reexamine every couple of months, and tweak the service. The worst thing about the system is that it doesn’t meet it’s timetables. Why not change the timetables? Make it a realistic setup, instead of forcing the drivers to stick to timetables that obviously aren’t maintainable.

I’d really like to see a decent electronic system. A combination of the smart stops, but better electronically available timetables. Not just PDF copies of the timetables on the website, but a proper, searchable system.

I envisage a Google maps-like page, where you can choose your start and finish points, and the system shows you all of the possible transit options between these points (including connections, if necessary), and when the vehicles are scheduled to run.

For instance, I could say I wanted to get into Adelaide from my house, and it would show me the next departure time of the train, and the bus, and the relevant arrival times.

I can currently use the “Nomad on Board” crappy system on my phone, but I need to know in advance the route numbers, and it’s really not efficient to compare them. And the times are out - it seems to think I’m in a different timezone to what I actually am anyway.

Missing NSButton Type

I’m trying to make a control that allows me to indicate when a record in my application is synced with the AddressBook person of the same name - I have made it so that I can only enable syncing when a person with the exact same name exists in both places, but to indicate it, I want to use a button that shows a pressed-in state, but also alters the image.

I want the image to be black-and-white by default, but when pressed in, it becomes coloured.

Apparently, this isn’t possible. You can either have a button which changes it’s image, or displays a pressed in look.

Might have to subclass it.

Update: You can subclass it, but there’s no need to. Just give yourself a reference to it (myButton, for instance), and then:

[[myButton cell] setShowsStateBy:NSPushInCell | NSCellLightsByContents | NSCellLightsByBackground];

Escalator Spinning

Gotta love this.
via Mister. D

Face Transformer

This is pretty cool. Upload an image of a face, and you can run some transforms on it to get alterations.

Try it out at http://www.faceofthefuture.org.uk/

For instance, from two pictures of me, here are some of what I may look like as an “Older” adult:

Picture 1.png Picture 3.png

The one on the top actually looks a little bit like my grandfather, and the one on the bottom looks an awful lot like my father. But older.

Some other funny ones. Afro-Caribbean:

Picture 4.png

East and west asian:

Picture 5.png Picture 6.png

And, saving the best until last, two different ape-men:

Picture 7.png Picture 2.png

NSSegmentedControl and Core Data.

It’s not possible to directly hook up an NSSegmentedControl (or NSSegmentedCell) to a Core Data controlled NSArrayController (or any, for that instance). I wanted to be able to use one of these controllers to allow the user to select one, many or all items from the array.

To define the behaviour a little bit more: You can select the first item in the control (which will be called “All”), and it will select or deselect all of the other items, depending on what it’s state becomes. If you click on another segment, then it will toggle the selection of that segment. If all segments are ON after pressing a segment, then the first segment must also display ON, otherwise it will be OFF.

I did it by creating a new class: SegmentController. (I know, I should put on a prefix…)

SegmentController has two required IBOutlet variables, which refer to the NSSegmentedControl, the NSArrayController, and a property NSMutableIndexSet, which stores, sets and gets the selection indexes (I think this should be indices, but I’ll stick with Apple’s convention). I also have a sortDescriptors array, so that this object can sort the array controller.

There are a couple of limitations, which I might look at how I deal with - for instance, the NSSegmentedControl must have exactly one more segment than the NSArrayController has items. I’m using it to select one or more days, and this number doesn’t change. It should be possible to dynamically create the right number of segments, and populate them with values (I even have a readonly field called shortName set aside in my Day objects for this), but at awakeFromNib the NSArrayController is still empty, and I can’t figure out a nice neat way to force a fetch.

Hooking up the elements in Interface builder is easy. Create the NSArrayController, and set that up however you need to. Do the same with the NSSegmentedControl - at this stage you’ll need to put values in each of the segments. Now, create a new instance of SegmentController (you might need to add the class files to your XCode project first). Connect the two outlets up to the required objects.

Now, in the Bindings Inspector, connect up you’ll want to make the Selection Indexes parameter point to the selectionIndexes model key of your Segment Controller object.

Finally, make the selector of the NSSegmentedControl point to the selectSegment: action of the Segment Controller.

I did notice a slight delay between deselecting one segment and the “All” segment deselecting. A simple optimisation - moving the call to segmentCount out of the loop test and into a local variable made it much smoother.

That should probably do it. It might need a bit of tweaking. You should be able to have multiple instances of this in your project, if it is required. It’s been designed that you’ll need a seperate one for each Segmented Control, as it refers to the objects it is connected to, rather than the sender of the message.

My source code is here: SegmentController.zip

Using moGenerator as part of the Build Process (XCode)

Using Core Data is awesome.

moGenerator makes it even better, as you can have Entitites defined as being of a particular class, and this code generator creates two classes for each Entity - a machine-readable one which is updatable by running the script again, and a human readable one that you can safely edit - it won’t be changed once it has been created.

You can easily make this tool a part of you build process.

First, create a new directory inside your project folder, I called mine MO. Then, cd to that directory, and run:

$ mogenerator -m ../*_DataModel.xcdatamodel

Then add the folder MO to your project.

Now add a new build phase script, and put into it:

cd MO
mogenerator -m ../*_DataModel.xcdatamodel

It’s not quite perfect - if you add a class, it won’t be added to your project automatically. You might be able to get around this by including the -includem switch, but then you won’t be able to have the .m files located in your project, else you will get duplicate symbol errors.

Mercurial and Trac

I’m enamoured with Mercurial for all of my version control needs. I’d like Versions to work with it, but the response I got from the developer suggests it never will. “UI of Versions is designed completely around the concept of centralized version control “ I can see that the same type of interface would work quite well with Mercurial, or another DVCS, without too many hassles.

Still, even just with the CLI, I’m coping.

A couple of days ago I started playing with Trac for bug tracking. I had used Bugzilla (not for my own projects, but I use it at work), and it doesn’t work properly with Mercurial. The good news is that Trac does, almost out of the box.

The trac-post-commit-hook works fine, and allows me to have a repository linked in with my trac store, and when changes are checked in that have “fixes ticket:X”, it automatically updates the trac for that ticket. It’s a bit of a repetitive process to set it up (you have to manually edit both the repo/.hg/hgrc file, and the trac/trac.ini file to add support for each other, but it’s easy enough to do).

The only annoyance is that the username isn’t quite the same in both - so changes made in Trac have the username matt, whilst those made in mercurial have the default username there - which includes my full name and my email address.

To-Many Relations in Core Data using Cocoa Bindings

I’m currently learning stacks (and maybe developing a useful application along the way) about Core Data and Cocoa Bindings.

I managed to hook up all of the “first level” Entities to UI elements, but was struggling a bit figurng out how to get the to-many relationships to work.

To make all elements of the type Person appear in an NSTableView, you can create an NSArrayController, set it to the Entity type, and put Person in the relevant field. Then all people will appear in the list.

If you have a manager, who might supervise zero or more people, then how do you get a sub-set of People. More specifically, how do you get a just the other side of a To-many relationship.

I thought I was going to have to resort to actually writing some code, and use a Predicate, or something like that. But there is an IB only method.

You can create an NSArrayController, and as well as putting in the Entity type (and hooking it up to the Managed Object Context), just put that it gets it’s Content Set from another object - in this case it would be People.selection.supervises (or whatever it is called).

This isn’t quite flawless - if you just hook up a button to the “add:” outlet, then it doesn’t quite add properly - the reverse of the attribute is not set. I had to make up an IBOutlet in my window controller that creates a new component, and sets the relationship up.

Which meant I ended up having to write two lines of code. For each relationship.

Core Data vs. SQL Alchemy vs. J2EE

Three languages. Three different Object Relational Mapping systems. One operating system.

Over the past couple of days, I’ve been madly learning how to create programs in Core Data, using Objective C and Cocoa. It’s given me plenty of food for thought, and made me perhaps think that it’s not that SQL Alchemy rocks my world, it’s just that J2EE/EJB is just ORM done wrong.

I actually got exposure to SQL Alchemy in detail before J2EE - I first came across them at the same time, but using SQL Alchemy was at work, and I basically had to learn in 2 days what a full semester worth of J2EE taught me. Perhaps that was just because learning the python stuff was so damn easy.

Now that I understand just how cool an Object Relational Mapping is, getting into Core Data was easy. Creating the same schema in SQL Alchemy (actually, using Elixir, so it was just object creation), and then in a Core Data xcdatamodel - basically the same process, was even simpler in Core Data: simply because it is a GUI tool, and you can see the whole model in one go, instead of having to scroll through a text file examining classes.

But doing GUI programming using the ORM is where Core Data really shines. Using Cocoa Bindings, you can just plonk down an NSTableView, and tell the object where it gets it’s data from. If you have two GUI widgets using the same data model, and you change selection in one, it even changes the selection in the other!

Core Data also helps look after Undo, Saving and all other sorts of goodness I haven’t even come across yet.

The only thing that Core Data isn’t good for is a multi-user system - or more precisely, a system where multiple users are accessing the data at the same time. I’ve used SOAP as the messenger format, where I had a rich client accessing services provided by my server, but this is cumbersome. I’ll just use Pylons, or perhaps Django to do a web application - where the interface is largely a Web Browser. In this instance, it will probably be best to just stick to a python-based approach. I’m tempted by WebObjects, but that would still require me to use Java.

If only Apple would release a distributed Core Data. I might be able to do something kind of cool with Distributed Objects, for a rich client, at least, but for Web, I may as well do the whole thing in python.

Disabling Menus

All of the cool kids are talking about Joel Spolsky’s post about disabling menus.

I agree with Gruber et. al., he’s dead wrong. Disabling a menu is a simple, yet powerful method of implicitly informing the user what she can or cannot do at the moment. Hiding menus, a-la Windows/Office “Show only recently used items”, however, it truly evil. This is not even hiding disabled items, just hiding ones that haven’t been used recently. Now, if I use one machine, and then go to another, it doesn’t know which ones I have used recently. Bullshit Incarnate!

Anyway, real users don’t use menus. Other than to learn the keyboard shortcuts.

The Old New Thing had a post way back in 2004, which has a mostly sensible answer: When do you disable an option and when do you remove it? Not strictly dealing with just menu items, but regardless, still logical.