|
You should consider to be more consistent?
Use spaces or tabs but not both!
For legacy code: <Ctrl+K, Ctrl+D> which reformats the code using the current VS settings.
|
|
|
|
|
|
|
Yes and no.
I prefer tabs (tabsize = 2) which makes collective code ownership easier because there are codes prefering tabsize = 4;
The given sample at StackOverflow using multiple spaces within the code (not for indention). You shouldn't to it that way. It was good for C++ but for C# you should avoid it:
StyleCop + NerdBank custom rules will be your friends
|
|
|
|
|
hfrmobile wrote: You shouldn't to it that way.
Why?
hfrmobile wrote: It was good for C++ but for C# you should avoid it:
Where's the difference?
No, really, these are honest questions.
(I generally would prefer elastic tabstops anyway)
|
|
|
|
|
Sorry for the confusion!
peterchen wrote: Why?
StyleCop: SA1025: The code contains multiple spaces in a row. Only one space is needed.
There is no need for it in C# (for C/C++ it is OK):
public enum PublicEnumeration
{
TestValueNull = 0,
TestValueOne = 1,
TestValueTwo = 2
}
prefer:
public enum PublicEnumeration
{
TestValueNull = 0,
TestValueOne = 1,
TestValueTwo = 2
}
peterchen wrote: Where's the difference?
C# and C/C++ are complete different languages .... OK, they have similar Syntax and keywords, but they're complete different!
|
|
|
|
|
For the second thing, It's more the comment style that makes a difference - though that's not a bad reason.
If you use another documenting utility, it might be an issue again. "Completely Different languages" doesn't cut it (for the questions I posed)
(I'd say XML comments are the default if you wouldn't have to balance source code readability against documentation quality so much, and if Sandcastle wouldn't be such a sluggish heavyweight.)
hfrmobile wrote: StyleCop: SA1025:
Well... what would you say about
StyleCopEX: SAX1026: newlines detected in method. Entire method can be implemented without newlines.
(i.a.W. a StyleCop warning is not a reason)
|
|
|
|
|
This soft tab may be better. Hard tab sometimes cause inconsistent tabbing as the user do not see extra tabs in the source code in Visual Studio.
Copying the entire code and paste in Microsoft Word and sometimes the extra tab can be seen.
So.... soft tab is better... as it can lesson the formatting as seen on Microsoft Word.
|
|
|
|
|
The ability to copy into MS Word is a poor excuse for a coding guideline. If you really must copy into MS Word, then untabify your code (there's a menu item for it, which you can even map to a key if you use it often) and then copy it.
By the way, I'm not saying that tabs is better. There are other better reasons for using spaces -- copying into MS Word is just a poor one. There are also very good reasons for using tabs, which is why I believe the programming world is so split on the issue.
|
|
|
|
|
Now that I've got a second thought... hard tab seems better now.
I had soft tabs on my code. I then just learned something... I switched to hard tab, then go to the very bottom of the code, then removed the very last closing bracket. I reinserted the closing bracket and all of the spaces were replaced with hard tabs, removing any inconsistent tabbing automatically. Ahh there we go!
|
|
|
|
|
I prefer hard-tabs and not soft-tabs (spaces) because to support coders preferences: Some prefer 4 chars for indention, others prefer just 2 ...
Collective code ownership is easier to mange indenting using tabs and so each coder can use the tab size she/he prefers
Tabs also enables us easier and faster navigation through the code using cursor keys
|
|
|
|
|
To have it consistent we are using in our group AStyle (artistic style) with an common agreed setting, also as a tool within VS.
This allows also the control of spaces between operators and much more.
|
|
|
|
|
|
no, I am mean the artistic style program, you can find it at http://astyle.sourceforge.net
|
|
|
|
|
It's nice to see that they support OpenVMS. That's where I've had trouble in the past. At one company we had a written standard of four SPACEs, and it was good. Then those Visual Studio people came along and didn't follow directions; they were supposed to set VS appropriately, but didn't. I'd open a file on my dumb terminus (or emulator) and the indenting would be screwed up. I wrote my own filter to correct it.
|
|
|
|
|
It is easy to use. Just a Hard Tab press. And also it makes the formatting proper. Pressing a single key instead of several space strokes is always a better idea.
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
|
|
|
|
|
It's just as easy to use spaces: you tell the IDE to substitute spaces (the appropriate number: I prefer 2 instead of 4). You'll need to press the backspace key more if you delete - but that's easily circumvented by not making mistakes.
If you've ever opened your code in another editor, you'll often be treated to a horror show of by using tabs.
/xml> "The difference between genius and stupidity is that genius has its limits." - Albert Einstein
| "As far as we know, our computer has never had an undetected error." - Weisert
| "If you are searching for perfection in others, then you seek dissappointment. If you are searching for perfection in yourself, then you seek failure." - Balboos HaGadol Mar 2010
|
|
|
|
|
|
It is not always necessary to delete parts of your indention due to mistakes; what about simple changes to your code, an if that was scrapped maybe. For that reason, hard, always
|
|
|
|
|
I prefer hard-tabs and not soft-tabs (spaces) because to support coders preferences: Some prefer 4 chars for indention, others prefer just 2 ...
Collective code ownership is easier to mange indenting using tabs and so each coder can use the tab size she/he prefers
Tabs also enables us easier and faster navigation through the code and avoids making mistakes
StyleCop is your friend!
The source code files will be smaller (this shouldn't be the only reason using TABs ^^)
|
|
|
|
|
This does not really matter until you have to diff in your source control tool. Spaces force everyone to be on the same page with respect to indentation size. I hate spaces and always use tab characters. I prefer to make sure everyone has the same IDE configuration than to force everyone to use spaces.
|
|
|
|
|
Absolutely agree with you even Diff (using Subversion) is able to ignore white spaces
But often I see code on MSDN pages using indention of 4 chars using spaces (!). I prefer indention of 2! When using TABs this is no problem
|
|
|
|
|
I am pretty consistant about using tabs. However I am no zelot. Compared to all the other faults I have seen in code, this is less than nothing.
Ken
|
|
|
|
|
Yes and no ...
Often have seen code with a mix of tabs and spaces and it was horrible to read because some coders used tabsize=2, others used tabsize=4 but with spaces ...
I agree with you that it should not be a big deal. In the .NET it is easy: Use StyleCop
|
|
|
|
|
If you do not like it you can run the code through a formatter.
but I use hard tabs.
cheers,
Donsw
My Recent Article : CDC - Change Data Capture
|
|
|
|
|
no stinkin' tabs. Formatting code so that it is easier to read has never helped a compiler that I've used.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|