Skip to content

allow prettier to format more files #1966

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

Merged
merged 3 commits into from
Mar 4, 2022

Conversation

petertseng
Copy link
Member

@petertseng petertseng commented Feb 17, 2022

It's my opinion that for these 15 files, we should not have a strong
opinion on the formatting, and therefore should just accept what
prettier gives us.

This leaves only 18 files ignored. That leaves much less manual work
needed.

Copy link
Member Author

@petertseng petertseng left a comment

Choose a reason for hiding this comment

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

you will notice that some of these appear to cause internal inconsistency, in that some JSON files an array will go on a single line, while in the same JSON file some other arrays will have each element on their own line. While I regret the inconsistency, I believe it's simpler to let prettier do as much as it can, because whatever tool we write to reformat the remaining files is maintained by us, and the less work it has to do, the less work it is to maintain it.

None of the files formatted in this PR are files where the array elements are representing rows of a 2D grid, so the formatting doesn't affect our ability to understand the input.

If the idea is that test cases are immutable, we don't run into problems where adding an element to an array causes a larger diff than necessary, since we simply cannot add elements to those arrays.

It's my opinion that for these 20 files, we should not have a strong
opinion on the formatting, and therefore should just accept what
prettier gives us.

This leaves only 13 files ignored. That leaves much less manual work
needed.
@@ -52,10 +52,10 @@
"size": 4
},
"expected": [
[ 1, 2, 3, 4],
[1, 2, 3, 4],
Copy link
Member Author

Choose a reason for hiding this comment

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

while I regret that we are losing the padding, I do not think it is important enough to preserve. I do not think losing the padding is going to cause trouble understanding this expected output.

Comment on lines 174 to 176
"basket": [
1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5
]
Copy link
Contributor

Choose a reason for hiding this comment

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

See #1917 why this is not desirable.

Copy link
Member

Choose a reason for hiding this comment

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

Are you referring to:

This makes copy and pasting harder for no reason.

If so, I don't really see why the new format is much harder, nor why copy-pasting is important here.

Copy link
Member Author

Choose a reason for hiding this comment

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

To avoid bikeshedding, let me assure you from the standpoint of someone who intends to write the formatting tool that the difference is going to be small - it would be only a small extra cost to add this one as an exception. There is an exercise where I already intend to change a multi-line array into a single-line one (scale-generator), so adding another one isn't an additional code path; it's just adding another exercise that takes that code path.

Since the difference is small, I don't intend to spend a lot of effort on this decision. I actually am supportive of optimising in favour of track maintainers (restoring the original), in exchange for a small extra maintenance cost. Since ultimately that benefits the students, which is why we're here. No need to make it any harder than necessary to implement an exercise from this JSON file.

However. I do need to gain clarification on which exercises this idea needs to be applied to. I apologise for engaging in what-about-ism, but understanding this concern is key to making sure we are helping track maintainers and our future selves. It seems to me like book-store, bowling, change, and variable-length-quantity would fall under the same category here - that their inputs would all benefit from being on the same line as their []. That would be four exercises. Please confirm whether my understanding is correct.

Copy link
Contributor

@SaschaMann SaschaMann Feb 17, 2022

Choose a reason for hiding this comment

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

If so, I don't really see why the new format is much harder, nor why copy-pasting is important here.

Line breaks make it annoying to copy into a REPL or into the code file (where it most likely looks like foo([...])). It's important because it saves a lot of time when manually implementing an exercise. For tracks that use generators, the formatting is irrelevant, so I don't see why we shouldn't optimise it for human-use whenever possible. I don't see any advantage of the new format for reading or implementing the exercise, only disadvantages.

Copy link
Contributor

Choose a reason for hiding this comment

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

However. I do need to gain clarification on which exercises this idea needs to be applied to. I apologise for engaging in what-about-ism, but understanding this concern is key to making sure we are helping track maintainers and our future selves. It seems to me like book-store, bowling, change, and variable-length-quantity would fall under the same category here - that their inputs would all benefit from being on the same line as their []. That would be four exercises. Please confirm whether my understanding is correct.

Yes, that sounds right. I'm not sure if there are other exercise but those are the main ones where it makes a big difference.

Sometimes the added line breaks add readability (see Pascal's Triangle) but for a list of numbers like in these exercises, I don't see that being the case.

Copy link
Member

Choose a reason for hiding this comment

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

Line breaks make it annoying to copy into a REPL or into the code file
It's important because it saves a lot of time when manually implementing an exercise.

Well, many tracks don't have a REPL nor do I think that "it saves a lot of time" is necessarily true (I feel that is an assumption).
That said, we should indeed optimize for human-readability, so if it is do-able for Peter to make these exceptional cases, then I am fine with it.

Copy link
Contributor

@SaschaMann SaschaMann Feb 17, 2022

Choose a reason for hiding this comment

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

Well, many tracks don't have a REPL nor do I think that "it saves a lot of time" is necessarily true (I feel that is an assumption).

Do those tracks gain anything from spreading it out over several lines? Maybe there are advantages, I just can't think of any.

There are very few programming languages that don't have a REPL at all. Whether or not people use it as part of their workflow is a different story, though.

(I feel that is an assumption).

Try it and measure it yourself if you want, I don't see how it wouldn't be slower to remove line breaks for every paste compared to just pasting them. 🤷

Comment on lines 164 to 170
"dominoes": [
[1, 2],
[2, 3],
[3, 1],
[2, 4],
[2, 4]
]
Copy link
Contributor

Choose a reason for hiding this comment

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

See #1917 why this is not desirable.

Copy link
Member Author

Choose a reason for hiding this comment

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

If I understand correctly, the idea here is that seeing [1, 2], [2, 3], [3, 1] all next to each other makes it more visually apparent that they could connect to each other, and that is lost if putting them on separate lines.

I have thought about it and I am sufficiently convinced.

May I remind from the standpoint of a person intending to write the formatting tool that I expect the extra maintenance cost incurred by this to be small. Given it is small, I think it's worth it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, the idea here is that seeing [1, 2], [2, 3], [3, 1] all next to each other makes it more visually apparent that they could connect to each other, and that is lost if putting them on separate lines.

Indeed.

Comment on lines +85 to +96
"expected": [
[1],
[1, 1],
[1, 2, 1],
[1, 3, 3, 1],
[1, 4, 6, 4, 1],
[1, 5, 10, 10, 5, 1],
[1, 6, 15, 20, 15, 6, 1],
[1, 7, 21, 35, 35, 21, 7, 1],
[1, 8, 28, 56, 70, 56, 28, 8, 1],
[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps these should all be triangles in this file.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will note this for consideration when writing the array formatter. After it is incorporated into CI I will try applying that to pascals-triangle and see how it looks. For the time being, I let prettier do as it will.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good.

Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

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

I approve of all these changes.

Comment on lines 174 to 176
"basket": [
1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5
]
Copy link
Member

Choose a reason for hiding this comment

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

Are you referring to:

This makes copy and pasting harder for no reason.

If so, I don't really see why the new format is much harder, nor why copy-pasting is important here.

@petertseng petertseng dismissed SaschaMann’s stale review February 17, 2022 08:22

I am making a ruling in favour of track maintainers, given that the additional cost to problem-specifications maintenance is going to be small. in applicable exercises, I have applied my decision

@ErikSchierboom
Copy link
Member

Requesting a review from @exercism/reviewers

Copy link
Member

@kotp kotp left a comment

Choose a reason for hiding this comment

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

Nothing looks awry, the formatting seems to be reasonable. The things that are meant to be formatted different appear to be not affected in a harmful way.

@SaschaMann SaschaMann merged commit b820099 into exercism:main Mar 4, 2022
@petertseng petertseng deleted the more-formats branch March 4, 2022 12:36
petertseng added a commit to petertseng/exercism-problem-specifications that referenced this pull request Mar 4, 2022
race condition between
"Exercise allergies test case"
exercism#1969
and
"allow prettier to format more files"
exercism#1966

Since this file is now being formatted by prettier, the test case added
in the latter PR must be formatted according to prettier.

There are alternate approaches, such as directing format-array to always
format `expected` with one item on each line, but it doesn't seem like
this is particular important for the `allergies` exercise.
petertseng added a commit to petertseng/exercism-problem-specifications that referenced this pull request Mar 4, 2022
race condition between
"Exercise allergies test case"
exercism#1969
and
"allow prettier to format more files"
exercism#1966

Since this file is now being formatted by prettier, the test case added
in the latter PR must be formatted according to prettier.

Otherwise, as will be observable from any PR after
exercism#1966, CI fails
on main.

There are alternate approaches, such as directing format-array to always
format `expected` with one item on each line, but it doesn't seem like
this is particular important for the `allergies` exercise.
@petertseng petertseng mentioned this pull request Mar 4, 2022
SaschaMann pushed a commit that referenced this pull request Mar 4, 2022
race condition between
"Exercise allergies test case"
#1969
and
"allow prettier to format more files"
#1966

Since this file is now being formatted by prettier, the test case added
in the latter PR must be formatted according to prettier.

Otherwise, as will be observable from any PR after
#1966, CI fails
on main.

There are alternate approaches, such as directing format-array to always
format `expected` with one item on each line, but it doesn't seem like
this is particular important for the `allergies` exercise.
petertseng added a commit to petertseng/exercism-problem-specifications that referenced this pull request Mar 31, 2022
suggested as a follow-up action to format-array being merged, in at
least two separate occasions:

exercism#1968 (comment)
exercism#1966 (comment)
petertseng added a commit to petertseng/exercism-problem-specifications that referenced this pull request Mar 31, 2022
suggested as a follow-up action to format-array being merged, in at
least two separate occasions:

exercism#1968 (comment)
exercism#1966 (comment)

The reason for the suggestion is that helps visualise the human-readable
form of the triangle that we are used to seeing.
petertseng added a commit to petertseng/exercism-problem-specifications that referenced this pull request Mar 31, 2022
suggested as a follow-up action to format-array being merged, on at
least two separate occasions:

exercism#1968 (comment)
exercism#1966 (comment)

The reason for the suggestion is that helps visualise the human-readable
form of the triangle that we are used to seeing.
ErikSchierboom pushed a commit that referenced this pull request Apr 1, 2022
suggested as a follow-up action to format-array being merged, on at
least two separate occasions:

#1968 (comment)
#1966 (comment)

The reason for the suggestion is that helps visualise the human-readable
form of the triangle that we are used to seeing.
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.

4 participants