Open hiiamboris opened 2 years ago
Quoting my own experience from an attempt to improve the debug output facilities:
...the meaning of
form
is most likely to produce single-line messages. It is quite disappointing then to see it freeze for a minute and then throw an out of memory error, or output hundreds of megabytes of text in it's zealous attempt to form the complex tree, as if anyone would ever need that. Even more dissatisfying is that I cannot meaningfully override it, as unlikemold
,form
is often called internally, namely by string actions (insert
,append
,change
), byrejoin
(which isappend
-based), byrejoin
(though that's costly), rewrite of actions is not possible at Red level.
Another use case I'm thinking here about is clipboard. What happens when user copies into clipboard:
And how should this operation be named?
Obviously it should produce pure text output so one could paste it somewhere. Without any internals (so it's clearly not mold
). It doesn't involve files, so it's not save
. Not ellipsized or in any other way shortened (which goes against main form
usage). Formatting intent is not known - result may be read by humans, or it may be imported into other software (so preferably the result should include raw unformatted numbers and full dates, preferring interchangeability over readability).
So candidates are:
format
(with interchangeability intent) is closest, but it usually gets a format spec, while here we want to format a chosen default specform
is further, since its usual intent is short messagesto-string
intent I don't have enough info, besides while to-string
may work locally to string!
just can't, it's too important to override in any context
I was rewriting
mold
functionality to better suit Spaces, and I was again caught by the fact that it's behavior is not defined.For instance, console uses
mold
to display it's output, but it truncates it so if output is bigger than 1-2 lines, I usually just ignore it and resort to??
orprobe
which are again based onmold
. So first thing I see is a design problem in console itself - instead of showing me a part of output I can expand with a click, it truncates it to a point where it's non-informative. Also funny that console usesform
to output floats, andmold
for any other value - another indication of the lack of design effort here.??
is used both in console and to log some values into a file for later inspection (kind of a daily thing for me). I clearly don't want to output excessive info, because I won't be able to find my way around it. E.g. if I dump a Draw block, seeing each rich-text dumped as a fullface!
object is ridiculous (I only want to see the actual text in this case). And it's just one example. Naturally I try to rewritemold
so it shortens all values output below the top nesting level.OTOH,
save
also usesmold
, so if I limitmold
output, I also limitsave
. Do I want that?save
is meant to beload
ed, not just inspected visually. But what's the point of it without /all refinement, if we can't guarantee subsequent load success? JSON-like data trees - small subset of Red, is that all where it's applicable? In any case if I limitsave
, I also limit the possibility to dump JSON-like data, unless I add another mode to mold (/all-like loadable mold, mold for simple data trees, and mold for coder's overview during debugging).Should I use
form
instead ofmold
when debugging? E.g. redirect??
to it? What isform
even meant for?Looks completely useless for debugging... The only use case I know if is creating small messages to
print
directly or as anerror!
text (where?function?
is a lesser evil indeed than it's full body dump). Often asform reduce
as a lazy way to delimit the message with spaces, which often fails (e.g. if you have a comma you don't want a space before it), then one has to resort torejoin
, which main use case is different - creating templated file names and such. Even then they're both inferior in readability to string interpolation.And there's
to string!
, which is totally unclear to me where it should be used, save for simple integer or word to string conversions. And thenformat
, which IMO has the most clearly defined use compared to other funcs.So it's all quite a mess grown waywardly from the ground up, without clear top-level design that should start with use cases. At least I couldn't find anything more informative in R2 docs than this.
To introduce some order into formatting functions, I propose using this REP for discussion. What are use cases for every formatting function (both how they were used historically and how do you see them applying to this use case in the future)?
We've had some discussion during format work, but it was inconclusive. Feel free to dig up any useful discussion links on the topic.
I'll start with an overview of how I see it:
?
=help
??
mold
, but for named values?
does. Great for debug logs, or for deeper inspection in console (but suffers hard from a danger of unlimited output)source
??
is shortermold
on-[deep-]change*
, which can only be seen withmold/all
(not sure it's worth hiding, but rationale is that we know 100% that these are not for object user's tinkering)mold/all
save/all
work? I use it mainly to see the real value of afloat!
save
save/all
save/all
form
#rejoin
to string!
rejoin
#rejoin
append
which usesform
internally#rejoin
(string interpolation)format
format
complex data structures (trees, objects, blocks, etc)I also think
?
/??
could eventually be replaced to by a console-integrated GUI tool like Red Inspector, but we'll still need these for environments without a GUI.