Apple Cocoa Cavil

I’m going to try to sound more like Andy Rooney1 up here on this blog. Also, how about I indicate when the boooring technical notes begin and end with technical and interesting.

This is one of my favorite xkcd comics. It really speaks to my experience. Usually I can pull away before I’ve finished registering for comments. Sometimes I’m halfway through a closely reasoned argument when I realize how perfectly pointless and non-personal-goal-advancing my actions are. Then, in the worst case scenario, there I am mixing it up with the other comment-warriors. Here’s me windmilling my way through a post about dolphin killing on Japanprobe. This used to be the url for a pitched brawl in which I interjected a few uninformed comments. Etcetera.

Anyway, I thought I’d write this post at a more meta level to dissuade myself from commenting elsewhere. So here goes (technical):

Have you ever noticed that Objective-C is really, really weird? Like, they just took all the C- and C++- style conventions and changed them? Me too. And on top of that it’s compiled and you do memory management and the engineers make APIs that have objects called NSCamelCasedFactoryMethodObjectFacilitator2. Okay, so then someone makes a script-y dynamic thing for managing the Objective-C stuff, good idea. And when designing this scripting interface they make the following language syntax design decisions:

Finally, the instruction separator is a dot, like in English sentences:
myString := ‘hello’.

The following example shows how to send a message to an object:
myString class

See, this is funny, because it’s completely different from every other programming language3. That is all.

Umm, but there is a somewhat interesting take-away. Both Apple and Microsoft have designed really sucky APIs (in terms of intuitability rather than functionality) , compared to which GTK is fairly sane (it gets a bit clunky when dealing with “GtkIter” operations). But the MacOS developers follow Apple’s improvements of this API, cooing over the increased simplicity afforded by the new NSMakesYourToastRegistry. It’s the same with new C#/ Windows API developments. So (this is actually the interesting part) the lesson is that when people work within a “closed” development system, they lose their sense about good and bad design!4

Here’s the idea. Closed development systems don’t get good feedback and don’t have good change mechanisms, so even very good engineers (probably Apple’s are some of the best) end up working in the dark a little. It gets all culty, because there’s an elect that makes the design decisions and a laity that passively learns the new scripture. And everyone’s straining so hard to understand what the design class hath laid down that they’re no longer perceiving the design objectively. And proprietary lock-in helps, because it leads to fatalism (“what can I do, switch to Windows?”). There are all these weird little island communities where the natives are effectively locked-in to a platform because they’ve already invested the energy to understand its weird design. This isn’t even necessarily a proprietary vs. opensource thing. There are strange over-designed opensource projects that aren’t particularly open because of this class division (and most opensource projects rely on only 1-3 main contributors, it seems). All I’m saying is that bad APIs / development languages happen when designers aren’t being influenced in the right way by the end-user developers, and I’m speculating that this has to do with particular attitudes and processes associated with proprietary code and also a kind of design elitism. I mean, doesn’t Objective-C code (as code) suck?


  1. I include this link because I think this already marginal reference will become incomprehensible in ten years.[back]
  2. Yeah, I’ve got their number all right.[back]
  3. Actually, these are pretty interesting design decisions. The := assignment syntax is wack, but probably necessary for named arguments or something. The dot on the end is okay, but you’re moving the OO-messaging operator into the generally useless semicolon position. By using the space for messaging, you’re now saying “subject verbs(args)” instead of “subject.verb object, args” (in Ruby you can omit the parens for a function). [back]
  4. So I sort of believe that. Mainly I’m bitter because I can’t get some code to work on MacOS.[back]


12:00 PM me: Does [your company] use whitespace or tabs?

12:01 PM Ian: you mean spaces?

everyone uses spaces.

four spaces, in fact.

It’s Guido gospel.

12:00 PM me: Does [your company] use whitespace or tabs?

12:01 PM Ian: you mean spaces?

everyone uses spaces.

four spaces, in fact.

It’s Guido gospel.

me: But spaces suck.

12:02 PM Ian: not even remotely.

me: I know that’s the gospel, but it doesn’t make sense.

Ian: It makes excellent sense.

Easier to deal with. Only one kind of whitespace.

me: Do Windows and Linux use different tab characters?

Ian: no.

12:03 PM me: Dude, two-space tabs.

Google uses two-space whitespace, btw.

Ian: well, nobody else does.

me: I know. It drives me crazy.

12:04 PM

Ian: I like four. Everything lines up properly.

def myfunc():

me: Eh. I use two-space tabs in Ruby, and I don’t like to change when I program in Python. Gajim uses tabs, though.

Ian: We were never told this, it’s just the general rule.

12:05 PM me: Well, it’ll break if you mix them.

Ian: I am aware.

me: That’s retarded.

Ian: Not really. It has to break.

