1. Hey! Guest! The 31st GMC Jam will take place between Nov 16th, 12:00 UTC (Friday noon) and Nov 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Discussion What's your indentation style?

Discussion in 'Off Topic' started by Bingdom, Jun 13, 2018.

  1. Bingdom

    Bingdom Googledom

    Joined:
    Jul 1, 2016
    Posts:
    1,640
    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:
    6,132
    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)
        }
     
    JCJ and Jafman like this.
  3. Amon

    Amon Member

    Joined:
    Sep 13, 2016
    Posts:
    121
    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:
    26
    Ratliff Banner style!
    Code:
    if junkfood&&late{
        for(a=8 a<20 a++){
            run(bathroom,2);
            }
        }
     
  5. Guest User

    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..
     
    Jafman likes this.
  6. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    2,871
    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;
    
     
  7. Mert

    Mert Member

    Joined:
    Jul 20, 2016
    Posts:
    118
    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:
    680
    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,743
    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;
    }
    
     
    Joe, Cloaked Games, Gamebot and 4 others like this.
  10. Desix

    Desix Member

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

    Cantavanda 〜Flower Prince〜

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

    Roman P. Member

    Joined:
    Mar 1, 2017
    Posts:
    204
    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,272
    Allman, forever.
     
    Vether likes this.
  14. Cat

    Cat Member

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

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

    Mick Member

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

    Mercerenies Member

    Joined:
    Jun 21, 2016
    Posts:
    97
    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();
    }
     
  17. Cloaked Games

    Cloaked Games Member

    Joined:
    Jul 4, 2016
    Posts:
    736
    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.
     
    Simon Gust likes this.
  18. TitanAnteus

    TitanAnteus Member

    Joined:
    Jun 23, 2018
    Posts:
    14
    This guy gets it.
     
    Nocturne likes this.
  19. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    723
    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";      
            }
        }
    }
    
    
    
     
  20. Gamer-15

    Gamer-15 Member

    Joined:
    Nov 11, 2016
    Posts:
    57
    This is my style:

    Code:
    if (problem)
    {
     fixProblem();
    }
    else
    {
     continue();
    }
     
  21. zendraw

    zendraw Member

    Joined:
    Jun 20, 2016
    Posts:
    1,297
    it depends on the case, but somthing like this
    Code:
    if (asdf)
    {
            if (ghjk)
            {
                      dasdasd
            }
            if (qwer) {fasdasdas};
            else {dasfsdfwe};
    } else
    {
            dasdasfd
    }
     
  22. amusudan

    amusudan Lousiest of Potatoes

    Joined:
    Jun 20, 2016
    Posts:
    183
    Code:
    if      ( something )
                                then
                {
            something
    }                                                     else
           {
                                               something
                                                                                        }
    
     
    JackTurbo likes this.
  23. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    2,871
    jesus christ
     
    amusudan likes this.

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