|
I have a habit of typing } followed by back key as soon as I type {. This keeps things under control as the chances to forget typing } are none. I would also suggest to try outlining for visual studio. Try this[^]. Using this you will be able to work in the current block while collapsing the other code blocks. Another thing I would like to suggest is the use of ctrl+K+D(for code formatting), Ctrl+M+O and Ctrl+M+P to toggle outlining. I find these combinations very handy while coding.
|
|
|
|
|
The tool looks good. Going to give it a go when I can. Thanks
|
|
|
|
|
You're welcome
|
|
|
|
|
RossMW wrote: They can be time waster.
They have never been a time waster for me. I have never given it a second thought.
Because you don't do this much, you will notice "everything", I would guess.
|
|
|
|
|
I am constantly formatting the document. In VS it is Ctrl+E, D. This keeps the braces matched up.
Eric
|
|
|
|
|
|
What I have been known to do:
void SomeLongFunction {
// many lines of code
} // end void SomeLongFunction
|
|
|
|
|
No just use Resharper it does it for you.
|
|
|
|
|
In VS you can just use ctrl+'}' on one of the braces to toggle to what VS thinks is the match. This can be done for any open and close types, html tag or ( ) etc. VS2013 will add both for you by default as you type.
|
|
|
|
|
RossMW wrote: Do you have any tips on keeping these damn { } under control?
Yes, it's called ReSharper[^]
I've been using it since 2009 and I have no idea how to use Visual Studio anymore without it.
I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone - Bjarne Stroustrup
The world is going to laugh at you anyway, might as well crack the 1st joke!
My code has no bugs, it runs exactly as it was written.
|
|
|
|
|
Find matching brace (most code editors have one) -- Visual Studio: ctrl-], Vi: %
Use a smart editor that automatically adds, shows or otherwise assists in making sure you have balanced brackets.
Consistent indentation.
It also helps not to have large blocks of code, but sometimes that just can't be avoided.
It is a pain sometimes, but I've just learned to live with it since the previous alternatives were much, much worse.
We can program with only 1's, but if all you've got are zeros, you've got nothing.
|
|
|
|
|
How long is on average one of your methods?
A method shouldn't be longer than a screen, which makes around 50 lines of code.
This will solve your braces problem immediately.
modified 20-Oct-19 21:02pm.
|
|
|
|
|
I don't know about anyone else, but when I enter a '{', I also enter the corresponding '}' before I insert any code in between the braces. I never have a problem with unbalanced/misplaced braces.
Fletcher Glenn
|
|
|
|
|
Obviously, you are using the god-forsaken "K&R" bracing style
if (condition) {
}
When you choose a coding style based on readability rather than historic fanboy popularity, these problems go away:
if (condition)
{
}
Truth,
James
|
|
|
|
|
When there's too much nesting, and therefore too many braces, consider
1) refactor out inner nestings into new methods
2) label }'s:
namespace foo
{
public class bar
{
public void fu()
{
for(var int i = 0; i < 10; i++)
{
if(Math.PI != 0.0)
{
} // if PI not 0
} // for i
} // fu
} // bar
} // foo
|
|
|
|
|
Productivity Power Tools [^] includes Guidelines which are helpful.
VSCommands [^] has a "Code Block End Tagger" that will show a "tag" on the closing brace either all the time or only when the opening brace is not in view.
Sincerely,
-Mark
mamiller@rhsnet.org
|
|
|
|
|
This. I consider both packages a must. Also, VSCommands' tag has some important advantages. In addition to telling you what the curly brace is ending, it is clickable - navigating you back to the matching opening curly brace.
|
|
|
|
|
|
In Visual Studio, you can press Ctl-K & Ctl-D
that will format your document. Same as pressing Edit>Advanced>Format Document.
That will give you an indication of where the faulty area is, then, you can follow the {}'s via indention.
Moving from VB to C#, for a while, I followed the convention of put in all the decorations first, before inserting code.
What got me was how after a period of time using c#, coding vb, I felt like I was leaving stuff out, ... in particular the semi-colons.
|
|
|
|
|
Hey,
Go to Tools->Extension Manager. There are many useful extensions there for you like "Brace Completer" which will automatically puts '}' when you type '{', "Code alignment" for aligning your code automatically, "highlight all occurrences of selected word", "word wrap with auto-indent", "JScript Editor Extensions" for many useful JavaScript extensions.
Hopefully it will help you better coding
|
|
|
|
|
I often comment the closing brace, saves a lot of brace-matching but does add some clutter:-
...
}
}
}
}
|
|
|
|
|
RossMW wrote: Do you have any tips on keeping these damn { } under control?
Always, always, always have my opening and closing brackets in the same row or column. And put comments after }, as Member 10707677said.
Trying to figure out where the missing { is when people put the opening { on the same line as the function or if, is just making life unnecessarily hard. And sometimes I come across conditions that are so ugly, I have to do it there too...
if (((x==0) && (y==1)) && (z==2) && ((w==3) && foo==bar))
if ( ((x==0) && (y==1))
&& (z==2)
&& ((w==3) && foo==bar)
)
Occasionally, I have to go and ask whoever wrote it... why?
|
|
|
|
|
I've been doing web dev for a couple the last couple of years. Necessity (a/k/a providence) has allowed me to go back and play with C++.
At first, it was a fierce battle to bring distant memories into the fore - but like riding that bicycle: strong typing, ::, and the like, do give one a warm fuzzy feeling.
A clear move back towards the top of the fool chain.
Time to make some tracks towards home.
"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 disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
I've been using C/C++ quite a bit for the last couple of years and I find a lot of satisfaction in using them.
New version: WinHeist Version 2.1.1 new web site.
I know the voices in my head are not real but damn they come up with some good ideas!
|
|
|
|
|
You need to seek help. Perhaps go and see a sharp therapist.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|