Skip to content

Coding Standards

M Alfiyan S edited this page Feb 14, 2023 · 24 revisions

The Mata Elang source code consists of several programming and scripting languages.

In Mata Elang development, there are minimal coding standards to improve and maintain software quality and maintainability.

Cording Styles

Declaration

  • Be sure to declare variables and functions at the beginning of the script.

Good:

int intColumnA;
int intColumnB;
int intColumnC;

intColumnA = 123;
intColumnB = 223;
intColumnC = 323;

Bad:

int intColumnA;
int intColumnB;

intColumnA = 123;
intColumnB = 223;

int intColumnC;

intColumnC = 323;

Naming

  • Naming variables are adjusted globally for easy understanding by others.
  • Use descriptive verbs in function names.

Good:

public static int addNum() { ... }

Bad:

public static int num() { ... }

Line breaking

  • Each statement should get its own line.

Good:

num = 2;
num = num + a;
if (num == 5) {
    print('Number is 5');
}

Bad:

num = 2;
num = num + a;
if (num == 5) {
    print('Number is 5');
}

Comments

  • Comments must be added for understandable reasons in every statement context.

Good:

# Show the number to check the pattern 
num = 2;
num = num + a;
if (num == 5) {
    print('Pattern is 5');
}

Bad:

# Add num to a, print Number of num
num = 2;
num = num + a;
if (num == 5) {
    print('Pattern is 5');
}

Indentation

  • Use 4 or 2 spaces for indenting, not tabs.
  • The other indent sizes are prohibited.

Good:

if (num == 5) {
    print('Number is 5');
}

Bad:

if (num == 5) {
      print('Number is 5');
}
  • A case label should not be indented. The case statement is indented.

Good:

switch (condition) {
case fooCondition:
case barCondition:
    i++;
    break;
default:
    i--;
}

Bad:

switch (condition) {
    case fooCondition:
    case barCondition:
        i++;
        break;
    default:
        i--;
}

>> Back to HOME