Discussion What's your indentation style?

Bingdom

Googledom
Hello!

In case you're not familiar with the range of indentation styles, the Wikipedia is a great source.

My indentation style is 1TBS. I prefer it over K&R because I favour consistency - Keeping curly braces for control statements that have only one statement.

E.g.
Code:
if (problem) {
    fixProblem();
} else {
    continue();
}
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Whitesmith Style. I find having the {} on lines to themself a much more visually pleasing and easy to read style than any of the others.

Code:
if (keybaord_check(vk_space))
    {
    if (var1 + var2 + var3 == 10)
        {
        room_goto(room);
        }
    scr_FollowPlayer(player_id);
    }
else if (var1 + var2 + var3 == 20)
    {
    scr_AttackPlayer(player_id)
    }
 

Amon

Member
Code:
if ( var 1 == 80 ) {
var2 = 1;
       }
             else{
format_crap_properly;
        }
Excecute_Dangerous_viRus_For_ZX_Spectrum;
Commodore_64_Is_King}{]{;
 
J

Jafman

Guest
Ratliff Banner style!
Code:
if junkfood&&late{
    for(a=8 a<20 a++){
        run(bathroom,2);
        }
    }
 
G

Guest User

Guest
Code:
    if(problem) {
    
        fix_problem();
        and_hide_error(); }

    else { continue; }
i (typically) switch to K&R when writing code that will be read by others, however..
 

Simon Gust

Member
Code:
// made up indentation style
// rules
if (expression_takes_one_line) {
    put_bracket_on_statement_line = true;
}
else
{
    flagA = true;
    flagB = true;
    put_bracket_on_statement_line = false;
}

// exception 1: twin statements
if (move < 0) hspd -= 0.2;
else
if (move > 0) hspd += 0.2;

// exception 2: twin for-loops
for (var i = 0; i < wdt; ++i) {
for (var j = 0; j < hgt; ++j) {
    // statement
}}

// bracketless indent
var inst = instance_create(x, y, object);
    inst.health = 100;
    inst.speed = 3.5;
 

Mert

Member
Not the best, no indent, no nothing; but I like it ;)
Code:
case iap_ev_purchase:
        var product = iap_data[? "index"];
        var map = ds_map_create();
        iap_purchase_details(product, map);
        
        switch (map[? "status"])
        {
            case iap_failed:
                if (global.analytics==true && global.purchase_pathfinder==true && string(map[? "payload"])=="iwillalwaysloveyou")
                {
                ga_addDesignEvent("Monetization:IAP:Failed:"+string(map[? "product"]));
                global.purchase_pathfinder=false;
                }
                if (script_exists(global.purchase_fail_script)){script_execute(global.purchase_fail_script,string(map[? "product"]))};
                break;
                
            case iap_purchased:
                if (global.analytics==true && global.purchase_pathfinder==true && string(map[? "payload"])=="iwillalwaysloveyou")
                {
                var currency,price,type;
                currency = purchase_get_currency();
                price = global.pmap[? string(product)+"_price"];
                type = string_copy(argument[i],1,2);
                
                if (type=="du")
                {
                ga_addBusinessEvent(currency, price, "Durable IAP", string(map[? "product"]), "Menu", "", "");
                ga_addDesignEvent("Monetization:IAP:Purchased:"+string(map[? "product"]));
                }
                else
                {
                ga_addBusinessEvent(currency, price, "Consumable IAP", string(map[? "product"]), "Menu", "", "");
                ga_addDesignEvent("Monetization:IAP:Purchased:"+string(map[? "product"]));
                }
                show_debug_message("Purchase Happened. Currency : "+string(currency)+" - Price : "+string(price)+" Type : "+string(type));
                global.purchase_pathfinder=false;
                }
                ds_map_set(global.pmap,string(map[? "product"]),true);
                ds_map_secure_save(global.pmap,"pdata.json");
                
                if (script_exists(global.purchase_success_script)){script_execute(global.purchase_success_script,string(map[? "product"]))};
                break;
            case iap_canceled:
                if (global.analytics==true && global.purchase_pathfinder==true && string(map[? "payload"])=="iwillalwaysloveyou")
                {
                ga_addDesignEvent("Monetization:IAP:Cancelled:"+string(map[? "product"]));
                global.purchase_pathfinder=false;
                }
                if (script_exists(global.purchase_cancel_script)){script_execute(global.purchase_cancel_script,string(map[? "product"]))};
                break;
        }
        ds_map_destroy(map);
        break;
}
 
