Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we use compound literal syntax? #14

Closed
ColinEberhardt opened this issue Nov 8, 2013 · 7 comments
Closed

Should we use compound literal syntax? #14

ColinEberhardt opened this issue Nov 8, 2013 · 7 comments
Labels

Comments

@ColinEberhardt
Copy link
Contributor

While tech editing i7t I realised we have an inconsistency with some people using compound literal syntax:

self.imageView.frame = (CGRect){ .origin = CGPointZero, .size = self.photo.size };

Should we use this less-often used, yet highly useful syntax? Or use the CGRectMake macro for simplicity / familiarity?

My gut feeling is that we should use this feature, but ensure that the code style guidelines are easily discovered by reader (i.e. linked to by every tutorial), and that we make one goal of the style guideline to be educating the reader.

@hollance
Copy link
Member

hollance commented Nov 8, 2013

My vote: yes. Reason: it's a useful part of the language.

@gregheo
Copy link
Contributor

gregheo commented Nov 8, 2013

I would say use it for your own structs or third-party ones without helper functions/macros only.

I think the (semi-)official Apple line is to use the CGGeometry functions for creating and accessing CGRects and that's more what you see out in the wild too.

@funkyboy
Copy link
Contributor

funkyboy commented Nov 9, 2013

I prefer CGRectMake. I feel it's more widely adopted.

@moayes
Copy link
Member

moayes commented Nov 10, 2013

+1 CGRectMake

@icanzilb
Copy link
Member

+1 on using the Apple provided geometry functions.

Also if you ever use blah = (CGRect){...} you immediately start a comment war on "what if Apple changes the CGRect underlying structure one day?"

@rwenderlich
Copy link
Member

+1 CGRectMake and similar.

@ghost
Copy link

ghost commented Nov 12, 2013

+1 on always using the geometry functions, as per the documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants