Clarify documentation for Format.out_indent#1382
Conversation
|
Actually (as I guess you have seen) in all default cases, Regarding code breaking, we scanned opam packages for this PR and identified the ones which could break (for example I sent a patch for The first case was discussed in the PR (or one of the related ones). Regarding the second, I think it was not. Do you have a lot of examples of 2. in your codebase that change All in all it is indeed true that the changes are not retro-compatible. The only problem that I see with this change is that, going forward, if you change That's why I think we should mention the side-effect you propose in the documentation of the module, if we go forward with the patch. We should even say that you should change Other than that I would be ok with the patch for the sake of retro-compatibility, especially if some codebases (not in opam) have a lot of |
|
If the patch is not accepted, I suggest we add to the documentation the pitfalls you mention. |
|
Thanks for the comments @rbonichon! I only had to adapt one instance of "2.", but I found the non-backwards compatible behaviour surprising, specially because the documentation currently reads:
which I initially interpreted to mean the code in this PR (meaning that updating out_spaces also changes out_indent)! |
|
@rbonichon thanks for your enlightening analysis. I found this bit in particular interesting:
I am not very familiar with the use-cases for these functions. Could someone explain what are the typical use-cases for overriding out_spaces and out_indent? Is it actually the case that most changes to "spaces" should naturally also affect the notion of identation (which seems to be @nojb's assumption)? |
|
@gasche Just to give an example of a possible use: to define a kind of As for the expectation that most changes to "spaces" should also affect "indentation", that has been the case until now (where "indentation" was not a separate concept from "spaces") and I was just arguing purely from the point of view of backwards compatibility. |
|
@gasche Prior to #615 , Overriding Actually, @pierreweis and I did exactly that (display formatting marks) when we were preparing examples for our paper on Format last year. That's actually when it struck us that there was no clean way of graphically differentiating indentation and spacing, which ultimately lead to the introduction of |
|
I'll let the community decide if backwards compatibility is more important than a cleaner (from my point-of-view) separation between |
|
Since #615 was not in 4.05, "the community" should decide before the 4.06.0 release. |
|
FWIW, I would vote for a cleaner separation.
|
|
Let's assume we don't include the current PR in the release -- that's my reading of the fairly-weak consensus around. Could someone propose a documentation PR about the issue fairly soon? (Ideally we would like to release before the end of the month.) |
334da0e to
15d084f
Compare
|
I agree that the "consensus" seems to be to leave things as they are, which is fine by me. I just pushed a tiny one-line change to the documentation that would have cleared things up for me when reading it. |
stdlib/format.mli
Outdated
| - field [out_newline] is equivalent to [out_string "\n" 0 1]; | ||
| - field [out_spaces] is equivalent to [out_string (String.make n ' ') 0 n]; | ||
| - field [out_indent] is the same as field [out_spaces]. | ||
| - fields [out_spaces] and [out_indent] are equivalent to [out_string (String.make n ' ') 0 n]; |
There was a problem hiding this comment.
can you reformat to fit in 80 columns?
15d084f to
d622af3
Compare
|
Merged, cherry-picked in 4.06: 9f4e707 @Octachron, if it's easy for you to update your manual beta, that could be an occasion. |
|
@nojb Thanks for the added documentation. I'll try to add a line to the Changelog reporting what you need to do in case you want a behavior compatible with the previous release. |
Follows from discussion of PR ocaml#1382.
Follows from discussion of PR #1382.
|
One of the packages that breaks because of the new record field is notty : see pqwy/notty#17. I'm linking the issue here for reference. It seems from the discussion that notty's author, @pqwy, would have welcome @nojb's initial transitional proposal. |
Notty's author strongly agrees.
I'm also surprised at this gratuitous breakage, since it's so easy to mitigate. |
|
It's a debate between retro-compatibility vs. having to deal with just as surprising behaviors in the future -- indeed if you start OCaml at 4.06, why would you expect that changing Also we identifed only 2 packages (now 3) at the time of the PR, so code breaking objectively seems to be pretty rare. Due to lack of strong consensus, we went with more documentation in the Changelog. |
This is a (tiny) follow-up to #615.
In that PR a new field
out_indentwas introduced in theformatter_out_functionsrecord type inFormat, used for indentation. This function used to be identical with theout_spacesfield. This breaks code in two cases:{... with ...}because the new field may end up with an incorrect value.The second case is more problematic because it is a "silent" bug.
I propose a fix for this second case by making the default
out_indentreferenceout_spaces, so that any update toout_spaceswill also affectout_indent.(surprised that this was not done in the original PR, I wonder if I am missing something obvious...)
@rbonichon @pierreweis