To prettyprint (or pretty-print) is to present an object to a human reader, so that it is easier to perceive the object's structure, or, less commonly, to simply make it more attractive. A prettyprinter is a computer program that prettyprints. Prettyprinters for programming language source code are sometimes called code beautifiers or syntax highlighters.
Many text formatting programs can also typeset mathematics: TeX was developed specifically for high-quality mathematical typesetting.
Code formatting and beautification
Programmers often use tools to format their source code in a particular manner. Proper code formatting makes it easier to read and understand. Moreover, often different programmers have different preferred styles of formatting, such as the use of code indentation and whitespace or positioning of braces. A code formatter converts source code from one format style to another. This is relatively straightforward because of the unambiguous syntax of programming languages. Code beautification involves parsing the source code into component structures, such as assignment statements, if blocks, loops, etc. (see also control flow), and formatting them in a manner specified by the user in a configuration file.
An early example of pretty-printing was Bill Gosper's "GRIND" program, which used combinatorial search with pruning to format LISP programs. The term "grind" was used in some Lisp circles as a synonym for pretty-printing.
Project style rules
Many open source projects have established rules for code layout. The most typical are the GNU style and the BSD style The biggest difference between the two is the location of the braces: in the GNU style, opening and closing braces are on lines by themselves, with the same indent. BSD style places an opening brace at the end of the preceding line, and the closing braces can be followed by 'else. The size of indent and location of white space also differs.
Example of formatting and beautifying code
The following example shows some typical C structures and how various indentation style rules format them. Without any formatting at all, it looks like this:
The GNU indent program produces the following output when asked to indent according to the GNU rules:
It produces this output when formatting according to BSD rules:
Error messages from various software tools can be very lengthy and obscure.
Special tools and techniques are usually used to beautify the output, highlighting the cause of error and/or hiding not important stuff.