[Post] C Java PHP Perl Python program code beautification tool use

Source: Internet
Author: User
Tags beautifier coding standards tidy checkstyle

Guidance:

Programmers should be good at communication. The significance of code beautification is to reflect developers' respect for others. Good coding conventions can make the source code clear, easy to read, and accurate, it is more intuitive and consistent with other language conventions, so that programmers can better communicate with each other.

Statistics show that code with good indentation can improve code reading efficiency by more than 40%. Another statistics shows that more than 70% of software development efforts maintain previous code, therefore, beautifying the format of previous code is often the first step in refactoring. The use of the code beautification tool (pretty print program) can make the basic code indentation standard a system that is easier to execute.

In addition, if you are the creator of the department code specification, you should also understand that programmers are not machines. It is almost impossible to write code without making code indentation errors. Tools-based batch formatting and sorting tools facilitate the configuration import/export mechanism to develop a unified indentation specification is a truly operable system.

  Introduction to several open-source code beautification tools

Tool Name applicable language introduction installation/Use

Cindent is synonymous with code beautification tools. indent is a standard tool attached to GCC,

Indent [Options] [input-files]

Indent [Options] [Single-Input-file] [-O output-file]

Perlperltidy is also written in Perl. After downloading: Perl makefile. pl; Make; make install

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] OUTFILE

C ++ Java (PHP) is 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] 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 ).

A powerful Java code formatting tool in addition to the standard interface, the command line tool can also be used as a plug-in for ant JBuilder eclipse jdeveloper and other tools, and provides APIs to download from http://prdownloads.sourceforge.net/jalopy/

See the relevant installation documents.

Pythonpythius contains two tools:

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"

The error correction tool for HTML/xmlhtml code can help your HTML code better comply with W3C specifications. It is now called tidy because it is not only used in HTML, it also applies to the formatting of xhtml xml.

However, JSP is not suitable for the code beautification of embedded scripts such as asp php jsp.

  

After the source code is downloaded, make generates the tidy executable file:

Tidy file1 file2...

Note: Use the-raw option for pages with Chinese characters

Tidy.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.

Htmltidy supports XML format beautification:

Tidy-XML-imq web. xml

Tidy-XML-imq build. xml

Other tools:

  PHP code beautification Tool

Phpcb: PHP code beautifier has the command line version and graphic interface code viewer.

Http://www.phpedit.net/products/phpCodeBeautifier/

  Java code beautification tools

For Java code formatting, jacbe is also a good choice. By default, it contains a configuration file that is fully formatted according to Sun's code specifications. There are even Commercial Code Organization tools such as jindent to achieve better results.

Importscrbber: the sorting tool declared by Java import. It can convert a reference such as import java. util. * into a single reference and help delete a reference that is no longer needed. Http://importscrubber.sourceforge.net/

To introduce these tools, you can find: jacbe jindent jxbeautifier...

Http://directory.google.com/Top/Computers/Programming/Languages/Java/Development_Tools/Code_Beautifiers/

  Use the command line tool to modify code in batches

In Windows 2000, use the for command to implement directory traversal, file filtering, and command execution. For example:

For/R % F in (*. Java) Do astyle -- style = Java % F

For/R % F in (*. htm *) Do tidy-raw-imq-wrap 132-F % F. Err % F

For/R % F in (*. asp) Do vbsbeaut.exe-I-S4 % F

Linux: Execute traversal with find-exec, for example:

Find./-name *. Java-exec astyle -- style = ANSI {}/;

Therefore, do not be confused by the beautiful graphic interfaces of many commercial software. When faced with thousands of source files, batchcompute Based on command lines is also a very important feature.

  ForEclipseIDE development environment tools and plug-ins

More and more IDE development environments contain code beautification functions, but some are still not as powerful as these specialized tools. If some developers use eclipse, some are loyal users of JBuilder, how can they easily comply with code specifications? The answer is to use all jalopy plug-ins for these mainstream IDE development environments.

Jalopy: Java code beautification tools: http://jalopy.sourceforge.net/

Eclipse plug-in: http://jalopy.sourceforge.net/plugin-eclipse.html

Checkstyle: Java code specification (indentation, naming) Check Tool http://checkstyle.sourceforge.net

Eclipse plug-in: Eclipse checkstyle plug-in

Installation:

