Comments (5)
While I was one of the people in favor of allowing instance variables, there are some cases where using an instance variable directly instead of the property produces different results. For example, if your property is declared with the copy attribute, I do not believe (someone please correct me if I'm mistaken) that accessing the variable directly will automatically give you the copy behavior. Of course, you are free to code it yourself, but that is more prone to errors.
Note, we are in no way suggesting that it is bad practice to use private instance variables -- I use them almost exclusively in my own code, as do many others here. But for the tutorials, the committee decided to pick one way to do things and stick with it.
That said, you'll still see instance variables in some tutorials on the site, I am sure.
from objective-c-style-guide.
doing it is MUCH faster
I just want to call out this one point you made. For the vast majority of the code that developers write, clarity should be favoured over micro-optimisation. It is very rare that the solution to a performance problem is to simply circumnavigate properties by directly accessing instance variables.
And also, I am with @elephantronic … I am pro-ivar, but this is such a minor point, that I am more than happy to use private properties and write interesting tutorials, solve bigger issues, and (hopefully) inspire developers.
from objective-c-style-guide.
I am happy I am not the only one that is pro-ivar on production code. That's in my opinion more justifiable than using properties exclusively. And that's not a micro-optimisation. A class method using exclusively properties instead of their ivars can compile into code that is as much as 4 times larger, and up to 10 times slower or more. Just look at the assembly code generated or profile it. I won't call it a micro-optimisation. The only real reason for exclusive use of properties is taste, with ARC there is no longer a compelling reason for using private properties.
I expect that at some time in the future Apple will come out with Namespaces and Static (or Final) Methods. Yes, you can currently simulate namespaces by prefixing everything, and get the functionality of static methods by implementing C functions taking 'self' as the first argument. (Interestingly an argument named 'self' is allowed, so it is not a reserved word in this context). Unfortunately the required syntax does not match Obj-C method conventions.
When Apple implements the above, direct access to ivars will no longer be regarded as a non desirable thing. It may even turn into a recommended approach, as the current major issues of the language will suddenly become solved.
from objective-c-style-guide.
As I mentioned elsewhere, this was debated to death here #5 - we put it to the vote, and went with the majority. I doubt this will be changed!
from objective-c-style-guide.
The team voted to use private properties instead of instance variables. This decision is going to stick. As @ColinEberhardt mentioned, it was discussed throughly!
from objective-c-style-guide.
Related Issues (20)
- Init section contradicts Golden path section HOT 2
- Can we lint to enforce some of this style guide? HOT 6
- Symbol prefix: 2 vs. 3 characters HOT 26
- English should be used, really? HOT 7
- What's the point on using properties instead of instance variables? HOT 8
- License for this guide? HOT 1
- Not linking to Official Apple Style Guide HOT 1
- RWT prefix typo in constant definition HOT 1
- What is the recommended line width for Objective-C?
- Use style guide principles in examples
- arrayCount should be named something else HOT 4
- Contradiction between Init Methods and Golden Path
- Error handling
- I want make new branch for Korean ver.
- Google style guide URL is broken HOT 2
- Should self keyword should be used in init methods ?
- How do I indent something like this??? HOT 3
- Xcode behavior regarding indenting block
- 关于枚举(Enumerated Types)的想法
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from objective-c-style-guide.