red / REP

Red Enhancement Process
BSD 3-Clause "New" or "Revised" License
11 stars 4 forks source link

mold/form/rejoin/what-have-you: top-level overview #134

Open hiiamboris opened 2 years ago

hiiamboris commented 2 years ago

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 ?? or probe which are again based on mold. 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 uses form to output floats, and mold 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 full face! object is ridiculous (I only want to see the actual text in this case). And it's just one example. Naturally I try to rewrite mold so it shortens all values output below the top nesting level.

OTOH, save also uses mold, so if I limit mold output, I also limit save. Do I want that? save is meant to be loaded, 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 limit save, 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 of mold when debugging? E.g. redirect ?? to it? What is form even meant for?

>> form does [1 + 1]
== "?function?"

Looks completely useless for debugging... The only use case I know if is creating small messages to print directly or as an error! text (where ?function? is a lesser evil indeed than it's full body dump). Often as form 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 to rejoin, 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 then format, 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:

N Function Uses Target reader Comment
1 ?=help Function help, bird's-eye view of Redbol data during debugging Coders Great for objects, maps, not useful for blocks currently. Great for console, not so for debug log files
2 ?? Like mold, but for named values Coders It could support unnamed values in parens, like ? does. Great for debug logs, or for deeper inspection in console (but suffers hard from a danger of unlimited output)
3 source ? Coders I never used it, since ?? is shorter
4 mold Visual inspection of Redbol data during debugging Coders Currently hides on-[deep-]change*, which can only be seen with mold/all (not sure it's worth hiding, but rationale is that we know 100% that these are not for object user's tinkering)
5 mold/all ? ? Was just a kludge to make save/all work? I use it mainly to see the real value of a float!
6 save ? see save/all Without a loadability guarantee, is there any point in it?
7 save/all Save/load complex Redbol data, config files Redbol scripts, coders (during debugging) Obsoleted by Redbin or still relevant?
8 form A lazy poor man's short message composition (when it works) see #rejoin
9 to string! Low-level number formatting, anything else? ?
10 rejoin Low-level short message composition see #rejoin Today uses append which uses form internally
11 #rejoin (string interpolation) A readable way to produce short messages Coders (runtime errors), admins (log messages), end-user and translator (UI strings)
12 format Full control over representation of numbers, date/time, logic strings, units of measure (incl. L10N) End-user (often one reading it on paper), or standard-compliant parsers Doesn't seem meaningful to me to 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.

hiiamboris commented 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 unlike mold, form is often called internally, namely by string actions (insert, append, change), by rejoin (which is append-based), by print. Even if I could rewrite print, maybe even rejoin (though that's costly), rewrite of actions is not possible at Red level.

hiiamboris commented 1 year ago

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: