One of my favorite newsletters is Jack Ganssle’s The Embedded Muse.  In a recent issue, Jack discussed helpful tools for embedded systems development, and the tool Uncrustify came up.  I decided to run the tool on the UDK 2014 source, and this post discusses the results.

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.

NonameNo need to download and install Uncrustify, GNU Indent, or any of the others.  Just select your desired code beautifier application and Universal Indent GUI will update its interface to display those options pertinent to the selected beautifier.  There are twenty-four different code beautifier applications supported by Universal Indent GUI!

2.  An elegant help system

NonameThe popular code beautifier applications offer literally hundreds of options.  Having to read through PDFs or on-line HTML pages in order to absorb all the many configuration settings is extremely tedious.  The genius of Universal Indent GUI is that a user can hover over an option and trigger a yellow popup containing an explanation of each particular configuration option.  The user can change those options important to him and ignore the rest.  Simple and intuitive!

3.  Live Indent Preview

NonameEven with the nice help system, nothing beats actually viewing the source code with the various options applied so you can make sure you are getting exactly what you think you’re getting.  Universal Indent GUI allows you to open a source code file, turn on the Live Indent Preview feature, and see your source code respond to configuration changes in real time.

4.  Universal Indent GUI outputs configuration files and batch files

NonameOnce you’ve selected the options important to you and configured them, a couple clicks will allow you to either a) save a configuration file ready for your code beautifier application; and/or b) create a batch file/shell script that will automatically apply your new configuration file to a source code directory tree.  These files can then be shared among all the various members of your development team to ensure consistent style.  Moreover, a source code repository pre-commit hook could be established to enforce a standard programming style.

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:

Running it on the UDK 2014 code base (file 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!

Post a Comment

  1. I have used Universal Indent off and on for several years and have found it very useful.

  2. Big fan of consistency in coding style, it really helps when reviewing and debugging code.
    Although the wiki (which is supposed to be a summary of the PDF): 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.


Be sure to select an account profile (e.g. Google, OpenID, etc.) before typing your comment!