beautifier : Java Glossary
home B words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
Go to : punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
CurrCon neededThe CurrCon Java Applet displays prices on this web page converted with today's exchange rates into your local international currency, e.g. Euros, US dollars, Canadian dollars, British Pounds, Indian Rupees… CurrCon requires Java 1.1 or later, preferably 1.6.0_06 . If you can’t see the prices, of you if just want to learn more about CurrCon, click here for help.
beautifier
a program that tidies up Java source code to some standard format. I does not rigidly follow Sun’s conventions, but it is quite close.

Advantages of Beautifiers

  1. Beautified code is consistent and hence easier to read.
  2. You will save tens of thousands of keystrokes you would otherwise spend compulsively aligning and tidying code manually.
  3. Beautifiers are 100% consistent. Even team members who have not an anally retentive bone in their bodies will turn out perfectly formatted code. Even fastidious you can never achieve perfect consistency with purely manual alignment.
  4. Beautifiers stop fights in teams where team members have their own preferred style they don’t want anyone else to meddle with. To be a good computer programmer you must be borderline OCD (Obsessive Compulsive Disorder). This means likely you will develop stylistic formatting quirks that are very important to you, but are meaningless to others. Others can’t follow them even when they want to. Those stylistic details that are so glaring to you, sail right over their heads. Further it just irritates them to be bullied into following “meaningless” rules, as if you were telling them they can’t walk on sidewalk cracks. Team members are irked walking on eggs, trying to mimic every other team member’s style when working on "their" code. Separate idiosyncratic styles for separate classes encourages territorialism.
  5. You settle on a corporate style for checkin, and team members are free to beautfy to their personal style when they edit or view a piece of code. They automatically beautify back to corporate standard for checkin. You can make the standard as elaborate and quirky as you like. It does not interfere with anyone’s work. Because it does not matter, there is far less reason to fight over what it should be. The boss can have it 100% his way, and expect 100% compliance.
  6. Beautifiers get rid of most false deltas on CVS checkin. Since spacing is beautified to a standard, you don’t get CVS deltas registered by a stray space. As part of beautification, I collapse runs of blank lines down to one to avoid that type of false delta.
  7. If you change your mind on what constitutes the optimal format, you can do a bulk beautify on all code you have ever written. That is deeply satisfying to the obsessive perfectionist.
  8. Beautifiers prevent deceptive code, code that is indented to look like it does one thing, but actually does something else.
  9. Beautifiers can be helpful in detecting bugs such as unbalanced or improperly nested {} [] (). You beautify, and look at the beautified indent structure to detect anomalies. If you insist on only manually aligning code, you deprive not only yourself, but all team members of this useful tool.

Disadvantages Of Beautifiers

  1. It is an extra step. If you forget, you will create hundreds of false CVS deltas on checkin.
  2. You can never find a beautifier that will do things exactly the way you would if you did them by hand with infinite time.
  3. Beautifiers often have bugs. This means they may break lines inappropriately, introduce white space or add superfluous and ever growing blank lines.
  4. They are not manly. Real men do everything manually no matter how much time it wastes.
  5. Be careful when reordering declarations to make code pretty. You can often disturb the order of static or instance initialisation and stop it working. I broke BigDate this way allowing Visual Age to sort all my declarations alphabetically. It really had me scratching my head.

The Ideal Beautifier

I have not yet found a beautifier that is sufficiently anally-retentive about spaces that you never get spurious CVS deltas. You should be able to control how much space there should be before and after () [] ; + - = in various contexts, e.g. method call, cast, empty declaration, nested () depth, /* // etc.

Ideally a beautifier should work two ways:

  1. Inside your editor just a click away.
  2. As a standalone utility so you can batch beautify and routinely beautify before adding to CVS. You want spacing absolutely standard, no judgement at all.
  3. You need a beautifier for each type of text you use in your project such as Java, JSP, HTML, CSS, XML, SQL…
Trita is unusual in that is will beautify Java, JSP, HTML, CSS, PHP, JavaScript and even C#. It learns your preferred style by looking as a sample of your formatted code.$35.00 USD

A beautifier does not have to understand the full syntax of Java and it also has to handle code with syntax errors. This makes it somewhat simpler than a full parser. In other words, to get the beautifier exactly the way you want, you may have to write it yourself.

Any modern IDE will beautify code, e.g. Eclipse, Netbeans or IntelliJ Idea. I use Idea, which has two highly configurable beautifier plugins called Rearranger and code Formatter. For tiny projects I use SlickEdit since it is integrated into the editor, where it is convenient to type quickly/sloppily then beautify frequently.


CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.16] The information on this page is for non-military use only.
You are visitor number 15,647. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/beautifier.html J:\mindprod\jgloss\beautifier.html