A Question of Style
-
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
-
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.
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#.
-
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?
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.
-
TheArtistFormallyKnownAsMaxxx wrote:
I can indent 4 spaces, my colleague can indent 2 spaces
Different indents in the same source? :~
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')
-
Given that he's into testicles and anvils, probably not.
Software Zen:
delete this;
-
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
Why use SPACEs there rather than a TAB? Shouldn't it be a full indent? :confused:
-
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
Jim (SS) wrote:
write a whole program on a single line
You should be able to; avoid constructs that require newlines.
-
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
But that's after the first non-whitespace character and therefore not part of the indent.
-
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.
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.
-
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')
But if you type it out in a DOS box, it's 8.
-
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.
I have now, just emailed it off.
-
But if you type it out in a DOS box, it's 8.
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')
-
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:
^ 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.