471,354 Members | 1,191 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Coding Conventions?

I realize that you people have not seen much of me other than some framework
responses I have posted.

I am primarily a VB guy (yes, you can laugh) But I have lurked here for
several years, picking up little crumbs of C# wisdom.

Perhaps it's just my style, but what's this annoying behavior of the IDE and
how do I stop it:

C# seems to want me to write all my code like this:

public class Foo
{
public void DoThis()
{
// code here
}
}

What I REALLY want is to write my code like this:

public class Foo {
public void DoThis() {
//code here
}
}

Things like loops, IF and CASE blocks get really irritating when they use
the lengthy expanded format that the IDE seems to enforce, and I really want
the code window to behave like how I think. Is there some option or
template that I have to modify?

Also, while I'm at it, how do you all prefer to write? Expanded curly
braces? Brace on the sig line? whole programs in one big long line of
text? I guess here, I am just asking how the rest of you prefer to write
code.
--
Peace & happy computing,

Mike Labosh, MCSD MCT
"Escriba coda ergo sum." -- vbSensei
Jan 22 '06 #1
4 1374
> Things like loops, IF and CASE blocks get really irritating when they use

Whoops, that's my VB drain bramage showing its head. I mean SWITCH blocks.

--
Peace & happy computing,

Mike Labosh, MCSD MCT
"Escriba coda ergo sum." -- vbSensei
Jan 22 '06 #2
Mike,

Go to "Tools | Options". On the dialog that pops up, go to "Text Editor
| C# | Formatting"

Under there, past "General", there is "Indentation", "New Lines",
"Spacing" and "Wrapping".

That should allow you to set everything that you want. For your
specific braces issue, you want "New Lines" and then you want to UNCHECK the
following:

Place open brace on new line for types
Place open brace on new line for methods
Place open brace on new line for anonymous methods
Place open brace on new line for control blocks

As for my style, I prefer to code like this:

public
class
MyClass
{
public
MyClass
(
)
{
}
}

But that's just me.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike Labosh" <mlabosh_at_hotmail.com> wrote in message
news:u7*************@tk2msftngp13.phx.gbl...
I realize that you people have not seen much of me other than some
framework
responses I have posted.

I am primarily a VB guy (yes, you can laugh) But I have lurked here for
several years, picking up little crumbs of C# wisdom.

Perhaps it's just my style, but what's this annoying behavior of the IDE
and
how do I stop it:

C# seems to want me to write all my code like this:

public class Foo
{
public void DoThis()
{
// code here
}
}

What I REALLY want is to write my code like this:

public class Foo {
public void DoThis() {
//code here
}
}

Things like loops, IF and CASE blocks get really irritating when they use
the lengthy expanded format that the IDE seems to enforce, and I really
want
the code window to behave like how I think. Is there some option or
template that I have to modify?

Also, while I'm at it, how do you all prefer to write? Expanded curly
braces? Brace on the sig line? whole programs in one big long line of
text? I guess here, I am just asking how the rest of you prefer to write
code.
--
Peace & happy computing,

Mike Labosh, MCSD MCT
"Escriba coda ergo sum." -- vbSensei

Jan 22 '06 #3
> Also, while I'm at it, how do you all prefer to write? Expanded curly
braces? Brace on the sig line? whole programs in one big long line of
text? I guess here, I am just asking how the rest of you prefer to write
code.


For what its worth, I do prefer the default formatting. Braces on seperate
lines, class and method definitions on one line(with the exception of the
where operator or inheritets\implements lists of more than about 3 items,)
and statements taking one line each. I was quite pleased when I launced
VS.NET the first time and found the C# conventions to be almost exactly to
my liking.
Jan 22 '06 #4
Consistency is more important that the style you actually use, especially if
you code as part of a team. You want all code to look like it could have
been written by anyone within the team, and that any team member making
changes doesn't have to "think" about formatting style, since after a few
months of applying a consistent coding style it becomes second nature. If
you're a one-person developer you don't have these issues obviously, but
consistency is still important.

At my previous job I did not put opening curly braces on a line by
themselves - UNLESS they were for a class declaration or the opening body of
a function (classic C K&R style). My opinion back then was that if K&R
invented the language, so am I to argue about their formatting style?

But C# is not truly C, so I take some liberties with it. Really short
methods you might find writing on a line by themselves, like C++ inline
methods. For example, in C#:

public abstract string MyProperty( ) { get; }

Padding this out to multiple lines serves no useful purpose and in my
opinion actually reduces the clarity of the code, since there is no
implementation anyway.

At my new job braces go on a line by themselves, but we still have enough
flexibility to allow for the above convention where the construct is short
enough to warrant it (we effectively apply our C++ coding conventions -
where they make sense - to C#).
"Mike Labosh" <mlabosh_at_hotmail.com> wrote in message
news:u7*************@tk2msftngp13.phx.gbl...
I realize that you people have not seen much of me other than some
framework
responses I have posted.

I am primarily a VB guy (yes, you can laugh) But I have lurked here for
several years, picking up little crumbs of C# wisdom.

Perhaps it's just my style, but what's this annoying behavior of the IDE
and
how do I stop it:

C# seems to want me to write all my code like this:

public class Foo
{
public void DoThis()
{
// code here
}
}

What I REALLY want is to write my code like this:

public class Foo {
public void DoThis() {
//code here
}
}

Things like loops, IF and CASE blocks get really irritating when they use
the lengthy expanded format that the IDE seems to enforce, and I really
want
the code window to behave like how I think. Is there some option or
template that I have to modify?

Also, while I'm at it, how do you all prefer to write? Expanded curly
braces? Brace on the sig line? whole programs in one big long line of
text? I guess here, I am just asking how the rest of you prefer to write
code.
--
Peace & happy computing,

Mike Labosh, MCSD MCT
"Escriba coda ergo sum." -- vbSensei

Jan 23 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Roman Roelofsen | last post: by
3 posts views Thread by David Inada | last post: by
1 post views Thread by jarit | last post: by
9 posts views Thread by Neil Zanella | last post: by
144 posts views Thread by Natt Serrasalmus | last post: by
7 posts views Thread by Ralph Lund | last post: by
6 posts views Thread by Andrea Williams | last post: by
4 posts views Thread by Dotnetjunky | last post: by
19 posts views Thread by auratius | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.