This is kind of a weird, old legacy function that we export. Should we deprecate it? Use an IO context flag? Just unexport it?
Triage decided the code can remain in Grisu, but it shouldn't be exported anymore
Triage: We should un-export this from base, but keep it available in Grisu if people want to use it directly. Using Grisu directly is sometimes a reasonable thing to do if you want really custom float printing, e.g. the plotting packages use it to print data points with consistent precision.
print_shortest is also used in writedlm(), line 733 of DelimitedFiles in stdlib.
As part of the stdlib it's fairly kosher for that to depend on an internal Base function since they will be updated in sync.
This could become a :shortest
flag in IOContext. Grisu already looks at the :compact
flag.
We could also just get rid of this since the only reason DelimitedFiles
calls it is because I put it there and I think various people would prefer that it use more standard short-but-not-necessarily-the-tricksiest-and-very-shortest printing.
I've been strongly reluctant to have IOContext be used to pass specific formatting choices recursively. I think if you care about that level of detail in your output, you should [have to] define the recursive structure also.
Not sure why mbauman removed needs-tests – this function does not appear to have any. If it's not simply deleted, it needs them written instead.
This issue doesn't add any features so this is not the place to put the "needs tests" label. If you want to open a separate issue about testing print_shortest
that would be fine, but that seems premature since we may decide to delete it.
Now that we have printstyled
, we could fold shortest
into a keyword argument to that function.
Frankly, I'm just not sure this is all that necessary of a function. But sure, that's an option.
I think the magic of print_shortest in writedlm() is not necessary. It lose the type differentation for floats with '*.0' because print_shortest write them as '0', so afterwards you dont know wether this element was originaly an Int or an Float.
Most helpful comment
We could also just get rid of this since the only reason
DelimitedFiles
calls it is because I put it there and I think various people would prefer that it use more standard short-but-not-necessarily-the-tricksiest-and-very-shortest printing.