Uncrustify is an open-source code beautifier, comparable to other popular alternatives such as GNU Indent or Artistic Style. Code beautifiers (a.k.a. pretty-printers) make code easier to read. They automatically update source code to use one consistent style throughout. The user creates a configuration file that contains specifications for the types of code changes to make: tab/space settings, newline options, brace styles, etc. After feeding the configuration file and target source code into the beautifier tool, the tool modifies the source code according to the user’s specified configuration. After I dug further into Uncrustify, however, I discovered the real star of the show—Universal Indent GUI!
By themselves, the various code beautifiers like Uncrustify are cumbersome to use. Much time is spent examining all the various configuration options (which number in the hundreds) and manually editing terse configuration files—a tedious affair. Thankfully, graphical front-ends exist for these tools, and Universal Indent GUI is best-in-class.
Here are four great features of Universal Indent GUI:
1. Universal Indent GUI contains all the various code beautifier applications.
2. An elegant help system
3. Live Indent Preview
4. Universal Indent GUI outputs configuration files and batch files
Universal Indent GUI: Summary
Universal Indent GUI has several other convenient configuration options which are simple and do not get in your way. The application is available for both Windows and Linux. There is no special installation required—simply unzip and execute. I was very impressed with this tool, and highly recommend it to anyone who considers programming style an important characteristic of well-crafted software. Tip: use the Uncrustify config.txt file in order to browse what Uncrustify options are available within Universal Indent GUI.UEFI BIOS Coding Standards
Intel has created a coding standards guide for EDK II. Below are the parts of the coding standards that could possibly be enforced by a code beautifier application, along with the Uncrustify options I selected in Universal Indent GUI in order to make the UDK 2014 source code Intel-coding-standards-compliant: (correct, the Intel UDK is not compliant with the Intel coding standards…)- Limit line length to 80 characters
- 2 spaces of indentation
- Never use tab characters.
- Set editor to insert spaces rather than a tab character.
- if, for, while, etc. always use { }, even when there is only one statement
- The opening brace ({) should always appear at the end of the line previous line.
- The opening brace ({) for a function should always appear separately on a new line.
Using Universal Indent GUI, I created the following batch and configuration files for Uncrustify to operate on the UDK source:
https://github.com/WilliamLeara/BasicInputOutput/tree/master/Uncrustify
Running it on the UDK 2014 code base (file UDK2014.MyWorkSpace.zip) took about one minute on my 3GHz 8-core Windows 8 system. Sample:
The job made many changes, mostly around enforcing the 80 column limit which the UDK source does not adhere to. I also noticed that trailing spaces were removed from lines. I think it would be a lot of fun to play with all the various Uncrustify options and use the tool to automate work.
Do you use a code beautifier application in your organization? Are they helpful, or a hindrance? Leave a comment! What are your experiences with these tools: positive or negative? Which one of the many code beautifier applications have you tried? Leave a comment!
I have used Universal Indent off and on for several years and have found it very useful.
ReplyDeleteBig fan of consistency in coding style, it really helps when reviewing and debugging code.
ReplyDeleteAlthough the wiki (which is supposed to be a summary of the PDF): http://tianocore.sourceforge.net/wiki/Code_Style/C says:
“limit line length to 80 characters”
The PDF file actually says:
“Do not produce lines that exceed 120 columns in your source files. Preferably, limit line lengths
to 80 columns or less. When this doesn’t leave sufficient space for a good postfix style comment,
extend the line to a total of 120 columns. Having some level of uniformity in th expected width of
the source is useful for viewing and printing the code. ”
I interpret that to mean the limit is actually 120 columns, not 80. Like the difference between a black and white “Speed Limit” sign and the black and yellow “Advisory Speed” signs you see on curves. The Advisory speed signs give a recommended speed, but it is not a “limit”.
In my opinion, any standard that limits itself to 80 columns is saying that it is stuck in the days of 80X25 text mode.
Regardless, code beautifiers are a good way to make sure your code conforms to your organizations coding style.