March 19, 2012 at 7:23 am
I've been in both environments regarding standards. Personal preference wise I use spaces; however I think the nail was hit on the head of a standard being put into place. Whatever the standard becomes it should be follow depicting unity among team members.
I don't really know if there is a wrong or right answer to this one; it is one that has and probably will all ways be battled out!
March 19, 2012 at 7:29 am
Nakul Vachhrajani (3/18/2012)
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.
THANK YOU!
I have been looking for that setting forever. I thought SSMS lacked it. Then I went looking again because of your post.
For anyone else who couldn't find it, it's Tools / Options / Text Editor / Transact-SQL / Tabs
Then set your tab and indent size, and choose "Insert spaces". Me, I use tabs set to 3 spaces...
March 19, 2012 at 7:31 am
Tabs
Cheers
March 19, 2012 at 7:49 am
Another point of view: Best setting is the default setting of the tool (SSMS, VS, ...). Otherwise you have inconsistencies by everyone who has forgotten to change the setting.
And some people reinstall very often.
March 19, 2012 at 7:51 am
tabs
To borrow from web design: semantic meaning. If the tab character (following newline) is taken to mean "indent" then four levels of indentation is literally 4 tab characters. I use tab to align the '=' following a field alias. In this usage it means align the equal sign to some visual column for the purpose of readability. It would be great to have the IDE understand this convention and implement it without requiring me to use multiple tab keystrokes to compensate for longer/shorter field aliases.
I feel that a space should be reserved to mean a literal space character.
I also agree that it's largely a non-issue when beautifiers can reformat valid code into any visual presentation you want. In that case the code is actually reparsed and any original whitespace is irrelevant.
March 19, 2012 at 9:48 am
Spaces preferred. The problem with tabs, as mentioned in the article is that people don't use them consistently. So you get spaces and tabs mixed, which results in very messy looking code.
One of the first things I do when I install an IDE/editor is go to the settings that changes tabs to spaces.
I suspect some people who prefer tabs simply for fewer keystrokes are lazy and probably also don't bother to do other things that result in clean and neat code. (Code block alignment, etc.)
March 19, 2012 at 10:23 am
Lots of people say tabs because it's less typing. You can configure tabs to be entered as spaces. I wouldn't think the typing is that big a deal then, especially with CTRL+arrow keys.
March 19, 2012 at 10:27 am
Tabs, all the way.
Saying that you want to use spaces because people will write improperly formatted code is a hack. Tabs have the same usefulness and purpose in writing SQL as they do in C#. The people that will use spaces where they should have tabs probably won't use either correctly (if at all), so why would you want to deliberately shoot yourself in the knee for them?
Spaces are a cop out. Next thing you know you'll be recommending cursors because someone may someday work on the code that doesn't understand other constructs. 😉
March 19, 2012 at 10:29 am
Don't care too much about Tab vs Space in T-SQL code. It makes a difference in Python coding, but that's the only place I've seen where that matters. I tend to run other T-SQL through a formatter to make it a little easier to read so don't care too much about the formatting most times.
We do a lot of web front end coding and decided on Tabs there to reduce the amount of data sent back to the users in some of the front-end code where things aren't necessarily compiled or completely compressed. It was standardized, a decision was made, everyone sticks to it.
March 19, 2012 at 10:34 am
MarbryHardin (3/19/2012)
Tabs, all the way.Saying that you want to use spaces because people will write improperly formatted code is a hack. Tabs have the same usefulness and purpose in writing SQL as they do in C#. The people that will use spaces where they should have tabs probably won't use either correctly (if at all), so why would you want to deliberately shoot yourself in the knee for them?
Spaces are a cop out. Next thing you know you'll be recommending cursors because someone may someday work on the code that doesn't understand other constructs. 😉
This is why it can become a religious war. Everyone has their own preferences and it isn't a cop out.
And regarding the use of cursors, what an apples to oranges comparison that one is. Everyone knows that cursors are a necessary evil that should be avoid 99.999% of the time. They have their uses, but it is very rare in most production code.
March 19, 2012 at 10:39 am
I think maybe you're right. This one isn't going to get resolved one way or the other.
It kind of reminds me of the the old programmer's argument of how do your pronounce the datatype "char"?:
"It's short for "character" so it's pronounced 'care'."
"It's spelled 'char' so it's pronounced exactly as it's spelled."
There's just no winning either way.
March 19, 2012 at 10:40 am
Back in my 20's, my entire COBOL program was taken by another developer who replaced every blank comment line with a line containing asterisk in column 7 stating categorically that it took less space to store an asterisk line than a blank one! The code was stored by Librarian - a text compression add-in and source management tool, so his method added to scarce bytes. Duh!
Now we're debating tabs and spaces. 30 years and nothing much changes... 😀
Worse than tabs/spaces, is when I find lazy (senior!) programmers leaving scrotty, non-formatted, uncommented, SQL-spaghetti for their successors who must spend cycles formatting for basic readability before being able to get on with the task charged to them. One prime example eventuated in two major logic flaws in the Invoice SQL I inherited - and the originator felt it was just fine to check in their multi-statements to a line piece of junk and call it "done and tested" (My eye...!)
As for the post that said "less key strokes" - "insert spaces for tabs" = same keystroke count, especially with smart tabs.
Totally agree with spaces for tabs as I've met so many different indent sizes ranging from 3 or 4 to 8. Try reading a chunk of heavily indented code that pops up with 8 column indents - where's my triple-wide screen when I need it?!
Thank goodness for SQL Prompt's Format SQL - not perfect but it helps expose rotten wood.
March 19, 2012 at 10:45 am
Nadrek (3/18/2012)
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?
+1:-D
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
March 19, 2012 at 11:58 am
This is one of those presentation vs content items.
I wish the tools were intelligent to store a common interpretation but present as the individual prefers.
To me the presentation of this is as much a user preference as having green text on a black background or white text on a blue background.
I've found problems with both tabs and spaces while writing for SQLServerCentral.
If you forget to wrap up your code in pre tags then you get proportional spacing. A real swine when using space.
Trying to enter tabs is a real swine when working in HTML.
March 19, 2012 at 2:40 pm
I can't relate to this debate at all. I'd be thrilled if a certain colleague used ANY kind of indentation to make his SQL code readible.
Can anyone recommend a free or very inexpensive SQL Beautifier/Formatter which works well with complex queries? One that integrated with SSMS 2008 would be ideal.
(I can't seem to connect to the SQLInform website (sqlinform.com) that Nadrek mentions. Perhaps SQLInform is overwhelmed today due to being mentioned in this thread?)
Viewing 15 posts - 16 through 30 (of 49 total)
You must be logged in to reply to this topic. Login to reply