Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. A Question of Style

A Question of Style

Scheduled Pinned Locked Moved The Lounge
question
67 Posts 29 Posters 66 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jim SS

    Personal preference is tabs (3 spaces), but I am glad that other people have other preferences. I can almost always tell my code from others because of formatting. I got used to compacting my code when we only had 80x25 green screens so I could see more code on the screen at a time. I like:

    if (...) {
    ...;
    } else {
    ...;
    }

    others always do:

    if (...)
    {
    ...;
    }
    else
    {
    ...;
    }

    or:

    if (...)
    {
    ...;
    }
    else
    {
    ...;
    }

    It makes it easier to spot my own code and what may have been modified by me or others. I had a friend that could spot my code anywhere. He always claimed that I could write a whole program on a single line. :rolleyes:

    SS => Qualified in Submarines "We sleep soundly in our beds because rough men stand ready in the night to visit violence on those who would do us harm". Winston Churchill

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #61

    Jim (SS) wrote:

    write a whole program on a single line

    You should be able to; avoid constructs that require newlines.

    1 Reply Last reply
    0
    • S Synaptrik

      I can think of one reason. When aligning columns of assignments, if comparisons, etc. When using tabs instead of spaces, say yours is set at 2, and your colleague's is set at 4, you'll find freaky alignments for the mixed code. e.g. int foo = 0; int foobar = 0; So, I prefer spaces. And a code standard to enforce the number, after deliberations of course. :) Some shops use 2, but most I've found prefer 3.

      This statement is false

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #62

      But that's after the first non-whitespace character and therefore not part of the indent.

      1 Reply Last reply
      0
      • P PIEBALDconsult

        I just installed and experimented with SciTE yesterday, it has settings for each language.

        aquatarian wrote:

        and fix the indenting to the project's code formatting rules before commit.

        If only. :sigh: Eventually I wrote my own untab utility. It would be better if the code library system performed a beautify action to ensure standards compliance and eliminate (most) format-only changes.

        B Offline
        B Offline
        BananaRaffle
        wrote on last edited by
        #63

        Netbeans does this. You can define, very specifically, how to format the source. Then you hit a key/menu command and it reformats the entire file. It comes with built-in configurations that format in the style of ANSI, K&R, Linux, MYSQL, OpenSolaris, Apache, etc. It's not 100% perfect (sometimes a space will be out of place), but it's still the closest I've seen to the ideal.

        1 Reply Last reply
        0
        • L Lost User

          No - if I set my tab spacing to 4 and my colleague to 2, then the display of thesource on my PC shows 4 'spaces' - the same source on his PC shows 2 'space'

          If I knew then what I know today, then I'd know the same now as I did then - then what would be the point? .\\axxx (That's an 'M')

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #64

          But if you type it out in a DOS box, it's 8.

          L 1 Reply Last reply
          0
          • H Henry Minute

            PIEBALDconsult wrote:

            I wrote my own untab utility

            Did you do an article on it?

            Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #65

            I have now, just emailed it off.

            1 Reply Last reply
            0
            • P PIEBALDconsult

              But if you type it out in a DOS box, it's 8.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #66

              Yeesss. If I inscribed it using a chisel in a block of stone, the layout wouldn't be perfect either - but I don't tend to use archaic methods - that's why I paid good money to buy VS

              If I knew then what I know today, then I'd know the same now as I did then - then what would be the point? .\\axxx (That's an 'M')

              1 Reply Last reply
              0
              • A aquatarian

                When I'm not writing in a .NET language I use a cross platform editor too, Vim. It has a "modeline" feature where you can put a special line in (beginning with your language's comment char) that specifies the tab stop

                :: Windows batch/cmd script example, typically the last line in a file
                :: shiftwidth specifies the width of auto-indenting
                :: vim:tabstop=4:shiftwidth=4:noexpandtab

                # Perl example

                vim:tabstop=4:shiftwidth=4:noexpandtab

                Another popular cross platform editor (probably friendlier than Vim for a VS user), emacs, has a substantially similar capability though I personally do not know its syntax. Happily, vim also has the "retab" command so if someone sends me a file indented with spaces I can typically fix that in an instant :-\ Vin also has all number of features for auto expanding tabs with spaces, making the backspace key delete n number of spaces, etc... (and I'm reasonably confident that emacs mirrors this capability) so my main point is people should use whatever they want and fix the indenting to the project's code formatting rules before commit. Let your editor empower you! Hopefully someday I will figure out how to embed vim into VS which it can supposedly do.:cool:

                E Offline
                E Offline
                Ekimus
                wrote on last edited by
                #67

                ^ OMG!!! Tabs vs. Spaces?!? Why not vi vs. emacs too??? On Topic: Spaces... If the editor doesn't have an option to insert n spaces in place of a tab character/keystroke, then it's not a programmer's editor. I got disappointed with Dreamweaver simply because of this since I had to follow standards with my php code.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups