hadley/r-pkgs — pull request #102 by jimhester (2014-10-23 15:26:58+00:00)
Title: Don't cuddle `else`

I realize this is your personal style, so you are welcome to reject this change, but I wanted to provide some arguments against promoting cuddled `else`. I used to use cuddled `else` as well until I was persuaded otherwise.

First the argument for a cuddled `else` is that it saves a line of whitespace. While this is a nice thing in general, with modern monitors you generally have a lot of vertical space to work with.

However cuddled `else` has the following readability drawbacks. It no longer maintains vertical alignment with the controlling `if`, nor with it's own closing bracket. This makes it more difficult to identify what controlling expression goes with which block.

It is also more difficult to distinguish the `else` block visually, because you lose the left-brace only line as a separator. This makes it more difficult to visually 'chunk' the code.

A minor practical benefit to un-cuddled `else` is that you can easily comment out the `else` by simply commenting out the block. With cuddled `else` you have to move the else to a new line before commenting. This benefit is more pronounced when you would like to comment individual nested `if-else` constructs.

```r
if (test) {
body
}
#else if (test2) {
# body2
#}
else {
body3
}
```
If you were using cuddled `else` in the above code you would have to manually edit all three of the blocks, rather than simply commenting out the middle one.

I took most of these arguments from [Damian Conways 'Perl Best Practices'](http://books.google.com/books?id=gJf9tI2mytIC&lpg=PT46&dq=perl%20best%20practices%20Don%E2%80%99t%20cuddle%20an%20else&pg=PT46#v=onepage&q=perl%20best%20practices%20Don%E2%80%99t%20cuddle%20an%20else&f=false), which is what finally convinced me that un-cuddled `else` was preferable (for me at least).

I assign the copyright of this contribution to Hadley Wickham.