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

Prefer trailing dots over leading dots #2

Merged
merged 1 commit into from
May 25, 2017

Conversation

amiel
Copy link
Contributor

@amiel amiel commented May 24, 2017

The community styleguide did not pick one and instead encourages teams to pick one.

There is a lengthy discussion here: rubocop/ruby-style-guide#176 and is a pretty interesting read.

Note that this only applies to ruby.

What are we talking about?

To clarify, here's what we're talking about:

  # trailing dots
  one.two.three.
    four

  # leading dots
  one.two.three
    .four

My argument

Having read through the discussion, I propose we use trailing dots.

It seems like the arguments can be oversimplified to mostly (source:

  • leading dots is more visually pleasing
  • trailing dots has more functional advantages

Here are some of the arguments I like:

  • Basically, when continuing lines like this, you need context on both lines. Using the trailing dot gives context on the first line, indentation gives context on the second line (source).
  • Code written with leading dots cannot be pasted in to irb/pry (source).
  • Loading dots are easier for parsers (source).
  • There are some scenarios in which leading dots can cause bugs (source).

@amiel amiel requested review from nathancarnes and kyle-rader May 24, 2017 19:58
@amiel
Copy link
Contributor Author

amiel commented May 24, 2017

I'd love input from everyone on this, but will specifically wait for review from the people that use ruby the most ( @kyle-rader and @nathancarnes ).

Copy link
Contributor

@kyle-rader kyle-rader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amiel @nathancarnes I agree with trailing dots.
I think the summary of arguments from @amiel is pretty good, but this guy adds some more points

Notably, that leading dots don't even work in Ruby 1.8, and there is an actual performance penalty.

Copy link

@nathancarnes nathancarnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me.

But, more broadly: do not do either except in rare cases. It's probably an indication you have a terrible, terrible Demeter violation.

That is, trailing dots over leading dots
@amiel amiel force-pushed the choose-dot-continuation-style branch from b76b193 to a13f1e9 Compare May 25, 2017 16:30
@amiel amiel merged commit e4037f2 into master May 25, 2017
@amiel amiel deleted the choose-dot-continuation-style branch May 25, 2017 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants