What is a Beautifier, how does it format code and what are its limitations?
The reversal of a minification
A Beautifier is a program that maximises a source code compressed by a minifier to improve its readability. The Beautifier reformats the source code without changing the functionality of the source code. It is therefore a code beautification. The process is also called Beautifying, Maxification or Unminifying.
Example of Beautifying
After minifying, the code looks like this:
And this is the result after using a Beautifier:
The structure is easier to follow than after minifying, the functionality is unchanged, but not all information could be produced as in the original. Comments are still missing and also – but not here in the example – shortened variable names (during minifying, depending on the tool used, variable names are also shortened to a single letter) cannot be restored to the original state. A Beautifier is therefore not a form of Un-Do, but takes the existing source code and improves its readability.
Formatting with Beautifier
How does a Beautifier improve the readability and consequently the maintainability of the code? It
- uses indentations,
- adds blocks to modifying statements like if, else, for, while etc,
- sets spaces before and after the arguments of modifying statements and for operators,
- uses code coloring for syntax highlighting.
A Beautifier does all these things according to a fixed scheme, so that a uniform structure is created. Indirectly, this also means that deliberate violations of formatting rules, which further increase the readability of the code, and which have been removed by minifying, are not restored by Beautifying.