interpolation proposals and safety
Steven Schveighoffer
schveiguy at gmail.com
Fri Aug 30 18:30:33 UTC 2024
On Friday, 30 August 2024 at 15:21:49 UTC, Adam D Ruppe wrote:
> On Friday, 30 August 2024 at 14:36:56 UTC, Steven Schveighoffer
> wrote:
>> Yes, I purposely said log, because that's the intention of
>> `writeln`.
>
> Gonna disagree with this: writeln's intention is to write a
> line to the stdout stream. It has no more semantic knowledge;
> it is fundamentally a low level function with a wide variety of
> high level uses.
`writeln` has a *default mechanism* for writing out data. What
does this default mechanism do? It dumps the contents of a
struct. This screams "logging".
If `writeln` only supported strings, or required opt-in to string
conversion (i.e. erroring without explicit `toString` function),
then it would be clearer. But I can't see any purpose for this
default other than logging data when it's useful.
But technically, this job belongs to `format`, so `writeln`
indeed is a mechanism to output formatted data to a stream. It's
just that the combination of formatting data with the default
format being "contents of object" is best suited to logging.
If one is worried about accidentally writing badly-formatted or
accidentally revealing data, one shouldn't use `writeln`.
This reminds me of javascript when you get a field on the screen
and the text is `[Object object]`
-Steve
More information about the Digitalmars-d
mailing list