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

How to break long lines? #27

Closed ColinEberhardt closed 10 years ago

ColinEberhardt commented 10 years ago

This is less relevant for the web, but important for book authors. I think it would be great to provide some guidance about how to break long lines of code over multiple lines.

rwenderlich commented 10 years ago

Good idea. My very rough attempt at defining a rule:

When a line of code wraps beyond a printed line, break the line at the next syntax appropriate spot. The new line(s) should be indented with two spaces after the previous line. Example:

_productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];

In print this line would wrap, so should be reformatted to:

_productsRequest = [[SKProductsRequest alloc] 
  initWithProductIdentifiers:productIdentifiers];

This might not be the best guideline, so I'm open to discussion here.

hollance commented 10 years ago

In the previous version of the iOS Apprentice, when a line was wrapped it had a special character inserted at the end that indicated this (a little arrow). That might be worth looking into.

For the current version, which is done in Word, when I wrap a line I shift it over all the way to the right so that it is obvious that it is wrapped. Not ideal but I find that clearer than simply indenting it.

(Choosing a slightly smaller font for code blocks will also help prevent wrapping.)

Sent from my iPhone

On 12 nov. 2013, at 20:11, rwenderlich notifications@github.com wrote:

Good idea. My very rough attempt at defining a rule:

When a line of code wraps beyond a printed line, break the line at the next syntax appropriate spot. The new line(s) should be indented with two spaces after the previous line. Example:

_productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers]; In print this line would wrap, so should be reformatted to:

_productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers]; This might not be the best guideline, so I'm open to discussion here.

— Reply to this email directly or view it on GitHub.

ndubbs commented 10 years ago

I've seen the arrow used in other books too. It is very difficult to cut and paste when viewing the electronic versions.

rwenderlich commented 10 years ago

Putting special characters at the end of a line when it wraps is a maintenance nightmare, I'd vote against that until we have better tooling support to do that automatically :]

A smaller font for code blocks is a good idea and something we should do for future books for sure though.

funkyboy commented 10 years ago

Agree on this.

Cesare Rocchi studiomagnolia.com

On Nov 17, 2013, at 6:17 PM, rwenderlich notifications@github.com wrote:

Putting special characters at the end of a line when it wraps is a maintenance nightmare, I'd vote against that until we have better tooling support to do that automatically :]

A smaller font for code blocks is a good idea and something we should do for future books for sure though.

— Reply to this email directly or view it on GitHub.