kodecocodes / objective-c-style-guide

A style guide that outlines the coding conventions for Kodeco
http://www.raywenderlich.com/62570/objective-c-style-guide
3.1k stars 625 forks source link

arrayCount should be named something else #59

Open franklau12 opened 9 years ago

franklau12 commented 9 years ago

Is it possible to change this line: NSInteger arrayCount = [self.array count];

to either NSInteger names = self.names.count, or NSInteger names = [self.names count]

This is because I've seen a lot of inexperienced developers use array when naming an array, even though they should name using as high level of abstraction as possible (i.e. instead of nameArray, they should use names). And I think your style guide has a big influence within the Objective-C community.

Thanks

funkyboy commented 9 years ago

Maybe you mean

NSInteger namesCount = ...

?

gregheo commented 9 years ago

I'd call the array names and the counter nameCount but otherwise that makes sense to me.

The bigger point is count was a method and not a property in the old days, but we should switch to self.names.count. Perhaps we have Swift to thank for turning such things into properties in the modern runtime!

franklau12 commented 9 years ago

Thanks for the quick reply guys, I did mean nameCount or numNames, sorry :( Yes, Thanks for pointing that out, Greg. self.name.count would be better since count is a property

franklau12 commented 9 years ago

Could we do it this way. Since count is now a property, it'd be now under the preferred section

Preferred: NSInteger nameCount = self.names.count;

Not Preferred: NSInteger nameCount = [self.names count];