Reputation: 27673
How to turn it off has been asked. But what's the point in it to begin with? After all - when I want to continue after the braces (or parentheses) - I have to press some key anyway. So how can I use this to my benefit?
Upvotes: 2
Views: 2979
Reputation: 8446
Different people have different preferences, but features like this in a code editor enable faster writing of code to the well-practiced user. For instance, when creating a function, typing
void foo(){ <enter>
will create the following code
void foo () {
<cursor here>
}
allowing you to quickly create something without worrying about typing out the syntax of the language (as much). The same should work with if
, while
, etc.
Like myself, programmers tend to be lazy (Doh! >.<) so even a couple fewer key presses is a glorious thing.
EDIT:
There is a comment that this doesn't actually save key presses, so I will attempt to clarify what I mean.
QUALITATIVELY: this is what I meant by "people have different preferences". Some people probably don't care about this feature, but some people find it very useful. Some people think that coding with auto-completion features feels more fluid... once you get used to it, it's hard to code without it.
QUANTITATIVELY: consider the following class wrapped within a namespace with and without auto-completion of braces and tabs.
namespace MyNameSpace {
\t public class DoStuff {
\t \t private int myPrivate;
\t \t
\t \t public DoStuff() {
\t \t \t myPrivate = 73; // 0x1001001 yay palidromes!
\t \t }
\t \t
\t \t public int GetMyStuff() {
\t \t \t return myPrivate;
\t \t }
\t }
}
ok, so if all of the "\t"s are tabs, then that's 22 (I hope I can count!) tabs, and 3 curly braces at the end for a grand total of 25 key presses. Not much, but not bad for such a small file and a simple feature.
What I really like about auto-completion of braces is what can happen when it is combined with more advanced features and tools. Depending on your IDE of choice, there may be many tools that let you auto-complete not only braces and parentheses, but keywords, type names, identifiers, etc. If you implement an interface, for example, there are tools which will automatically create an implementation class shell (without any implementations inside the methods), which means that you don't have to write any method declarations at all!
In my opinion, there is a tool out there that will suit any programmer better than a plain text editor. Just keep trying IDEs and corresponding tools until it feels right to you, and don't focus on the quantitative measurement of key presses.
Upvotes: 2
Reputation: 1823
I find the premise to be slightly questionable. Yes, there are instances where if you want to keep typing lines in sequential order the automatic brace completion probably gains little to nothing. However, I'd suggest that you (I) frequently program in non-linear lines. Some examples:
When you hit the end of a method, you are often going to jump to some other file to continue, so you don't have to add the ending brace of a method.
When you are modifying code inside of a method, you often times are just adding a couple lines of code.
Even when creating new files, I rarely start with a blank file, either I'm using a code snippet, or copying some other file as a starting point. Further, even if you're starting with a blank file, probably the first few lines that you're adding are namespace {
and class {
. Right there are two closing braces that you don't have to type because you're likely not going to be adding code after them.
And I'm sure there are more instances. Off the top of my head, I'd guess that I write continuous lines of code pretty infrequently. That may just be me though.
Upvotes: 3
Reputation: 1254
The point is that when you want to continue after the braces, you will have to press a key as you would have to if the feature didn't exist. However, when you want to type inside the braces or parenthesis, you won't have to type another key, the IDE won't complain about missing braces or parenthesis [and will indent everything correctly] while you type, and you'll be able to start typing right away.
Also, remember that there are other languages supported by Visual Studio that can, sometimes, take more advantage from this feature. Visual Basic, for example, does not requires that all method calls have parenthesis in them:
// This is completely valid in VB
obj.Method1.Method2.Method3()
// So if you open a parenthesis, it is because you probably want to write
// something inside them, like this:
obj.Method1(argument).Method(argument2).Method3(argument3)
Upvotes: 0