<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="en-CZ" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">Unfortunately, “Prettyprinting” can be reduced to indentation and new lines only for XML and JSON, however YAML offers much more dynamic formatting.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">I think when we kick XML out of the equations (and workaround comments), we can simplify the printing API to following:<o:p></o:p></span></p>
<p class="MsoNormal" style="background:white"><span style="font-family:"Courier New";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:white"><span style="font-family:"Courier New";color:black">   
</span><span style="font-family:"Courier New";color:#336BDD">enum</span><span style="font-family:"Courier New";color:black">
<b><i>Style</i></b> { </span><i><span style="font-family:"Courier New";color:#CE54B8">BLOCK</span></i><span style="font-family:"Courier New";color:black">,
</span><i><span style="font-family:"Courier New";color:#CE54B8">FLOW</span></i><span style="font-family:"Courier New";color:black"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="background:white"><span style="font-family:"Courier New";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:white"><span style="font-family:"Courier New";color:black">   
</span><span style="font-family:"Courier New";color:#336BDD">public</span><span style="font-family:"Courier New";color:black">
</span><span style="font-family:"Courier New";color:#336BDD">sealed</span><span style="font-family:"Courier New";color:black">
</span><span style="font-family:"Courier New";color:#336BDD">interface</span><span style="font-family:"Courier New";color:black">
<b><i>Printable</i></b> {}<o:p></o:p></span></p>
<p class="MsoNormal" style="background:white"><span style="font-family:"Courier New";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:white"><span style="font-family:"Courier New";color:black">   
</span><span style="font-family:"Courier New";color:#336BDD">public</span><span style="font-family:"Courier New";color:black">
</span><span style="font-family:"Courier New";color:#336BDD">record</span><span style="font-family:"Courier New";color:black">
<b><i>PrintableValue</i></b>(ConstantDesc </span><span style="font-family:"Courier New";color:#CE54B8">value</span><span style="font-family:"Courier New";color:black">)
</span><span style="font-family:"Courier New";color:#336BDD">implements</span><span style="font-family:"Courier New";color:black">
<i>Printable</i> {}<o:p></o:p></span></p>
<p class="MsoNormal" style="background:white"><span style="font-family:"Courier New";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:white"><span style="font-family:"Courier New";color:black">   
</span><span style="font-family:"Courier New";color:#336BDD">public</span><span style="font-family:"Courier New";color:black">
</span><span style="font-family:"Courier New";color:#336BDD">record</span><span style="font-family:"Courier New";color:black">
<b><i>PrintableList</i></b>(<i>Style</i> </span><span style="font-family:"Courier New";color:#CE54B8">style</span><span style="font-family:"Courier New";color:black">, List<?
</span><span style="font-family:"Courier New";color:#336BDD">extends</span><span style="font-family:"Courier New";color:black">
<i>Printable</i>> </span><span style="font-family:"Courier New";color:#CE54B8">list</span><span style="font-family:"Courier New";color:black">)
</span><span style="font-family:"Courier New";color:#336BDD">implements</span><span style="font-family:"Courier New";color:black">
<i>Printable</i> {}<o:p></o:p></span></p>
<p class="MsoNormal" style="background:white"><span style="font-family:"Courier New";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:white"><span style="font-family:"Courier New";color:black">   
</span><span style="font-family:"Courier New";color:#336BDD">public</span><span style="font-family:"Courier New";color:black">
</span><span style="font-family:"Courier New";color:#336BDD">record</span><span style="font-family:"Courier New";color:black">
<b><i>PrintableMap</i></b>(<i>Style</i> </span><span style="font-family:"Courier New";color:#CE54B8">style</span><span style="font-family:"Courier New";color:black">, Map<ConstantDesc,
<i>Printable</i>> </span><span style="font-family:"Courier New";color:#CE54B8">map</span><span style="font-family:"Courier New";color:black">)
</span><span style="font-family:"Courier New";color:#336BDD">implements</span><span style="font-family:"Courier New";color:black">
<i>Printable</i> {}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">And get following results:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"><a href="https://gist.github.com/asotona/01a054ecca5d8f9608516cb738c33ce1">https://gist.github.com/asotona/01a054ecca5d8f9608516cb738c33ce1</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">and<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"><a href="https://gist.github.com/asotona/1e9b1c233c606724ad1c4e0eff1df3de">https://gist.github.com/asotona/1e9b1c233c606724ad1c4e0eff1df3de</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt">On 27.07.2022 10:10, "Michael van Acken" <michael.van.acken@gmail.com> wrote:<o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt">Am Di., 26. Juli 2022 um 21:43 Uhr schrieb Brian Goetz <</span><a href="mailto:brian.goetz@oracle.com"><span style="font-size:11.0pt">brian.goetz@oracle.com</span></a><span style="font-size:11.0pt">>:<o:p></o:p></span></p>
</div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt"><br>
<br>
<o:p></o:p></span></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><span lang="EN-US" style="font-size:11.0pt">To be more specific about the actual classes:
</span><span style="font-size:11.0pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:36.0pt">
<span lang="EN-US" style="font-size:11.0pt">Mapping accepts only fragments, because it must render as single line and for example in XML it renders as single element with attributes.</span><span style="font-size:11.0pt"><o:p></o:p></span></p>
</div>
</blockquote>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt"><br>
OK, so this unearths a previously unstated requirement: that we be able to turn certain maps into attributes, rather than embedded elements, when converting to XML.  Does this requirement correspond to anything in other formats?  Do we gain anything by dropping
 this, and formatting always to elements, and/or using other heuristics to determine when we can get away with this format optimization? 
<br>
<br>
In general, I'd like to unearth more of this sort of requirements.  Looking at the current hierarchy, I can't help but feel we've not yet "hit bottom"; it doesn't feel factored into separate concerns yet.  But I'm optimistic we can get there. 
<br>
<br>
Here's a naive decomposition, which looks a lot like the JSON spec if you squint:
<br>
<br>
    Value = SimpleValue(ConstantDesc) | ListValue(List<Value>) | MapValue(Map<String, Value>)<br>
<br>
Converting to this form is useful separate from formatting -- it provides a basis for query/traversal using simple string keys.  But it's not good enough for getting good formatting yet, because you need formatting hints to determine how to lay out / indent,
 right?  So let's consider how we might add these in as hints, that are more transparent. [...]<o:p></o:p></span></p>
</div>
</blockquote>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt">If it's a question of prettyprinting where indentation and line breaks<br>
are added automatically, then there is the option to layer all<br>
whitespace manipulation on top of the printed data.  I use this to<br>
prettyprint Clojure data structures, which closely resemble your<br>
`Value` production above.<br>
<br>
The key idea goes back to the 1980 paper "Prettyprinting" by Oppen and<br>
boils down to a single decision how to insert line breaks.  Given a<br>
delimited group<br>
<br>
  <start><elem><line><elem><line>...<elem><end><br>
<br>
where <start> and <end> are usually literals, <elem> arbitrary data,<br>
and <line> is eventually a single whitespace or a line break.<br>
Determine the width of the group assuming that all <line> (both in the<br>
group itself and as part of elements) are of width one.  If the<br>
group's width fits within the page width remaining, then print each<br>
<line> as a single whitespace, otherwise the group's <line> separators<br>
as line breaks.<br>
<br>
The "one line width" flows naturally from the leaves to the root.<br>
Combine this with indentation tracking, and the result is a simple but<br>
capable prettyprinter targeting a given page width as a soft target.<br>
Building on this, I print colorized side-by-side diffs of lists of classfiles.<br>
<br>
-- mva<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
</div>
</div>
</div>
</div>
</body>
</html>