Giter VIP home page Giter VIP logo

Comments (11)

mbbischoff avatar mbbischoff commented on August 15, 2024

The compiler is also fine with:

id <UIApplicationDelegate> appDelegate = UIApplication.sharedApplication.delegate;

but I'm pretty sure none of us would advocate that this style as a way to get the app delegate.

from objective-c-style-guide.

paulbruneau avatar paulbruneau commented on August 15, 2024

I'm going to start using that!

from objective-c-style-guide.

segiddins avatar segiddins commented on August 15, 2024

@paulbruneau the reason the compiler complains is because you are not assigning the result of the removeAllObjects method call to anything - in fact, you can't, since it's a void method. In Matt's example, he's using the result of the method, hence no compiler complaints.

from objective-c-style-guide.

paulbruneau avatar paulbruneau commented on August 15, 2024

If Apple wanted it to complain about myArray.count, surely it could. They apparently don't, and it doesn't.

from objective-c-style-guide.

bcapps avatar bcapps commented on August 15, 2024

If Apple had the compiler complain about every violation of how a construct is intended to be used, we wouldn't need a style guide.

from objective-c-style-guide.

paulbruneau avatar paulbruneau commented on August 15, 2024

No one said that, Straw Man. The decision is ours, I'm just providing some evidence to back my desire to not have to remember to put brackets around -count.

from objective-c-style-guide.

mbbischoff avatar mbbischoff commented on August 15, 2024

I also really like Brent's thoughts on this one because he mentions the problem of finding things later.

from objective-c-style-guide.

cdzombak avatar cdzombak commented on August 15, 2024

I believe the compiler warning @paulbruneau points out can actually provide some guidance about the intentions behind properties and when dot-notation for calling a method is appropriate.

If an operation is idempotent and has no side effects—by which I mean there are no visible modifications to state, either the receiver's or in any other object's—then property notation ought to be acceptable, particularly for trivial cases such as count and length.

I further assert that this usage, like proper usage of the ternary operator, "increases clarity [and] code neatness". It certainly hurts neither of those properties, and I believe it can help clarify the programmer's intention.

id <UIApplicationDelegate> appDelegate = UIApplication.sharedApplication.delegate;

Certainly, like anything else, this construct can be abused to create legal but unclear and unreadable code, and such usage should be prohibited.

I also really like Brent's thoughts on this one because he mentions the problem of finding things later.

I am simply not convinced this is enough of a problem to worry about. But setting that aside, I don't believe the argument applies here. Given my proposed usage rules, let's consider searching for the code that gets the managedObjectContext from a managed object. This method call could look like: object.managedObjectContext or [object managedObjectContext], but a search for managedObjectContext will find either usage.

If Apple had the compiler complain about every violation of how a construct is intended to be used, we wouldn't need a style guide.

You can make clang complain about a lot of violations of intended use :)

(Note that my definition of "side effect" is not "does something other than read an ivar", it's "a function or expression is said to have a side effect if, in addition to returning a value, it also modifies some state or has an observable interaction with calling functions of the outside world.", per http://en.wikipedia.org/wiki/Side_effect_(computer_science) )

from objective-c-style-guide.

bcapps avatar bcapps commented on August 15, 2024

These are all properties in iOS 8, so this isn't needed any longer.

from objective-c-style-guide.

paulbruneau avatar paulbruneau commented on August 15, 2024

I was right! Yay!

from objective-c-style-guide.

cdzombak avatar cdzombak commented on August 15, 2024

I was right! Yay!

:D

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.