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 64 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.
  • D Dan Neely

    No, hanging indents just require being smart about mixing them. The non hanging part is tabs, the extra spaces:

    TAB TAB DoStuff(Foo, bar,
    TAB TAB Spaces Baz);

    Works as intended on anyones editor regardless of tab width.

    Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

    P Offline
    P Offline
    patbob
    wrote on last edited by
    #55

    That's a great solution, except it won't work if the editor converts spaces to tabs. Most of the editors I use, both Win and Lin, do that.

    patbob

    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
      #56

      Nooooo... should I? :~ I'm pretty sure it also removes trailing SPACEs, which VS won't do :mad: It may also be one that reports lines of excessive length. I guess I can at least take a look at the code. Oh goody. :sigh: P.S. Yeach... better just to write a new one in C#.

      1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        What, if any, is the practical reason for preferring spaces over tabs? I use tabs because when I need to increase or decrease an indent, it's only a single character that must be added or deleted. I noticed that the Google Guidelines disallow tabs, and use only spaces. What have they got against tabs?

        M Offline
        M Offline
        Member 1229083
        wrote on last edited by
        #57

        I hate tabs, though I'm usually forced to use it in order to stay consistent with the rest of the source files I'm working on. I hate when I copy & paste my code somewhere and it looks all messed up because of the tabs not expanding correcly. What's worse is that when I want to change the indentation or change variable names, suddenly all the layout I've worked on gets distorted. When I hit the space bar, I want to see things moving to the right of it exactly by one space. I don't want it to cause the right part of the sentence to suddenly jump, and especially I don't want to keep pressing the silly space and watch how nothing happens.

        1 Reply Last reply
        0
        • B Brady Kelly

          TheArtistFormallyKnownAsMaxxx wrote:

          I can indent 4 spaces, my colleague can indent 2 spaces

          Different indents in the same source? :~

          All Sorted

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

          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 1 Reply Last reply
          0
          • G Gary Wheeler

            Given that he's into testicles and anvils, probably not.

            Software Zen: delete this;

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

            I'm not into them, I was merely proposing a worse scenario.

            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
            • D Dan Neely

              No, hanging indents just require being smart about mixing them. The non hanging part is tabs, the extra spaces:

              TAB TAB DoStuff(Foo, bar,
              TAB TAB Spaces Baz);

              Works as intended on anyones editor regardless of tab width.

              Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

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

              Why use SPACEs there rather than a TAB? Shouldn't it be a full indent? :confused:

              1 Reply Last reply
              0
              • 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