Motivations for Decorating Instance Variables

Mark Dalyrymple on the Big Nerd Ranch Blog:

These synthesizes tell the compiler that each property should be backed by an instance variable whose name is prefixed by an underscore. The compiler names the backing instance variable after the property if you don’t provide an alternative.

OK, so why do programmers do this? Seems like it’s just extra busywork. I see two main reasons: one involves style, and one involves safety.

I’m amazed at the number of bugs I see in people’s code that’s due to not using properties consistently. Please do this.

I sort of disagree with this part though:

Some people use a trailing underscore (that’s Google’s style), and folks also prefix or suffix with “m” for “member”. It’s all fine. One nice thing about the leading underscore is that it automatically participates in Key-Value Coding.

Just use an underscore — Apple says to.