ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
Prettyprint - Wikipedia, the free encyclopedia

Prettyprint

From Wikipedia, the free encyclopedia

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.

Contents

[edit] Pretty-printing mathematics

Pretty-printing usually refers to displaying mathematical expressions in a way that is similar to the way they are typeset professionally. For example, in computer algebra systems such as such as Maxima or Mathematica the system may write output like "x ^ 2 + 3 * x" as "x2 + 3x". Some graphing calculators can perform pretty-printing such as the HP-49 series and TI-89, or the TI-83 Plus/TI-84 Plus with the PrettyPt add-on.

Many text formatting programs can also typeset mathematics: TeX was developed specifically for high-quality mathematical typesetting.

[edit] 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.

There exist both standalone code beautifiers and built in ones in integrated development environments and text editors. For example, Emacs's various language modes can correctly indent blocks of code attractively.

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.

[edit] 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.

[edit] 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:

int foo(int k) { if (k < 0 || k > 2) { printf("out of range\n");
printf("this function requires a value of 1 or 2\n"); } else {
printf("Switching\n"); switch (k) { case 1: printf("1\n"); break; case
2: printf("2\n"); break; } } }

The GNU indent program produces the following output when asked to indent according to the GNU rules:

int
foo (int k)
{
  if (k < 0 || k > 2)
    {
      printf ("out of range\n");
      printf ("this function requires a value of 1 or 2\n");
    }
  else
    {
      printf ("Switching\n");
      switch (k)
        {
        case 1:
          printf ("1\n");
          break;
        case 2:
          printf ("2\n");
          break;
        }
    }
}

It produces this output when formatting according to BSD rules:

int
foo(int k)
{
        if (k < 0 || k > 2) {
                printf("out of range\n");
                printf("this function requires a value of 1 or 2\n");
        } else {
                printf("Switching\n");
                switch (k) {
                case 1:
                        printf("1\n");
                        break;
                case 2:
                        printf("2\n");
                        break;
                }
        }
}

[edit] Text formatting

Text formatting can be considered a generalized form of pretty-printing.

[edit] See also

  • indent
  • enscript, a general text printing tool with prettyprinting functions

[edit] External links

[edit] Historical implementations

[edit] Code Beautifiers

[edit] Coding style guides

Languages


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -