"Too Much Information" actually means "My Brain Is Too Small For it".
There are 4 code tabulation styles widely known (and this topic still generates flames):
1) no TABs, only SPACEs. Pros: code layout does not depend on a chosen TAB size. Cons: it is easy to screw proper indentation with a BACKSPACE; it is annoying to hit BACKSPACE 4 times instead of once (given tabsize = 4)
2) TABs are everywhere. Pros: easy and strict; you cannot screw indentation because it is always aligned to a grid Cons: changing tab size may produce weird result when TABs are used for alignment in a middle of a line
3) random mix of SPACEs and TABs. Pros: none. Cons: this approach is a pure evil.
4) TABS are for indentation level only, SPACEs are for alignment. Pros: same as in styles 1 and 2 — no dependence on tab size, easy, strict. Cons: unfortunately, code editors usually supports either style 1, or style 2, so you cannot just use TAB key everywhere and expect that your editor will be smart enought to replace TABs to SPACEs in proper places. At least, in VisualStudio it is so. May be other code editors are smarter?
I personally prefer TABS over SPACES, and, when coding alone, I just use the style 2. The “tab size problem” does not bother me because I just never use garbage editors/viewer which are not capable to configure the tab size.
In a team, I have to adapt to those members who still use the shitty Notepad and suffer from the “tab size problem”. On the other hand, I don’t want to lose all benefits of TABs, so I’d prefer to use style 4: TABs for indentation, SPACEs for mid-line alignments. Code editors are the only stoppers here.
So, what can we do at least for a VisualStudio Code Editor? Fortunately, there is a trick: you can use a combination of three commands:
>Edit.SelectAll >Edit.ConvertTabsToSpaces >Edit.TabifySelectedLines
So, you can use TABs for editing everywhere, and then, before committing the file, just run there 3 command in the VS Command Window. Command names are almost self-describing:
Edit.SelectAllselects the whole code text
Edit.ConvertTabsToSpacesconverts all TABs to SPACEs
Edit.TabifySelectedLinesconverts SPACEs back to TABs, but works only on leading SPACEs! That’s the trick.
Unfortunately, the solution is not ideal: it replaces all leading SPACEs to TABs, though there are cases when you should not do it. For example, if you break a long function parameter list into several lines, you’re actually staying on the same indentation level and want the parameter list be adjusted, not indented. Improving the algorithm will require source code parsing to find cases when a new line does not introduce a new indentation level.
Anyway, we still have a quite decent solution. But typing these commands again and again is unproductive. If you find yourself repeating — write a script. So it is better to translate these commands to a macro:
Public Module Editor Sub TabifyAll() Dim curPoint As VirtualPoint curPoint = DTE.ActiveDocument.Selection.ActivePoint DTE.ActiveDocument.Selection.SelectAll() DTE.ExecuteCommand("Edit.ConvertTabsToSpaces") DTE.ActiveDocument.Selection.Tabify() DTE.ActiveDocument.Selection.MoveToPoint(curPoint) End Sub End Module
Now we can add the macro as a menu command, assign a keyboard shortcut for it, etc. I’ve put this command into “Edit” menu as a “&Tabify” menu item, so I can use “Alt-E,Alt-T” shortcut.
Also it is possible to write a similar macro which will “tabify” only a text selection instead of the whole file, but actually I don’t think it makes a lot of sense: you usually want to keep style consistent over the whole document (and even over a whole project/solution/workspace), not just a small selection. I’d prefer a script which performs this action automatically upon a file save. May be someone will write a VS extension for this, someday…
Tumbled off one @yes-butno manifesto proudly saying “Yes, I’m a christian. Yes, I believe in evolution”, reblogged by 1000+s users. The message how I read it is “We’re open-minded enough to combine two contradictory worldviews in our heads, so nobody can blame us in dogmatism and hypocrisy”.
Disclaimer: if you’ve supported the manifesto but this is not what you’ve tried to say — you can stop reading here :)
OK, I saw this position many times, and I discussed it a lot, but I think it’s never too late and too much to repeat an old truth.
So, is it brave to be religious and believe in some contradicting scientific theory like Darwinian evolution or Big Bang theory? Is it open-minded and anti-hypocritical, now some commenters boast? Time to write my counter-manifesto, in the same “yes, but no” style :)
YES, you can believe in evolution/BigBang/etc, being christian or whoever else. After all, who’ll prevent you?
NO, this is not a bravery or open-mindness, at all. Rather blindness and big big misunderstanding, because it misses the main and crucial point of any scientific theory: YOU HAVE NOT TO BELIEVE in evolution or any other theory, even if it’s proven!
OK, let’s make it even stronger: you have to doubt any theory! Not just deny, like infamous AIDS-denialists, but DOUBT.
“Doubt to be sure" — that is the hardest trick! This looks like a paradox, and only truly brave and open-minded can embrace it in its entire beauty.
Indeed, the more you doubt a theory, the more you test it. The more tests it successfully passes, the more durable and trustworthy it becomes. If at some point your favorite fails — you bite a bullet and derive a new, better theory, which passes all previous tests plus the failed one. The way of doubts and tests and elimination of inadequate and maladaptive (sounds familiar?) is what can give you 99% of trust that the theory works well in most cases — but you’ll never get 100% trust (what the word “believe in" means).
This is how critical minds work, and how it’s totally different from any belief, and why the manifesto is so freakish. Those who regularly [re]invent this “I believe in <some scientific theory>"
manifesto nonsense, just habitually follow their religious mindset inherited from early childhood when we unquestioningly believe what we were said; now they try to be “tolerant / neutral / many-sided”, but imperceptibly sliding down into the comfortable “no doubts, just believe" state of mind.
So, this manifesto is not a word that I’d support and spread, because if you think more and deeper, it appears not thought-out very well. Amen :)