I'm working on some C# code. It's not as readable as it could be because of the formatting used.

Is anyone aware of any good code beautifiers that work well and adheres to industry standards? Interested in free ones too - if available

Visual Studio works great once you set the formatting parameters how you like them. Just delete the closing } in any file and retype it and it will reformat the file.

And there is no industry standard. There are two conventions that are the most popular

1: Brace on following line (sucks)

if (something == true)
{

2: Brace on same line (best)

if (something == true) {

Of course those are my opinions on which to prefer (but at least mine has studies backing it up saying it is more readable, so there!).

I prefer the first option - that way I can quickly work identify blocks of code, i.e. the end of an if block.

The code I have looks something like this:-

if (line.StartsWith("\"")) {
          line = line.Trim('\"');
          fields = LoaderSupport.ExtractStrings(line, "\",\"");
          return parseComma(fields, line);
        }
        else {
          line = line.Replace("  ", " - ");
          
          //"" around the message
          int one = line.IndexOf(" *");
          int two = 0;
          if (one > -1){            
            char s = line[line.Length-1];
            if (!(s > 57 || s < 48)){ two = line.LastIndexOf(" ", line.LastIndexOf(" ")-1); }
            else { two = line.LastIndexOf(" "); }

            if (two > -1){

Somebody has advised me on MSDN that Goto Edit=> Advanced=>Format Document will format the file - and the format takes option a) which I also happen to prefer. I'd be interested in seeing these studies !

Thanks for your help

1: Brace on following line (sucks)

Don't agree, code with brace on next line makes everting much clearer for me.:|
I know it is the style also used in the K&R book, and in the past I hapened to use alot of BEGIN and ENDs:D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.