[11.x] more consistent and readable chaining#53748
Merged
taylorotwell merged 1 commit intoDec 6, 2024
Merged
Conversation
my goal with this commit is to make multiline chaining more consistent and readable. obviously there can be a subjective component to things like this, so I'll do my best to layout why I think these changes are objectively good. I have limited this first proof-of-concept commit to chaining on new `Collection`s, as they are a good simple example. what did I change: - convert closures to arrow functions for very simple expressions - always begin the start of a chained method (`->`) on a new line - use a single indent from the first line on new lines why I think this is better: - readability is better by not having multiple methods on a single line. no more hunting for the closing parentheses - each line serves a single grokable purpose. the first line instantiates the new `Collection` with some data. each following line runs an operation on that `Collection` - significantly improved GIT diffs. changes you see in the diff are more likely to be isolated to the purpose of the change - the single indent still gives us good alignment, without the pitfalls of trying to line it up with some arbitrary character or pattern in the starting line. it's very easy to apply consistently across many scenarios.
shaedrich
reviewed
Dec 3, 2024
shaedrich
left a comment
Contributor
There was a problem hiding this comment.
Some simplifications with first-class callable or traditional callable array syntax
Contributor
Author
you're welcome to try these changes in a separate PR, but I'm keeping things as simple as possible right now. |
shaedrich
reviewed
Dec 3, 2024
shaedrich
left a comment
Contributor
There was a problem hiding this comment.
You could utilize higher-order messages
browner12
added a commit
to browner12/framework
that referenced
this pull request
Dec 10, 2024
my goal with this commit is to make multiline chaining more consistent and readable. obviously there can be a subjective component to things like this, so I'll do my best to layout why I think these changes are objectively good. I have limited this first proof-of-concept commit to chaining on new `Collection`s, as they are a good simple example. what did I change: - convert closures to arrow functions for very simple expressions - always begin the start of a chained method (`->`) on a new line - use a single indent from the first line on new lines why I think this is better: - readability is better by not having multiple methods on a single line. no more hunting for the closing parentheses - each line serves a single grokable purpose. the first line instantiates the new `Collection` with some data. each following line runs an operation on that `Collection` - significantly improved GIT diffs. changes you see in the diff are more likely to be isolated to the purpose of the change - the single indent still gives us good alignment, without the pitfalls of trying to line it up with some arbitrary character or pattern in the starting line. it's very easy to apply consistently across many scenarios.
browner12
added a commit
to browner12/docs
that referenced
this pull request
Feb 14, 2025
use a single indent for chains on a new line, rather than trying to align it with some arbitrary pattern in the first line. this arbitrary alignment very easily gets out of sync as changes occur to the code, and often times the adjustments are not made to the chained alignment. the single indent alignment does not suffer this problem. this is to bring us in line with laravel/framework#53835 and laravel/framework#53748 this commit only contains whitespace changes. if accepted, I will make these adjustments to the remaining docs pages.
taylorotwell
pushed a commit
to laravel/docs
that referenced
this pull request
Feb 14, 2025
use a single indent for chains on a new line, rather than trying to align it with some arbitrary pattern in the first line. this arbitrary alignment very easily gets out of sync as changes occur to the code, and often times the adjustments are not made to the chained alignment. the single indent alignment does not suffer this problem. this is to bring us in line with laravel/framework#53835 and laravel/framework#53748 this commit only contains whitespace changes. if accepted, I will make these adjustments to the remaining docs pages.
browner12
added a commit
to browner12/framework
that referenced
this pull request
Mar 11, 2025
this continues on some of my earlier formatting changes. you can read laravel#53748 for my arguments why single indent is better.
taylorotwell
pushed a commit
that referenced
this pull request
Mar 12, 2025
this continues on some of my earlier formatting changes. you can read #53748 for my arguments why single indent is better.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
my goal with this commit is to make multiline chaining more consistent and readable. obviously there can be a subjective component to things like this, so I'll do my best to layout why I think these changes are objectively good.
I have limited this first proof-of-concept commit to chaining on new
Collections, as they are a good simple example.what did I change:
->) on a new linewhy I think this is better:
Collectionwith some data. each following line runs an operation on thatCollectionif this PR is accepted I will look into more places to apply this consistently, and into automation we can use for these rules as we move forward.