Skip to content

Coding Conventions

Janaka Ranasinghesagara edited this page Dec 8, 2025 · 1 revision

When contributing to the Mie Simulator GUI please follow the coding conventions detailed below. Some of the initial development did not adhere to these guidelines but going forward, this will be the code style and structure.

Naming Conventions

Definitions:

  • Camel Case: Naming convention where the first letter of each word is capitalized with the exception of the first letter. Example: thisIsCamelCased
  • Pascal Case: Naming convention where the first letter of each word is capitalized including the first letter. Example: ThisIsPascalCased
  • Underscore Uppercase Delimited: Naming convention that places underscores between the words and the first letter of each word is capitalized. Example: This_Is_Underscore_Delimited
  • Underscore Lowercase Delimited: Naming convention that places underscores between the words and the first letter of each word is not capitalized. Example: this_is_underscore_lowercase_delimited

These are the only naming conventions that should be used in the Mie Simulator GUI and apply to different aspects of the code defined below.

  • Classes, general Functions (non-UI/Test), and properties, should be Pascal cased. Example: MyClass
  • Member Variables (Private/Protected), m Prefix + Pascal CASE. Example: mVariable
  • UI Methods (Slots, triggered by UI) should be Underscore Lowercase Delimited. Example: on_object_name_action
  • Test methods should be underscore delimited. Example: test_methods

Indenting

Code should be indented with 4 space characters, if a tab character is used, make sure your source-code editor replaces tabs with 4 spaces.

Braces

An opening brace { should appear on the line after the start of a statement block and the code inside the brace should be indented 4 spaces. The closing brace } should be inline with the opening brace on it's own line.

Braces may may be avoided when there is only a single line of code.

Spacing

Spacing improves the readability of the source-code, follow these guidlines for spacing:

  • Use a space after the comma between arguments in a function
  • Use a space after statements like if, while, and __for
  • Use a space before and after operators with the exception of ++ and --

Example:

#include <math.h>

class Complex
{
public:
    Complex(double re, double im)
        : _re(re), _im(im)
    {}
    double modulus() const
    {
        return sqrt(_re * _re + _im * _im);
    }
private:
    double _re;
    double _im;
};

void bar(int i)
{
    static int counter = 0;
    counter += i;
}

namespace Foo
{
namespace Bar
{
void foo(int a, int b)
{
    for (int i = 0; i < a; i++)
    {
        if (i < b)
            bar(i);
        else
        {
            bar(i);
            bar(b);
        }
    }
}
} // namespace Bar
} // namespace Foo

Getting Started with the Application and Source Code

Mie Simulator GUI

Contributing

Discussions

Clone this wiki locally