12:06 PM me: I know, but it’s still retarded.

12:07 PM

Ian: I mean, it’s been the standard forever. Tabs are bloody annoying, since they look like spaces but aren’t.

me: But tabs are semantic! Just turn on printer’s symbols if it bothers you.

12:08 PM What’s annoying is backspacing and it goes back…one…character…at...a..time.

12:10 PM I swear, future generation will look back on this as utter madness.

6 minutes

12:17 PM Ian: well. I don’t have to do that.

Vim does tht for me.

12:18 PM me: I thought so.

Ian: it backspaces a tab at a time if appropriate, otherwise space. It’s perfectly natural.

me: Well, that’s not so bad.

Ian: but my code will always render in exactly the same way on everyone’s machine. Lines will have the same length.

12:19 PM if it’s 79 chars, it won’t wrap on somebody else’s editor who has their tabs set to 8 or something

me: I’m right, though. But it is utter gibbering insanity.

What is sacred in web pages is verboten in code. This is ridiculous to me.

12:20 PM Ian: what is sacred in web pages?

whitespace is ignored.

me: Tab means indent!

Ian: tab doesn’t mean a damn thing in a web page

me: User sets the indent!

I know. Using space is like using <br /> in webpages.

12:21 PM You’re trying to control display.

And you call it a virtue.

Ian: well, yeah. html isn’t for content.

me: Madness.

Ian: indentation is set in CSS

me: Yes!

That’s my point.

12:22 PM Tab means <indent />

Ian: But it doesn’t.

In a web page, “beginning of paragraph” means <indent/>

12:23 PM there’s no tabbing.

You can’t artificially insert a tab character.

me: If someone said, don’t use <p>, use <br />, some users change the margins on paragraphs, you’d say he was an idiot.

Ian: You can’t double-tab.

no users change the margins on paragraphs. My own CSS does.

me: I understand. I’m saying tab means indent, a semantic element. It means level of scope in Python.

12:24 PM Ian: but it doesn’t. whitespace means level of scope.

me: But if they wanted to, they could. Then it wouldn’t display properly. Best to use <br />

Ian: no, they couldn’t.

me: Ahh!!!

12:25 PM Yes, they could. They could change the default stylesheet, and make it !important.

Ian: The end user doesn’t control the display of a web page, except for text size.

me: Ugh.

They have a degenerative sight disorder that requires the paragraphs to be widely spaced.

12:27 PM I’m saying the principle that is sacred in web pages is considered a liability in code, and only really in Python and shell scripts, because indentation is just for looks in C++, Ruby, Java, etc.

Ian: But no one will ever do that. I don’t understand how this is at all relevant. Code display has nothing to do with layout. The goal is to do it the same way as everybody else.

and that sacred principle is…?

i still don’t get it.

Since there are no tab characters in web pages.

12:28 PM me: Let the user determine presentation. That’s the principle. If they want to apply another stylesheet that makes your page look stupid, so be it.

Ian: But that isn’t a sacred principle in web pages.

me: Yes it is.

It’s why we don’t use tables and <br /> for everything. It’s why we don’t compose web pages in Word.

12:29 PM Ian: No, it isn’t.

We don’t do it that way because it’s extremely limited.

And it won’t display the way /we/ want it to.

me: Dude, wtf? Use flash if you want to control display.

12:30 PM Ian: But that’s totally wrong! That’s warped!

me: I understand that the user usually views a page the way you want him to.

But he doesn’t have to.

Ian: Always. Unless they’re hacking it.

In which case I don’t care.

12:31 PM Build the page to deal with big text and small viewports, but otherwise whatever.

me: What are you talking about? They can view a page in Lynx, or with a screen reader, or using a Greasemonkey script, or whatever.

12:32 PM

Ian: There aren’t other variations, except for the extreme outliers where people hack your CSS.

me: If it’s important to have code displayed with a certain size tab, you could include a hint at the top.

Ian: People using greasemonkey scripts know the page will be fucked up. Lynx doesn’t apply, since it strips CSS. Screen readers are a completely different thing.

12:33 PM me: I am horrified.

Ian: I dunno where you get this insane idea.

me: I don’t know why you’re fighting me on this. The whitespace thing, sure. But not this principle.

12:34 PM Ian: You can’t account for all users. Especially not if they are making up their own CSS.

me: <br />This is a paragraph.<br /> See, it’s better? Works every time, no matter what the user does.

Ian: It’s impossible to predict that.

Except you can’t do anything. That’s idiotic.

12:35 PM me: Yes, because it’s attempting to define display with markup.

Ian: but <p> tags aren’t for the benefit of the user

they are boxes with default CSS that you, the designer, change.

12:36 PM They’re roughly semantic, but you don’t use them wherever you have text.

me: Okay, I get you.

But a screen reader would use the paragraphs to know where to pause, for example.

