[comp.lang.misc] Comments on pretty-printing

sommar@enea.UUCP (Erland Sommarskog) (03/08/87)

A while ago I posted a request for information on programmable
pretty-printers (PPP). In another article I have made a summary 
of the replies I received. Since there were some discussion on the 
concept as such, I'd like to add some comments of my own.

Bob Pendleton wrote an article a little while ago where he gave 
a simple recipe for writing a pretty-printer. Not programmable, but
easy-to-modify. Of course if I only wanted to read other people's code, 
that would be sufficient. But if my standard deviates from the the 
one of the project, I must be able to re-format back to this standard 
after having added my corrections. So I would have to write at least 
two.

On the other hand, a real PPP is not an easy thing to use. There are
MANY parameters you have to set. Of course, one way could be to
let the user provide a grammar for the language with formatting info. 
But that would also a mean that a very few people would use it. I think it
is important to find an interface that makes a PPP so easy to use as possible. 
I haven't been thinking very intensely on it, but I have a vague idea 
of something menu-driven to set up the parameters. The parameters 
are stored on a (binary) file that the PPP reads at start-up. 

Mark Brader points on the fact that are situations when you may have pieces
of code that are syntactically equal, but the semantics makes you format them
in different ways. Yes, this is a problem, but I think one would have
to live with it. My actual interest in a PPP is not for my own code, but for
others that I should read and maybe modify. My own code I format by hand.

How far can a PPP go? Could I even make it convert procedure descriptions
to my favourite format? Some perhaps, but not much. The comments that
make up procedure descriptions can vary a lot in layout. Some people fills
a almost a page with every parameter and how its called. In my latest 
project I developed a quite compact layout which for instance only described
the parameters when their meaning were not trivial. The point of doing this
was that it increased the probability that the procedure would stay in 
one page on the listing.

Some formatting styles may waste information which you can't regain. I take
variable names as an example. Let's say I have a variable that I name 
SomeValue. Next one to read the code doesn't like the case shift so his 
PPP-profile changes it to some_value, SOME_VALUE or Some_value. That's OK. 
"SomeValue" can still be recreated. But if next guy despises underscores? 
(They are not standard Pascal) AND case shifts? His PPP-profile changes it 
to the quite unreadable "somevalue" which now only can be restored to 
"SomeValue" by a human being.

Erland Sommarskog
ENEA Data, Stockholm, Sweden
sommar@enea.UUCP