Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does google suggest to use trailing underscores when naming iVars in Objective-C?

In Google's Objective-C Style guide which is follow by many people , Google says

Class member variables have trailing underscores

Why? Is there any good reason for doing this? I found apple usually name an ivar when beginning underscore.

like image 489
Jimmy Avatar asked Apr 12 '11 01:04

Jimmy


2 Answers

I prefer trailing underscores because if I have:

int test_;

I can type 't' and it will appear in the code completion immediately.

With

int _test;

I have to type '_t' to get to the T's in code completion.

Whether that's true or not, not sure, but that's what I've convinced myself of.

like image 196
MarkPowell Avatar answered Nov 19 '22 06:11

MarkPowell


Heavy users of Core Data will have also noticed that Core Data attributes cannot begin with non-alpha characters. If you want to name ivars consistently across your app and various projects, this is another reason to append, rather than prepend, your ivars with an underscore.

If you're not using Core Data a lot, or you don't have OCD tendencies towards consistency in naming conventions, then whatever works best for you is probably the right answer.

like image 5
prairiedogg Avatar answered Nov 19 '22 06:11

prairiedogg