Over the years I have tweaked which compiler warnings I use. There’s one in particular that I used to turn on but will turn off from now on: GCC_WARN_SHADOW.

GCC_WARN_SHADOW is essentially drawing your attention to you possibly doing something other than you intended. This is like most warnings, but the difference is that the behaviour GCC_WARN_SHADOW is blocking is very useful.

Continue reading Against GCC_WARN_SHADOW

C99 initializers

You probably know CGRectMake, but did you know it’s not the only way to make rectangles? It’s not even the best way, really.

There’s also C99 initializer syntax.

The main advantage to the C99 syntax is that it gives you some very Objective-C like syntax, where the fields are close to the values rather than implied by positioning. (That’s not to say this is intentionally similar, or that it’s the only advantage. But it is nice.) It also provides type checking, and since fields are named it catches drifts in meaning that you otherwise wouldn’t catch.

It’s sometimes slightly more typing, but I use it everywhere now.

Continue reading C99 initializers

Why you should use instancetype instead of id

In my previous entry, I discussed when id will be promoted to instancetype. But now that I’ve explained this, I’d like to explain why you should understand this but not rely on it. Instead, you should use instancetype directly.

Let me start with this bold statement, then I’ll back up and explain it: Use instancetype whenever it’s appropriate, which is whenever a class returns an instance of that same class.

Continue reading Why you should use instancetype instead of id