Giter Site home page Giter Site logo

Comments (5)

 avatar commented on July 24, 2024

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.

ColinEberhardt avatar ColinEberhardt commented on July 24, 2024

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.

John-Lluch avatar John-Lluch commented on July 24, 2024

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.

ColinEberhardt avatar ColinEberhardt commented on July 24, 2024

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.

ndubbs avatar ndubbs commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.