Start page / Template development / Scripting / Code style

Code style

“Codestyle” denotes the style of the programming. To make scripts legible for other developers and above all to make them maintainable, a good style, i.e. a good code style, should be maintained in scripting. Several minor rules help to keep an overview in a script.

Blocks

If certain areas of a script, for example the summary of the declaration of global variables or the import of classes, are grouped together in specific places, these could be called a block. These blocks substantially increase the clarity of a script.

//!Beanshell

// Imports
import java.myclass;
..
.

// Global variables
foo = "bar";
bar = 0;
..
.

// Methods
myMethod() {
print("this is my method!");
}

// Script start
..
.

Indentation

Indented script code increases legibility. To ensure uniform indentation for developers with different editors, ideally tabs only should be used for indentation and not spaces.

Documentation

As in every other programming language, documentation of the source code is an enormous help in the event of subsequent extension or debugging of a script. Therefore, the function of smaller or particularly complicated sections of a script should be well documented.

//!Beanshell

// Single row comment

/* Multi-row
comment */

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.5 | Data privacy