-
-
Notifications
You must be signed in to change notification settings - Fork 554
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
Conversation
There was a problem hiding this 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.
af37010
to
32cfed5
Compare
@@ -52,10 +52,10 @@ | |||
"size": 4 | |||
}, | |||
"expected": [ | |||
[ 1, 2, 3, 4], | |||
[1, 2, 3, 4], |
There was a problem hiding this comment.
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.
"basket": [ | ||
1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5 | ||
] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. 🤷
"dominoes": [ | ||
[1, 2], | ||
[2, 3], | ||
[3, 1], | ||
[2, 4], | ||
[2, 4] | ||
] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
"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] | ||
] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
There was a problem hiding this 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.
"basket": [ | ||
1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5 | ||
] |
There was a problem hiding this comment.
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.
(vlq = variable-length-quantity)
2de3797
to
a62dc2d
Compare
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
Requesting a review from @exercism/reviewers |
There was a problem hiding this 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.
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.
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.
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.
suggested as a follow-up action to format-array being merged, in at least two separate occasions: exercism#1968 (comment) exercism#1966 (comment)
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.
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.
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.
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.