C
craig
I am curious about how many of you prefer style 1 vs. style 2, and why. Are
there names for these style?
style 1:
method {
}
style 2:
method
{
}
there names for these style?
style 1:
method {
}
style 2:
method
{
}
Nicholas Paldino said:Craig,
Personally, I use style 2. It's just a preference. I don't know if
there is a name for those styles, but I prefer to call style 1 "ugly" and
style 2 "pretty". =)
In all seriousness though, I find for myself that it is easier for me to
distinguish code blocks by using style 2.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
craig said:I am curious about how many of you prefer style 1 vs. style 2, and why. Are
there names for these style?
style 1:
method {
}
style 2:
method
{
}
craig said:I am curious about how many of you prefer style 1 vs. style 2, and why. Are
there names for these style?
style 1:
method {
}
style 2:
method
{
}
when you have several nested code blocks that span several pages so that you
can't see both the start and the end of the code blocks on the screen at the
same time.
scroll back and forth between the start and the end of the block while
trying to figure out the alignment.
Mike said:The only way to tell which bracket corresponds to which code block is to
scroll back and forth between the start and the end of the block while
trying to figure out the alignment.
When trying to decide which opening brace matches a closing brace in Visual
Studio, I use the Ctrl + ] key combination to jump back and forth between
them. To use it, place the cursor next to one of the braces before pressing
Ctrl + ]. The cursor will then jump to the matching brace.
-Mike
however,craig said:Thanks for all the responses. Its great to see that the consensus appears
to be the same as what I prefer as well, style 2. It seems that alot of the
sample code that I see in books and out on the web uses style 1,styleso
I was wondering if maybe I was missing something in prefering style 2.
The one thing that I notice is still kind of difficult using eitheris
when you have several nested code blocks that span several pages so that you
can't see both the start and the end of the code blocks on the screen at the
same time. If you want to do something like add a new method, it can be
tough to tell at what level within the code blocks to insert the method,
because all you can see is something like the following:
}
}
}
}
The only way to tell which bracket corresponds to which code block is to
scroll back and forth between the start and the end of the block while
trying to figure out the alignment. I suppose this may be an area where VB
shines because each of these block endings would be labeled, rather than
just appearing as a bracket.
why.
Are
Mattias Sjögren said:A little bit of both. I use "style 1" for statements inside a
method body (while, if, switch, for etc.), but "style 2" for methods
and types.
Simon Trew said:One thing I dislike about C# is I can't write things like
while (x)
{
null;
}
Which I've grown up with as a convention in C++ to be saying "I've
intentionally left this statement empty" which
while (x);
would not necessarily show so obviously.
Simon Trew said:Yes-- as I say, in C++ (or at least as far as MS style guidelines go) "NULL"
has become a convention for saying the same thing-- I guess it also might
suppress a possible compiler warning about an empty statement block, which
the comment would probably not. For the same reason you sometimes see things
like
public void MyFunctionThatMustConformToSomeSignature(object a, object b)
{
a;
DoSomething(b);
}
The first line of which suppresses a warning about a being an unused
parameter (in the C++ equivalent, that is). In fact MFC has a macro called
UNUSED_PARAMETER that simply translates to the above form; there is no
equivalent EMPTY_STATEMENT although it would be easy enough to define one.
I had more real estate with "vi" on an 80x32 monitor than I get these
days with .NET...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.