Use consistentCodeThe main reason for the beautification tool (pretty print program) isProgramThe structure and encoding style are standardized, so that the code is easy to read and understand.
A good coding convention can be usedSource codeClear, easy to read, accurate, more intuitive and consistent with other language conventions. A well-indented code can greatly improve the speed of code reading, thus reducing the cost of software maintenance.
Introduction to several open-source code beautification tools:
Tool Name |
Applicable Language |
Introduction |
Installation and Use |
Indent |
C |
Indent has almost become synonymous with code beautification tools. |
Indent is a tool attached to GCC, Indent [Options] [input-files] Indent [Options] [Single-Input-file] [-O output-file] |
Perltidy |
Perl
|
Perltidy is also written in Perl. A previous usage introduction. |
Run the perltidy script after the download. Perltidy [Options] file1 file2 file3... (Output goes to file1.tdy, file2.tdy, file3.tdy ,...) Perltidy [Options] file1-O OUTFILE Perltidy [Options] file1-ST> OUTFILE Perltidy [Options] <infile> OUTFILE |
Astyle |
C ++ Java (PHP) |
A very fast C/C ++/Java source code beautification tool. Astyle has many complete set of style definitions better than indent: ANSI Java Linux... you don't have to remember the complex indentation specific options. |
Download the source code, decompress the package, make, and generate the astyle executable file. Astyle [Options] <original> beautified Astyle [Options] Foo. cpp bar. cpp [...] Astyle -- style = ANSI *. cpp I tried to use it to format the PHP program, which is also very effective (of course, it is not a pure PHP code mixed with HTML code ). |
Pydent |
Python |
Pythius contains two tools: one is indent sorting. Pydent: Code indent Tool Pystat: Code statistics Tool |
After the source code is downloaded and unwrapped: Run "Python setup. py build" Run "Python setup. py install" |
Htmltidy |
Html/XML |
The error correction tool for HTML code can help your HTML code better comply with W3C specifications. htmltidy will try to ignore HTML code if the page contains asp php jsp and other programs. Htmltidy also supports formatting of XML Usage options:-XML |
After the source code is downloaded, make generates the tidy Executable File: tidy: file1 file2... Note: Use the-raw option for pages with Chinese charactersTidy.exe-raw-imuq-wrap 132-F % F. Err % F option description: -Raw: do not modify Chinese characters (output values above 127 without conversion to entities) -I indend: by default, HTML is Indented by two spaces. -M overwrites the original file -U forces all HTML tags to be capitalized (this can be left blank) -Wrap Page code with a width greater than 132 lines force line feed -F % F. Err: output the error to the "corresponding file name. Err" file. |
Batch code modification:
Win32:
For/R % F in (*. Java) Do astyle -- style = JAVA -- brackets = Break-closing-headers % F
For/R % F in (*. jsp) Do tidy-raw-imuq-wrap 132-F % F. Err % F
Linux:
Find./-name *. Java-exec astyle -- style = JAVA -- brackets = Break-closing-headers {}/;
Htmltidy error warning: some errors that cannot be parsed are actually caused by code irregularities.
- "<" In Javascript"
For example
For (I = 1; I <m; I ++)
Change
For (I = 1; I <m; I ++)
^ "<" Must be enclosed by spaces to prevent <m from being marked as HTML.
- The HTML attribute contains the JSP Tag:
Tidy output for common JSP attributes can be recognized.
For example: <input type = text size = "9" name = "alias" maxlength = 20 value = <% = infoform. getalias () %>
But code like this:
<% = infoform. getphoto () %> width = 120>
Because the start of the attribute is not <%, the IMG does not end with an error.
Htmltidy also supports XML format beautification:
Tidy-XML-imq web. xml
Tidy-XML-imq build. xml
Programmers should be good at communication. The significance of code beautification is to reflect developers' respect for others, so that programmers can better communicate with each other. Statistics show that a well-indented code can greatly improve the speed of code reading by 40%. Another statistics is that more than 70% of software development work is to maintain previous code, therefore, the use of code beautification tools is also a way to reduce software maintenance costs.
The above tools only beautify the code format indent. To comply with the complete code specifications, refer to the following documents:
GNU coding standards
Http://www.gnu.org/prep/standards_toc.html
Code conventions for the Java (TM) Programming Language
Http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
PHP coding standard
Http://utvikler.start.no/code/php_coding_standard.html
Perlstyle
Http://www.perldoc.com/perl5.6/pod/perlstyle.html
Html xml xhtml css...
Http://www.w3c.org/