Prettyprint

To prettyprint (or pretty-print) is to make something, commonly some printed material, appear more appealing to the human eye. A prettyprinter, or a program that automatically prettyprints, programming language source code is sometimes called a code beautifier.

Pretty-printing math

Pretty-printing usually refers to displaying mathematical expressions in a way that is similar to the way they are written by hand. For example in computer algebra systems the system may write output like x ^ 2 + 3 * x as x^2+3x. Mathematical pretty-printing is done by interactive numerical calculation programs such as Octave or MATLAB, and by computer algebra programs such as Maxima or Mathematica, as well as by TI-89 graphing calculator. It is usually not done by earlier, less sophisticated graphing calculators like the TI-83 or the TI-83 Plus, unless the calculator has a Pretty Print program such as PrettyPt installed.

Pretty-printing text

A very familiar idea of prettyprinting is the Wiki markup contributors are using to contribute to the Wikipedia; articles are plain text, for example the above paragraph is internally stored as
  Pretty-printing usually refers to displaying mathematical expressions   in a way that is similar to the way they are written by hand. For example   in [[computer algebra system]]s the system may write output   like <tt>x ^ 2 + 3 * x</tt> as <math>x^2+3x</math>. Mathematical   pretty-printing is done by interactive numerical calculation programs   such as [[Octave]] {{Free software}} or [[Matlab]], and by   [[computer algebra]] programs such as [[Maxima]] {{Free software}}   or [[Mathematica]], as well as by [[TI-89]] [[graphing      calculator]]. It is usually not done by earlier, less   sophisticated graphing calculators  like [[TI-83]], unless the . 
However the markup system prettyprints this as you see above. Ironically what a "prettyprinter" produces directly may be decidedly ugly. For instance, the Wiki actually translates to HTML, which may refer to images generated from embedded TeX, which may itself have been created by a math program's "prettyprinter" (see above). None of these files is pretty -- some of it is not even human-readable -- until a web browser (or its equivalent) renders it all.

Code formatting and beautification

Programmers may often want to use automatic 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. An automatic code formatter converts source code from one format style to another. This is relatively straightforward because of the very regular nature of the programming languages. Indeed, programming languages are defined in such a way that any particular snippet may have only one meaning, so that it compilation of the source code becomes unambiguous. Code beautification simply 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. There exist both standalone code beautifiers and built in ones in integrated development environments (IDEs). For example, Microsoft Visual Studio's source code editor does some limited code formatting like indenting blocks of code inside of braces properly.

Example of formatting and beautifying code

  int foo(int k) {    if(k==11) printf("hello\n");     else printf("good bye\n");  } 
  int foo(int k)    {     if( k == 11 )       printf("hello\n");     else        printf("good bye\n");  } 
  int foo(int k){if(k==11)printf("hello\n");else printf("good bye\n");} 
All three examples mean the same thing and parse in exactly the same manner. Example 1 reflects one preference, example 2 another one, and example 3 is another style which some might find less easy to read. A code beautifier will convert any of these into a format preferred by the programmer.

Pretty printers

 

<< PreviousWord BrowserNext >>
campsis
lake, kentucky
lake, louisiana
lake, missouri
thomas randolph
lake, maryland
h. c. artmann
lake, michigan
abc weapons
procedural knowledge
lake, virginia
lake, oklahoma
the mekons
joseph reinach
timiskaming district, ontario
salomon reinach
henry charles lea
theodore reinach
dramamine
riven
ahom alphabet
idiazabal cheese
dough
kishore kumar
balinese alphabet
vergina
batak alphabet
henry more
john little mcclellan
brahmi alphabet
johann georg ritter von zimmermann
edward fowler
t.c. williams high school
list of radio stations in alberta
john tulloch
list of zip codes in california
user name
multiple citizenship
list of u.s. state parks
jan baptist van helmont
fernwood
list of arkansas state parks
michael foster (physiologist)
fernwood, idaho