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

Should we use compound literal syntax? #14

Closed ColinEberhardt closed 10 years ago

ColinEberhardt commented 11 years ago

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 commented 11 years ago

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

gregheo commented 11 years ago

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 commented 11 years ago

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

moayes commented 10 years ago

+1 CGRectMake

icanzilb commented 10 years ago

+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 commented 10 years ago

+1 CGRectMake and similar.

ghost commented 10 years ago

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