Code:
if (keybaord_check(vk_space))
{
    if (var1 + var2 + var3 == 10)
    {
        room_goto(room);
    }
    scr_FollowPlayer(player_id);
}else
if (var1 + var2 + var3 == 20)
{
    scr_AttackPlayer(player_id)
}
Its worked for me like this for decades. Having new people join projects (non GameMaker projects) seems like this is the most legible to them.
 
Allman, all the time.

Code:
if ( not_using_allman )
{
    its_harder_to_find_matching_braces;
    its_clear_which_braces_belong_to_which_parent_statement;
}
else
{
    this = much_clearer;
    while ( Allman )
    {
        readability_for_me = pleasurable;
    }
}

switch (example)
{
    case 0:
        i_love_indentation = true;
    break;

    case 1:
        Allman = true
    break;
}
 

Mick

Member
Allman with a hint of K&R. I prefer indentations to be two spaces wide, i can do with the "normal" four spaces but with more indentation levels, the total indentation width often becomes too wide imo.

First time I actually saw Whitesmiths, was in the GMS manual and wondered why YoYo had chosen that "unusual" style. :)
 

Mercerenies

Member
1TBS myself, but with the exception that function braces go on the same line as well as control statement braces. Also, 2-space indents because I spend most of my time in languages that nest a lot of statements and functions inside each other (Ruby, Scala, etc), so that coding style naturally leaks out into brace-based languages like like C++ for me.

Code:
if (problem) {
  fixProblem();
} else {
  createProblem();
}
 
Code:
// made up indentation style
// rules
if (expression_takes_one_line) {
    put_bracket_on_statement_line = true;
}
else
{
    flagA = true;
    flagB = true;
    put_bracket_on_statement_line = false;
}

// exception 1: twin statements
if (move < 0) hspd -= 0.2;
else
if (move > 0) hspd += 0.2;

// exception 2: twin for-loops
for (var i = 0; i < wdt; ++i) {
for (var j = 0; j < hgt; ++j) {
    // statement
}}

// bracketless indent
var inst = instance_create(x, y, object);
    inst.health = 100;
    inst.speed = 3.5;
I actually do almost this exact same thing. The only thing different is I don't do the bracketless indent thing at the end. Also I always put my "else if" on the same line, not separate lines.
 
T

TitanAnteus

Guest
Whitesmith Style. I find having the {} on lines to themself a much more visually pleasing and easy to read style than any of the others.

Code:
if (keybaord_check(vk_space))
    {
    if (var1 + var2 + var3 == 10)
        {
        room_goto(room);
        }
    scr_FollowPlayer(player_id);
    }
else if (var1 + var2 + var3 == 20)
    {
    scr_AttackPlayer(player_id)
    }
This guy gets it.
 

JackTurbo

Member
I guess I'm just 1TBS?

Code:
if(whatEver == true){
    codeyCode = "indented like this";
}else{
    codeyCode = "still indented like this";
}


if(codeGetsDeep == true){
    if(codeGetsEvenDeeper == true){
        if(codeGetsDeeperStill == true){
            codeyCode = "still indented like this";      
        }
    }
}
 
Z

zendraw

Guest
it depends on the case, but somthing like this
Code:
if (asdf)
{
        if (ghjk)
        {
                  dasdasd
        }
        if (qwer) {fasdasdas};
        else {dasfsdfwe};
} else
{
        dasdasfd
}
 
Top