Discussion What's your indentation style?

Discussion in 'Off Topic' started by Bingdom, Jun 13, 2018 at 5:35 AM.

  1. Bingdom

    Bingdom Googledom

    Joined:
    Jul 1, 2016
    Posts:
    1,616
    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();
    }
     
    Jafman likes this.
  2. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    5,855
    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)
        }
     
    Jafman likes this.
  3. Amon

    Amon Member

    Joined:
    Sep 13, 2016
    Posts:
    55
    Code:
    if ( var 1 == 80 ) {
    var2 = 1;
           }
                 else{
    format_crap_properly;
            }
    Excecute_Dangerous_viRus_For_ZX_Spectrum;
    Commodore_64_Is_King}{]{;
     
    Jafman likes this.
  4. Jafman

    Jafman Member

    Joined:
    Apr 24, 2018
    Posts:
    21
    Ratliff Banner style!
    Code:
    if junkfood&&late{
        for(a=8 a<20 a++){
            run(bathroom,2);
            }
        }
     
  5. hipstercapitalist

    hipstercapitalist Member

    Joined:
    Nov 28, 2016
    Posts:
    385
    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..
     
    Jafman likes this.
  6. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    2,396
    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;
    
     
    RichHopelessComposer likes this.
  7. Mert

    Mert Member

    Joined:
    Jul 20, 2016
    Posts:
    57
    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;
    }    
     
  8. sitebender

    sitebender Member

    Joined:
    Sep 13, 2016
    Posts:
    597
    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.
     
    Gamebot likes this.
  9. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    1,552
    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;
    }
    
     
    Gamebot, slojanko, Jafman and 2 others like this.
  10. Desix

    Desix Member

    Joined:
    Jun 23, 2016
    Posts:
    385
    Code:
    if (objQuestion.Type = "Indent")
    {
        return "Allman";
    }
     
    slojanko likes this.
  11. Cantavanda

    Cantavanda 〜Flower Prince〜

    Joined:
    Jun 23, 2016
    Posts:
    54
    my sexuel indentation is hetero
     
  12. Roman P.

    Roman P. Member

    Joined:
    Mar 1, 2017
    Posts:
    186
    i don't indent or use spaces. just a new line after ; to keep it clean.
     
  13. RichHopelessComposer

    RichHopelessComposer Member

    Joined:
    Jun 20, 2016
    Posts:
    1,149
    Allman, forever.
     
    Vether likes this.
  14. Cat

    Cat Member

    Joined:
    Jun 22, 2016
    Posts:
    59
    I prefer Allman.

    Anyone who uses Lisp can stay far away from me
     
  15. Mick

    Mick Member

    Joined:
    Jun 30, 2016
    Posts:
    626
    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. :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice