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

Chain method calls omitting parentheses #3398

Closed
Industrial opened this issue Mar 6, 2014 · 11 comments
Closed

Chain method calls omitting parentheses #3398

Industrial opened this issue Mar 6, 2014 · 11 comments
Labels

Comments

@Industrial
Copy link

Hi.

I often stumble over scenario's where I have some code that calls a method with more then one argument and need to chain a call after it;

myMethod 1, 2, 3

With the 1.7.0 syntax changes, this means I could write it as;

myMethod 1, 2, 3
  .otherMethod 'more', 'args'
  .maybeSomethingElse {}, [], 4, 5, 6

Why not also allow the syntax to live on one line?

myMethod 1, 2, 3 .otherMethod 4, 5, 6 .otherMethod 7, 8, 9

With the current syntax, it means I should add a lot of parentheses or restructure the code vertically, which is not that nice if the arguments and method names are small and there's several invocations and I'd argue that this:

myMethod 1, 2, 3 .otherMethod 4, 5, 6
myMethod 1, 2, 3 .otherMethod 4, 5, 6
myMethod 1, 2, 3 .otherMethod 4, 5, 6

looks way better then this:

myMethod 1, 2, 3
  .otherMethod 4, 5, 6
myMethod 1, 2, 3
  .otherMethod 4, 5, 6
myMethod 1, 2, 3
  .otherMethod 4, 5, 6

and I'd argue that the space before the dot makes the meaning unambiguous (not belonging to the last argument of the previous method but the return of that call).

gr,

Tom

@AriaMinaei
Copy link

+1

On Thu, Mar 6, 2014 at 1:27 PM, Tom Wieland notifications@github.comwrote:

Hi.

I often stumble over scenario's where I have some code that calls a method
with more then one argument and need to chain a call after it;

myMethod 1, 2, 3

With the 1.7.0 syntax changes, this means I could write it as;

myMethod 1, 2, 3
.otherMethod 'more', 'args'
.maybeSomethingElse {}, [], 4, 5, 6

Why not also allow the syntax to live on one line?

myMethod 1, 2, 3 .otherMethod 4, 5, 6 .otherMethod 7, 8, 9

With the current syntax, it means I should add a lot of parentheses or
restructure the code vertically, which is not that nice if the arguments
and method names are small and there's several invocations and I'd argue
that this:

myMethod 1, 2, 3 .otherMethod 4, 5, 6myMethod 1, 2, 3 .otherMethod 4, 5, 6myMethod 1, 2, 3 .otherMethod 4, 5, 6

looks way better then this:

myMethod 1, 2, 3
.otherMethod 4, 5, 6myMethod 1, 2, 3
.otherMethod 4, 5, 6myMethod 1, 2, 3
.otherMethod 4, 5, 6

and I'd argue that the space before the dot makes the meaning unambiguous
(not belonging to the last argument of the previous method but the return
of that call).

gr,

Tom

Reply to this email directly or view it on GitHubhttps://github.com//issues/3398
.

@jashkenas
Copy link
Owner

Nice idea, but...

Why not also allow the syntax to live on one line?

Because then it reads poorly, as you've demonstrated.

@michaelficarra
Copy link
Collaborator

No way! Coco and LiveScript have this, and I love the improved consistency.

@vendethiel
Copy link
Collaborator

I, too, like it a lot in Coco/LS.

@Industrial
Copy link
Author

I'd say

myMethod(1, 2, 3).otherMethod 4, 5, 6

looks worse.

@jashkenas
Copy link
Owner

Reopened for discussion, but...

The original notion with . accessors was that they would bind tightly to whatever preceded them, regardless of whitespace.

Thus:

obj
  .this
  .that

... would chain tightly against the immediately preceding token.

We've now stepped away from that original design with the 1.7.0 syntax change (which I'm iffy on, for that reason). But continuing further seems quite unwise — and massively backwards incompatible to boot.

@jashkenas jashkenas reopened this Mar 6, 2014
@jashkenas jashkenas removed the wontfix label Mar 6, 2014
@vendethiel
Copy link
Collaborator

I really think (a .b) is of poor style.

@xyzwt
Copy link

xyzwt commented Mar 11, 2014

Good idea but it a poor style so maybe it would be a better idea to use another character than a dot for calling functions at the same object multiple times.

For example, if I use :. Then I should write

myMethod 1, 2, 3
  :anotherMethod 2, 3
  :yetAnotherMethod 4, 5

instead of

myMethod 1, 2, 3
  .anotherMethod 2, 3
myMethod 1, 2, 3
  .yetAnotherMethod 4, 5

EDIT: Add code examples

@xixixao
Copy link
Contributor

xixixao commented Mar 15, 2014

This is a duplicate of still open #1495, with a lot of argumentation for and against (I'd move it there so we don't repeat ourselves). I am with @jashkenas on this one, at least until the current change has been proven and tested. I think it crosses the boundary to LS land with <| etc. magic.

@eskhool
Copy link

eskhool commented Oct 23, 2015

+1 whitespace is very significant in coffee and the inline option should be available to those who like it. not making it work seems to overstretch the I-don't-like-it-argument

@GeoffreyBooth
Copy link
Collaborator

If someone wants to submit a PR for this, it would be considered. However there are many open issues with chaining/leading periods, so those would need to be fixed first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants