A code formatter

S

Simon

Hi,

Does anyone know of a code converter that take code like this:

public Name
{
get
{
return name;
}
}

and turns it it to this:

public Name{
get{
return name;
}
}


Notice how the braces arent put onto another line. (Whats the point? To make
your work look bigger?)

If anyone know of something that could go through a file and alter the
layout, that would be a big help

Thanks All

Simon
 
J

Jon Skeet [C# MVP]

B0nj said:
No, to make it less java-like...

Um, most Java programmers use braces on separate lines in my
experience. Not all by a long shot, but most.

I have to wonder what purpose the OP feels that putting the closing
brace on a line on its own serves, if he's asking what the point of
putting the opening brace on a line on its own is.

To my mind, the point is to make it clearer where the block starts and
finishes.
 
S

Simon

I have to wonder what purpose the OP feels that putting the closing
brace on a line on its own serves, if he's asking what the point of
putting the opening brace on a line on its own is.

I prefer it that way. It looks a lot tidier in my view and with indenting
code blocks are very easily distinguished.
I don't really see the point of putting them there - It just takes up more
paper when you come to print the stuff out!

Of course its just my preference though

Simon
 
C

clintonG

I have adopted the code block style myself which should not be
attributed to Java developers per se but rather to all developers having
learned to write clear and readable code from their C and C++
predecessors.

In any event, for those who prefer sloppy coding formats they should
know they will need to learn and use ctrl-[ brace matching more
frequently as they and others try to read and make sense of their code.

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/
 
J

Julie

Simon said:
Hi,

Does anyone know of a code converter that take code like this:

public Name
{
get
{
return name;
}
}

and turns it it to this:

public Name{
get{
return name;
}
}

Notice how the braces arent put onto another line. (Whats the point? To make
your work look bigger?)

If anyone know of something that could go through a file and alter the
layout, that would be a big help

Thanks All

Simon

If the MS Borg had done their formatter correctly (Format Selection: Ctrl+K,
Ctrl+F), they would have allowed customization of the reformatting
characteristics. It looks like they didn't (surprise!), too bad for us, we
must be assimilated.
 
N

Niki Estner

I think DevStudio's regex-search&replace feature should be sufficient:
Search for ":b*\n:b*\{", replace with " {".
(Unforunately this won't recognize comments)

Niki
 
M

Mark Broadbent

which is bloody annoying since I seen lots of code samples originating from
them with aforementioned style. Resistance is futile :(

--


Br,
Mark Broadbent
mcdba , mcse+i
=============
 
J

Joe Mayo [C# MVP]

Select Tools, Options to get the Options dialog box. Then select the folder
Text Editor, C#, Formatting. In the Indentation section, make sure "Leave
open braces on same line as construct is checked". It is unchecked by
default.

Joe
 
C

clintonG

Correction: that would be ctrl-] within the VS.NET IDE.


--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
URL http://www.metromilwaukee.com/clintongallagher/

in message
I have adopted the code block style myself which should not be
attributed to Java developers per se but rather to all developers having
learned to write clear and readable code from their C and C++
predecessors.

In any event, for those who prefer sloppy coding formats they should
know they will need to learn and use ctrl-[ brace matching more
frequently as they and others try to read and make sense of their code.

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
URL http://www.metromilwaukee.com/clintongallagher/



Simon said:
I prefer it that way. It looks a lot tidier in my view and with indenting
code blocks are very easily distinguished.
I don't really see the point of putting them there - It just takes
up
more
paper when you come to print the stuff out!

Of course its just my preference though

Simon
 
M

Mark Broadbent

thx joe. guess it pays to look :)

--


Br,
Mark Broadbent
mcdba , mcse+i
=============
 
M

Martin Maat

[opening brace on the same line as preceding code]
I prefer it that way. It looks a lot tidier in my view and with indenting
code blocks are very easily distinguished.
I don't really see the point of putting them there - It just takes up more
paper when you come to print the stuff out!

This is becoming a bit of a troll since code formatting preference is almost
a religion but nonetheless I feel my comments really matter so here goes.

Saving paper... It seems this is the one reason for not putting block
delimiters on the same vertical line. For clarity I see only drawbacks. When
was the last time you printed out a code file? This was done when
programmers only had line editors!

It is like one of those things that once had a pupose and just won't die
after the original reason for them vanished. Like underlining text to
emphasise, which was once the only way for type writers to emphasise
anything.

Be it "begin" and "end" or "{" and "}", compound statement delimiters should
be either on separate lines starting in the same column or optionally both
on the same line if the statement enclosed is more trivial than the compound
construct itself.

I feel it is a good thing that Microoft or any other tool vendor sets
standards for things like formatting and naming conventions, ideally they
should be part of the language. We will probably continue to see people use
bMyBooleanVariable and strMyStringVariable for quite a while, which was once
the only way to make the lack of type safety a bit less dangerous. I catch
myself still using prefixes for GUI controls as in tbxAmount where it should
be amountTextBox. Old habits die hard...

Martin.
 

Ask a Question

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.

Ask a Question

Top