Site Logo


Sparen's Danmakufu ph3 Tutorials - Coding Style Guidelines

Welcome to the style guidelines page! In this page, I will highlight the style guidelines that I (Sparen) use or plan to use in all tutorials on this website. These style guidelines are not official but it is recommended you follow them.

This is based off of Checkstyle (the Coding Style Standards for Java), and as such, I will organize this page in such a way as to show what is and is not acceptable.

//Not Acceptable
//Acceptable

White Space

Trailing White Space at the end of a line is not allowed.

Exactly one space is required before a single line comment following a statement.

let x;//declare x
let x; //declare x

The unit of indentation is four spaces.

It is also acceptable to use tabs, as long as you ONLY use tabs and do not use spaces for indentation at all.

This is because tab sizes are not standardized. Always maintain a standard indent size for your own code.

Blocks must be indented.

sub a{
function();
}
sub a{
    function();
}

Exactly one space is required after a comma.

let x = [1,2,3];
ObjSprite2D_SetSourceRect(objEnemy,64,1,127,64);
let x = [1, 2, 3];
ObjSprite2D_SetSourceRect(objEnemy, 64, 1, 127, 64);

Exactly one space is required after an include.

#include"file.dnh"
#include "file.dnh"

Operators must be surrounded by one space

Affects + - % = += -= *= /= %= == != > < >= <= && || ~

The negation operator ! is excluded from this guideline.

The multiplication and division operators * and / are excluded from this guideline but it is still recommended that spaces be added except in cases when it hampers legibility. However, if spaces are used, spaces must be used on both sides.

let x=5+4;
let y=x>10;
x+=3/5;
if(x>=20&&!y){
    let z = (x!=3)||y;
}
let str="danmaku"~"fu";
let x = 5 + 4;
let y = x > 10;
x += 3 / 5;
if(x >= 20 || !y){
    let z = (x != 3) || y;
}
let str = "danmaku" ~ "fu";
let m = 3 /2;
let n = 3 /2;
let p = 1 + 3/ 2;
let q = 1 + 3 /2;
let m = 3/2;
let n = 3 / 2;
let p = 1 + 3 / 2;
let q = 1 + 3/2;

White space is not allowed between a function call and its parameters.

Functions are not to be confused with control statements such as if, else, ascent, while, etc.

myfunc ();
myfunc();

White space is not required after control statements.

loop(5){}
loop (5){}

We suggest not using white space after control statements.

White space is not required before { in control statements.

Additionally, as stated in Lesson 6, there is no standard in Danmakufu for placing a { on the same line as the control statement or on the next line.

loop(5){}
loop(5) {}
loop(5){
}
loop (5)
{
}

Functions, Tasks, and Subroutines

All functions must be called with () even if they have no parameters

function GetCenterX{
    return 192;
}
GetCenterX;
function GetCenterX(){
    return 192;
}
GetCenterX();

Tasks must not be called with () unless they have parameters

task CreateBullet(){
    let obj = CreateShotA1(0, 0, 0, 0, 0, 0);
}
BulletCommands();
task CreateBullet{
    let obj = CreateShotA1(0, 0, 0, 0, 0, 0);
}
BulletCommands;

There are no case guidelines for function, task, and subroutine names

function abc(){}
function CreateBulletStringA1(){}
task BulletCommands{}
task fire1{}
sub renderObject{}

However, we suggest capitalizing all words.

function GetCenterX(){}
task CreateParticleA1{}
sub RenderHitbox{}

Variables

Final constants must be in ALL CAPS.

let bl_small_magenta = 23;
let BL_SMALL_MAGENTA = 23;

Variables must not begin with a capital letter

let AngleToPlayer = GetAngleToPlayer(objBoss);
let Angletoplayer = GetAngleToPlayer(objBoss);
let angletoplayer = GetAngleToPlayer(objBoss);
let angleToPlayer = GetAngleToPlayer(objBoss);
let angle_to_player = GetAngleToPlayer(objBoss);

For loop local variables should follow the i, j, k standard

ascent(x in 0..5) {
    ascent(y in -2..3) {
        descent(z in BALL_MAGENTA.. BALL_AQUA) {

        }
    }
}
ascent(i in 0..5) {
    ascent(j in -2..3) {
        descent(k in BALL_MAGENTA.. BALL_AQUA) {

        }
    }
}

This is a convention where i, j, k, etc. are used for integers in counting loops. This convention does not need to be followed if known integer values are not being counted.

ascent(obj in 0..length(GetAllEnemyID())) {
    Obj_Delete(obj);
}