Formatting
Prev | Chapter 3. Build File Structure and Formatting | Next

## Formatting

Four spaces should be used as the unit of indentation.

Do not use tabs instead, use 4 spaces in place of a single tab. Many editors can do this automatically.

Vertically align start and end tags for an element. Indent child elements.

Avoid lines longer than 80 characters, since they're not handled well by many terminals and tools.

Use a single space after a comma.

Group properties by use, for example, group directory definitions together. Insert a single blank line between groups.

Insert two blank lines between targets.

Insert one blank line between tasks within a target.

When an expression will not fit on a single line, break it according to these general principles:

- Break before an attribute.

- Break after a space or comma.

- Prefer higher-level breaks to lower-level breaks.

- Align the new line with the beginning of the expression at the same level on the previous line.

- If the above rules lead to confusing code or to code that's squished up against the right margin, just indent 8 spaces instead.

Examples:

        <property name="modules"
            value="libs, junit_tests, images, docs, api_docs, external_libs,
                  sources" />

        <copy todir="${unit_test_deploy}" overwrite="true">
            <fileset dir="${unit_test_home}">
                <exclude name="**/CVS" />
            </fileset>
        </copy>

This is wrong:

      <target name="test_all" depends="clean,setupApp,
                                        setupTests,setupLogger,
                        startReportServlet,runTests"/>

This is right:

        <target name="test_all"
            depends="clean, setupApp, setupTests, setupLogger,
                    startReportServlet, runTests"/>

Prev | Up | Next
Chapter 3. Build File Structure and Formatting | Home | Chapter 4. Projects