It is very convenient to install the plug-in as Eclipse. After downloading the plug-in, unpack it to the eclipse/plug-in/directory and restart Eclipse:

Configuration:

Jalopy: Windows ==> import/export the jalopy preference configuration in the general menu,

Checkstyle: Windows ==> perference ==> import/export of checkstyle configuration is on the right of the Configuration Interface

The import/export function of standard configuration can greatly reduce the learning time of developers for the above tools. For most developers, it is not necessary to have a detailed understanding of all the option configurations, you only need to know how to import the standard configuration. My common jalopy configuration files

Usage:

Jalopy: in addition to the original format option, the format with jalopy option is displayed in the right-click menu on the code editing interface, the source => orgenize Imports Provided By eclipse can achieve the same effect as imports srubber.

Checkstyle is a very complex code style check process: including indentation, naming conventions, etc. Therefore, the default value is disable. To start the checkstyle for a project, you need: project Properties ==> checkstyle ==> enable.

All of the above tools include ant extensions, which can be easily added to the ant script for Automatic Code Sorting/statistics.

References:

GNU coding standards

Http://www.gnu.org/prep/standards_toc.html

Code conventions for the Java (TM) programming languagehttp: // java.sun.com/docs/codeconv/html/codeconvtoc.doc.html

PHP coding standard

Http://alltasks.net/code/php_coding_standard.html

Pb: PERL/JavaScript beautifier

Http://www.arachnoid.com/lutusp/ftp/cgi/pb.txt

Html xml xhtml css...

Http://www.w3c.org

C-C + + beautifier how-:

Http://www.tldp.org/HOWTO/C-C++Beautifier-HOWTO/

Vbsbeaut code sorting Tool

Http://www.daansystems.com/vbsbeaut/

Dependency analysis between Java components

Http://www.clarkware.com/software/JDepend.html

  Appendix: Why is htmltidy unsuitable for reformatting HTML embedded scripting languages such as jsp php asp?

Some unresolvable errors are actually caused by code irregularities.

In JavaScript"
For (I = 1; I
Change

For (I = 1; I
^"
HTML attributes contain JSP tags: tidy output from common JSP attributes can be recognized.

For example:

But code like this:

Width = 120 type = "codeph" text = "/codeph">

Because the attribute does not start
Htmltidy completely complements the code by default. In fact, many HTML code is contained in the file. Htmltidy also has some problems in Chinese encoding recognition (currently only big5 is supported)

Cause:

Why is it difficult to maintain embedded code? After all, the non-standard HTML syntax checker is much more complicated than a language parser. For example, for such code:

  

  

In this form of code, beautification tools must understand both HTML and PHP syntax. Therefore, most of the formatting tools are for one language or for formatting the program part of the embedded script, or, only HTML-based formatting is supported. There are only a few large development tools such as virsual age and forte that contain JSP code beautification, and a large commercial text editor such as slickedit.

Solution: For the formatting of HTML parts of jsp asp and other files containing programs, it is best to use a specialized HTML editing tool Dreamweaver (≥4) and FrontPage (≥2000). For example, for FrontPage, select "Use the following rules to reformat the source code" from the menu tool ==> webpage options ==> HTML source code menu ".

In short, the embedded scripting language that uses HTML and programs together is a very bad habit of development. In the long run, using XML, XSLT, and other technologies to separate data, presentation, and logic is a more suitable mode for large-scale development.

For the current large number of asp php jsp applications, I still found some tools on Google and believe in homesite. In fact, the vbsbeautifier mentioned above actually calls perl5.8 on Windows.

A code beautification tool for ASP: vbsbeaut

Http://www.daansystems.com/vbsbeaut/

A Java-based HTML editor embedded with C ++ Java, JavaScript, Perl, and other C language code beautifiers: http://www.arachnoid.com/arachnophilia/index.htmlBeautifier highlights and indents source code using highlight configuration files (which are similar to ultraedit highlighting files ). as such, it supports C, C #, Java, Perl, PHP, Pascal, lisp, mumps, Eiffel, euphoria, and x86 explorer, amongst others.

Http://www.beautifier.org/

Trita is a source code beautifier which learns your personal formatting style by examining examples of your code.

Http://www.trita.com/

Supported: Java, javscript, CSS, JSP, HTML, ASP, lisp, Delphi, C #, C ++, PHP, Perl, Python, and SQL.

This article is transferred from

Http://www.chedong.com/tech/indent_tools.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.