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 628 forks source link

English should be used, really? #40

Closed John-Lluch closed 10 years ago

John-Lluch commented 10 years ago

I get the point on using (a particular sort of) English. Of course on a guide something must be agreed, but I want to point out that using English is a big a source of problems. This is because Apple uses it. Try to add an instance variable named _alpha to an UIView subclass and you will see. Crashes and odd things are guaranteed to happen without any previous warning. I avoid English in my code for that reason but other than using a different language, is there a consistent way to prevent this kind of issue?. What do English coders to prevent it? a custom prefix or suffix on each instance var?

ghost commented 10 years ago

Your example about using an instance variable with a name like _alpha is not a problem with using English, it's a problem with using names of common properties. Anytime you subclass an existing class, you need to be aware of its existing makeup.

I have coded for 16 years on some extremely large codebases, and in my experience using English has solved more problems than it has ever caused. But if it helps in your own code, you could try prefixing variables with something exotic, like _mySpecialPrefixVarName, much like Apple recommends prefixing class names for the same reason.

ColinEberhardt commented 10 years ago

I totally agree with @elephantronic obfuscation of all your variable names to avoid accidental collisions is not a good idea. This is a problem that is rare, and when the case arises, should be solved on a case-by-case basis.

John-Lluch commented 10 years ago

It's funny to regard the use of a Language different than English as "obfuscation". I suppose you realize I am not English native. Wow, this remains me of something, lol.

Anyway, is there actually a way or tool to determine which variable names are taken by superclases?. There must be cases where a variable or property is used that is not documented. I faced this problem in the past (when using English) more often than I had liked. As far as I can tell the compiler does not warn on this, or does it?

Thanks

ColinEberhardt commented 10 years ago

It's funny to regard the use of a Language different than English as "obfuscation"

Reading my comment back, it probably does sound like that. I really don't regard languages other than English to be an obfuscation!

It just feels like an odd proposal, to write our code in Italian, Spanish or French to minimise the potential collision with the Apple APIs that are written in (American) English.

John-Lluch commented 10 years ago

Hi Collin, no offence taken. That was just a comment not a proposal. I fully understand the benefits of adhering to a particular language for consistence, and English is the de-facto standard in this field. I formerly worked on a team that found English to be less productive and harder to document because it was not their everyday language. That's not odd, just depends on the team.

ndubbs commented 10 years ago

US english is used because it matches the names of properties and methods in the programming language. This decision is based to help beginners and non-english speaking readers. It can be challenging enough to learn a new programming language without intertwining the nuances of multiple spoken languages.

John-Lluch commented 10 years ago

Hi ndubbs. I understand this is off-topic, but is there actually a way to tell which properties or variables might be used on a superclass to avoid using the same names on a subclass. I had once a hard time finding a bug on a third party code that had _alpha as a variable in a UIView subclass.