[NIT] Pretty pretting #ifFalse:ifTrue:

Doug Way dway at riskmetrics.com
Wed Nov 21 01:48:25 UTC 2001


"Andrew C. Greenberg" wrote:
> 
> I never found use for a pretty printer, except perhaps to facilitate the
> reading of large hunks of awfully written code.  To that end, any
> decent-looking semantically equivalent code sufficed.  Since even the
> worst of Smalltalk code is usually much smaller and more comprehensible,
> the pretty-printing tool seems particularly pointless in Squeak even as
> a general editor.

Well, perhaps the indenting aspect of a pretty-printer isn't quite as necessary in Smalltalk as with other languages, since you usually have shorter methods without too much nesting of loops & conditionals.

But the theory of pretty-printing still seems valid to me... the idea that you'll be able to more quickly read and understand code if it's always uniformly well-formatted (and colored).  (In practice there's probably not a big improvement in understandability, since most Squeakers contributing to the base image write reasonably well-formatted code.)

On the other hand, some might argue that they can impart extra meaning to code they've written by hand-formatting it in a certain way, which should be preserved for all to see.  But that seems bogus to me... it certainly wouldn't outweight the benefits of reading uniformly formatted code.  I'd be curious to see a counterexample claim, though. :)

(The only exception to this, IMHO, is that it might be nice to preserve whitespace.  Sometimes, by using whitespace I like to say that these first three lines of code belong together as a group, and these last four are in a separate group, for example.)

> Thus, I am curious why some are so interested in this functionality.
> Have I been missing out on the party all these years?  Perhaps there
> could be some utility to such a tool, say, to impose coding standards on
> a development team, or to ease code typing to free coders from some
> extra keypresses.  Is that what folks use pretty-printing for?

Yeah, those are some good uses.

One reason I don't use pretty printing right now is that it reformats an entire method if you make a small change.  Well, it's not a huge problem, and not a problem at all if everyone's using pretty-printing. ;-)  But it would be cool if you could modify code with pretty-printing turned on, such that only code statements which you altered are saved with pretty-printing.

Another thing that was brought up, was that it might be nice to have support for non-pretty-printing (non-formatting) color highlighting in Squeak.  I know there have been some external goodies written, but it'd be nice to have in the base image.  We wouldn't even need to add a new preference... the colorWhenPrettyPrinting preference could be renamed to something like colorSyntaxHighlighting so that, when turned on, it used pretty-printed (parse-tree based) color highlighting when browseWithPrettyPrint was turned on, and non-formatting color highlighting when browseWithPrettyPrint was turned off.

- Doug Way
  dway at riskmetrics.com




More information about the Squeak-dev mailing list