Ian: They certainly don’t mean “paragraph,” and they’re only indented if you explicitly set text-indent.

If it’s a screen reader, you have a different style sheet

12:37 PM me: Yes!

Ian: and you use pause-before:blah

in the CSS

me: Do you define a css audio stylesheet for your pages?

Ian: Hell no.

me: So they use the default settings.

Ian: Certainly not for [my company].

12:38 PM me: It’s whatever they want.

And you can override stylesheet settings with !important.

Ian: Also it strips out all layout, so it’s irrelevant.

me: Huh? That’s layout. It doesn’t read them in any order.

12:39 PM Ian: WHO can?

The blind greasemonkey users?

me: Yes.

Ian: I will never, ever design a page for a blind greasemonkey user.

me: Argh.

Please see the analogy.

12:40 PM

Ian: I see what you’re getting at, but I think you’re totally wrong.

The user /can/ define presentation, but only by /breaking/ the original code and rewriting it.

Or using an application that discards certain things, like a screen reader.

me: “As god is my witness, I will never allow another programmer to view my code at anything but four spaces to an indent level. I would rather die.”

Ian: Or lynx.

12:41 PM So if you really want to, you can, before editing any code, translate all spaces into tabs, then do your editing, then retranslate and save.

That is roughly comparable.

It’s a simple greasemonkey script.

me: You’re saying it’s something freaky, because it’s rare. But it’s just rare. It’s something that’s built in to html.

12:42 PM

Ian: if you just have to have your indentation be a certain width, you can. But who the hell cares? The end user of code is the computer.

You make it useful for future coders, of course

me: You do know that all the CSS Zen Garden sheets refer to the same page, right?

Ian: Make it readable and whatnot


It’s a basic HTML structure.

12:44 PM divs with some ps and uls

me: Anyways, I can’t change the whitespace to tabs. People would yell at me.

Ian: Well, then you change it back, before saving.

me: Whywhywhy?

Ian: Because code isn’t written for you.

It’s written for everyone.

12:45 PM I take that back: it isn’t written for anyone.

it’s written to be run.

You make it readable, not pretty

more to the point: you make it /editable/

12:46 PM (which web pages aren’t)

me: What’s so bad about tabs??? They only occur at the beginning of the line. If there’s one, it means one level of indent, two two levels, etc.

If the user chooses to view them at 4 spaces per tab, they display like that, if 2, then that.

12:47 PM

Ian: Nothing in particular, except it’s a whole nother character to deal with. If “whitespace=space” it’s easier.

From a coding perspective.

I don’t have to wonder if there are tabs anywhere, because they’re all spaces.

12:48 PM me: The thing is, it doesn’t even matter in Ruby! I can write the whole script without any beginning of line spaces at all! It’s only Python that cares! And Guido bases it on the C++ coding standard, where it also doesn’t matter!

Ian: If I want to indent only one space, I can.

If I want to line up my dictionary values, I can.

12:49 PM me: In Gedit, tabs are arrows and spaces are dots.

Ian: If you turn that shit on. But most people don’t. Most people use emacs and vim.

me: Well, okay, there’s something.

12:50 PMThings only get out of whack if you mix tabs and spaces, it’s true.

Ian: mostly it’s just annoying to have arrows and dots scattered throughout your code.

me: It makes it clear for me.

12:51 PM I don’t understand why “knowing if whitespace is a tab or a space” is more important than knowing that you haven’t accidentally backspaced and set a line to three space indent instead of four.

That happens all the time.

12:52 PM Ian: that never happens.

I have autoindentation on.

me: It’s happened to me. It’s happened in code that I’ve downloaded.

Ian: Then someone wrote it poorly.

12:53 PM That happened to me when I used gedit, which is a stupid application.

or notepad or something.

me: All this effort for a marginal problem of “knowing whether a character is a whitespace or tab” when it introduces another marginal problem.

Ian: But there are no problems.

12:54 PM My code is always clean, no matter who looks at it.

me: Just like there were no problems with the five year plans!


12:55 PM Ian: Unless they have their line width set to something short. But then they would be an iiot.


me: Google uses two spaces! Four spaces is too much!

12:56 PM Ian: Google uses two spaces because fewer spaces translate into less downloaded.

me: Let the programmer decide!

Ian: Any web programmer worth his or her salt packs their code before uploading.

12:57 PM me: No, because code shouldn’t be nested beyond more than two or three levels anyway.

So it should be easy enough to read at two spaces.

Ian: ?

12:58 PM I mean, yeah, code rarely gets that deep

Except not really, when you have vars inside functions inside functions inside classes.

me: Most Ruby code uses two spaces and it’s easy to read.

12:59 PM About four or five levels.

Ian: Well, if Ruby takes over the world, perhaps other people will do it that way.