Announcement

Collapse
No announcement yet.

Code alignment

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Code alignment

    I'm just wondering how many coders on here like to align their code and what extent they go to.
    For instance the simple case is...
    Code:
    xyz = y;
    z   = a;
    I ask because I've always lined up my assignment but a couple of weeks ago I came across this extension for Visual Studio
    Code alignment

    At first I thought the amount of alignment he did was a bit crazy, but I tried it out and I have to admit, it has grown on me.

  • #2
    Re: Code alignment

    I usually don't bother with alignment my code at all.
    Obviously it doesn't go all over the place and I follow the general syntax rules that are expected.
    sigpic

    WAT WAT WAT WAT WAT WAT WAT WAT WAT WAT WAT WAT WAT WAT


    Comment


    • #3
      Re: Code alignment

      I rarely do true code alignment. I have some personal readability standards that could be placed into that category but mostly it's my OCD. Also, there are some code alignment considerations to make when writing x86 assembly.

      Aside from that, and slightly related, those who don't use tab indentation need to die in the white hot fire of a trillion stars.

      Comment


      • #4
        Re: Code alignment

        Originally posted by OxC0FF33 View Post
        Aside from that, and slightly related, those who don't use tab indentation need to die in the white hot fire of a trillion stars.
        I usually avoid spam posts like this but,
        +11384719374112347192374 googolplexes!
        sigpic

        WAT WAT WAT WAT WAT WAT WAT WAT WAT WAT WAT WAT WAT WAT


        Comment


        • #5
          Re: Code alignment

          Agreeing with your team on which standards to use is half the battle.

          Best is to agree on using a format which is supported by such an automatic code aligners; luckily they become available for more and more languages. If a team member makes a mess of it it's then easily straightened out.

          Comment


          • #6
            Re: Code alignment

            If there are only two or three assignments I wouldn't bother, but if I have a portion of code where lots of variables are assigned I do tab the "=" signs out so that they line up.

            The thing that I'm still not sure on is lining up braces. I always used to do:

            int foo(void)
            {

            }

            Now I more often do

            int bar(void) {

            }

            I think the first way is clearer but simply because most people do it the other way I've started to gravitate towards that now as well.

            Comment


            • #7
              Re: Code alignment

              I earlier did not used to bother about it. More recently i am doing alignment. Make the code more readable

              Comment


              • #8
                Re: Code alignment

                in addition to most standard whitespace rules i like to put even more whitespace than normal, i.e.

                Code:
                int foo( int a, int b )
                {
                        return a + b;
                }
                :)

                Comment


                • #9
                  Re: Code alignment

                  Originally posted by pH4ze View Post
                  I think the first way is clearer but simply because most people do it the other way I've started to gravitate towards that now as well.
                  Depends on the language you use. I've found with java a clear majority put the { on the same line. In c# a clear majority put it on a new line. C++ I don't think has such a clear consensus.

                  Personally I prefer { on a new line, but I don't think it makes much difference to readability (as long as you're consistent) so it's really just a minor issue & if I'm working with java I put it on the same line.
                  Last edited by fortifa; April 30, 2011, 08:43 AM.

                  Comment


                  • #10
                    Re: Code alignment

                    I never do the variable alignment bit. Makes the whole editing quite a bit messy without editor and it just feels unnatural. As a primary java coder I try to follow the Sun's standard which seems pretty reasonable to me.

                    I actually care about basic indentation. Use 4 spaces, for tabs which makes things consistent regardless of tab-stop issue. I consider good naming, nice spacing makes a more important contribution.

                    int aVariable, bVariable // one space after the type, comma and slash.

                    Login login .. rather than Login l.

                    Sorry if I went a little farther than the OP asked but it all boils down to how easy is the rule to follow and how much readable it make things. Consitentcy across a project is important so making up rules that other won't/can't follow doesn't make sense either. Even if its only your personal project, I find its best to stick to some basic rules and follow it. Today the convesion I follow is sort of in my muscle memory so I don't really worry about it but just follow it. So make a solid good practice as you start coding and things would go much easier in the long run.

                    Comment


                    • #11
                      Re: Code alignment

                      For me, it really depends on what I'm writing. If it's just a little script to make something on my own computer run a little easier, then why bother? But if it's a project that someone else will be contributing to at a later stage, alignment is almost as important as proper documentation.
                      For the bracketing, I often put the "{" on the initial line because I was taught that way. However, if I'm using an editor that doesn't have bracket highlighting, I'll often put the "{" on the next line for clarity.

                      Comment


                      • #12
                        Re: Code alignment

                        I've never aligned code like in the OP example; seems silly. Every coder will usually have a slightly unique white space format, however.

                        Comment

                        Working...
                        X