SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Tabs or Spaces


Tabs or Spaces

Author
Message
Steve Jones
Steve Jones
SSC Guru
SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)

Group: Administrators
Points: 147537 Visits: 19434
Comments posted to this topic are about the item Tabs or Spaces

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Nadrek
Nadrek
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4572 Visits: 2741
I propose the following amendment to "... only programming project with no disagreement whatsoever on code formatting is the one you work on alone", to wit:

"... only programming project with no disagreement whatsoever on code formatting is the one you work on alone, or when everyone viewing the code runs it through a code beautifier first".

My answer to tabs vs. spaces, case convention, and pre vs post commas is always to let a computer do tedious, menial, purely rules based work - use a SQL beautifier/formatter. If someone else doesn't like your settings, they can use _their_ settings. None of that matters to the SQL parsing engine, so why should it matter to us?

There's a few out there, of which SQLInform is a reasonable one, though it doesn't have as many options for list indentation as I'd like. It does handle at least some of the tabs vs. spaces conversions, to however many spaces per tab you prefer!
Nakul Vachhrajani
Nakul Vachhrajani
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3309 Visits: 2149
Perhaps the major reason I hate tabs in code is that tabs are not interpreted in the same way on all systems - some may have 4 spaces, others may have 7. This leads to a perfectly aligned and readable code on one machine, but mis-aligned code on another machine.

Another reason why I am against tabs is that result in the cursor jumping all over the place when scrolling up or down using the keyboard to find where an "END" exists for a particular "IF".

I always insist that my team has the "replace tabs with spaces" switch in SSMS options checked and also run code through the "beautifer" option of "Untabify selection".

In my humble opinion, there should be a consistent set of coding aesthetic standards that should be enforced by default (and result in warnings) by Visual Studio and associated tools.

Thanks & Regards,
Nakul Vachhrajani.
http://nakulvachhrajani.com
Be courteous. Drive responsibly.

Follow me on
Twitter: @sqltwins
Google Plus: +Nakul
Sean Lange
Sean Lange
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63146 Visits: 17960
I would tend to lean on the side of preferring tabs to spaces. I have worked in some environments where tabs would retain spaces like you mention but everybody had their own personal preference as to how many spaces represented a tab. The sql people typically used 4 spaces and the Delphi people typically used 8 spaces. It made all the stored procs so horribly formatted that we actually created a function (as a joke) to assign a random number of spaces to indent each line.

I can't imagine actually having an argument about it because I really don't think there is the one right way to go here. For me there plenty of other things to have arguments about than the differences between tabs and spaces.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Japie Botma
Japie Botma
SSChasing Mays
SSChasing Mays (640 reputation)SSChasing Mays (640 reputation)SSChasing Mays (640 reputation)SSChasing Mays (640 reputation)SSChasing Mays (640 reputation)SSChasing Mays (640 reputation)SSChasing Mays (640 reputation)SSChasing Mays (640 reputation)

Group: General Forum Members
Points: 640 Visits: 340
I will vote for tabs. Why? Just because I am lazy and using the arrow key to jump 4 spaces makes me smile. Our standards include the setup of the development environment. So tabs never cause ugly displays, and so I like it. I will retire in this company, so I do not have to worry about maintaining Steve's code someday. :-D

5ilverFox
Consulting DBA
South Africa
David Conn
David Conn
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3522 Visits: 1183
My Vote is for Spaces.

As previously mentioned there is no consistency in the interpretation of Tabs. I've seen 2, 4 & 8 Spaces.

Spaces are portable whereas Tabs are IDE specific.

I personally go for 2 Spaces mainly because I prefer to see all of my Code on one Screen without having to scroll left & right all of the time.

David
honza.mf
honza.mf
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2561 Visits: 1323
I vote for tabs. They can be extremely rapidly shown as 3, 4, 7... spaces by configuration and they can be converted to spaces if needed.
As I'm minority, I have my Visual Studio set to spaces.



See, understand, learn, try, use efficient
© Dr.Plch
paul.knibbs
paul.knibbs
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4242 Visits: 6240
There's no inconsistency in formatting using tabs provided you always use them--whether the code gets indented 4 or 8 spaces with a tab is largely irrelevant to its readability. Having said that, I prefer to use spaces simply because I can use fewer of them--I think a 2-space indent is ample, and if you use more than that (or use tabs) then you can end up having to scroll right to read the code in some cases!

Of course, these days it's almost a moot point because pretty much any competent code editor will have the capability of automatically indenting lines to suit your preferences.
Knut Boehnert
Knut Boehnert
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1351 Visits: 383
I prefer spaces simply for the main reason that T-SQL code is easier portable and readable between SSMS and BIDS.
BIDS by default uses 8 spaces for a tab where SSMS is configurable. SSMS has a big screen for code review, BIDS by default has a tiny window.
Tabs in BIDS can make the code disappear right out of the window. This then means extra efforts to enlarge the window, after review (and fix) back to default size and just simply more clicks than I want to count. All of this can be achieved with even more key strokes.

My main pet pieve is simply lazy developers who just don't care to follow one style and just mix and match then complain about the coding standards of others.
hannes.malan
hannes.malan
Valued Member
Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)

Group: General Forum Members
Points: 73 Visits: 251
I vote for tabs - less key strokes :-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search