include '.' on first line of multiline chained method invocations by lcowell · Pull Request #176 · rubocop/ruby-style-guide (original) (raw)

I've been using trailing dots, with the second line indented.

As stated by others, the point is that when you read that line, you know that the statement continues on the next line. To me, that's more natural than reading a statement that looks complete in itself but actually continues in an oh-by-he-way fashion.

@jdalbert's solution fixes the problem with aesthetics but doesn't change the fact that the best place to indicate continuation of that statement is before you get to the next line.

bad - need to consult first line to understand second line

one.two.three. four

good - it's immediately clear what's going on the second line

one.two.three .four

I have two problems with this rationale. For one, you have to read both lines no matter what. You can't read four or .four and have any clue what's going on without reading the preceding line. The only way in which the second line might help with that is that it starts with a ., but if it's really just a matter of visually indicating that the previous line needs to be looked at, I think the fact that the line is indented does this fairly effectively.

Lastly, the second example is helpful only so far as you're reading or scanning the code from bottom to top -- which I suppose you could -- but I don't get why readability in that direction would be preferred over readability from top to bottom.

We want to make it clear that the second line goes with the first, but we don't want to make it clear that the first line goes with the second. This seems backwards. Trailing dot and second line indentation addresses the issue from either direction. This is a no-brainer if you ask me.