Using Visual Studio as a code formatter

Hi all
This is not a question, but rather like a answer to my question.

I have a large program, for me atleast. It has many nested IFs and other blocks. I got more and more confused where blocks ended. Indenting code helps, but sloppy indenting does not. And commenting blocks with { makes this even more difficult. So, I tried to copy paste all code to Visual studio 2008 C++ file. And back to Arduino IDE.

In Visual Studio there is in edit/advanced menu, some interesting choices. Somehow I managed to get my code properly indented. (Start with "select all".) I'll check it better next time I need it.

Now my code is easier to follow in Arduino IDE too.

Have you any comments. Better ways to do this.

Well at least I hope this helps some one.

...any comments...

Ummm...

See http://www.arduino.cc/en/Guide/Environment. Scroll down to Tools and see Auto Format.

Or...

In your Arduino IDE on the Tools dropdown menu, click on Auto Format. It will tell you about mismatched brackets (among other things) and (maybe) that will make it easier for you to spot certain kinds of block errors.

I personally don't like everything about it, but it does tend to make indentation more consistent. For anything other than trivial test programs, I (usually) use an external editor (gvim on Linux) that does autoindent in a customizable way. (For example: When I print out programs, I like blocks to be indented four spaces, not two, which Arduino gives.) For a lot (a lot)more formatting options. I use the GNU indent utility program.. It "comes with the territory" on my Linux distributions, and I always install GNU compilers and lots of Linux-like utilities with Cygwin on my Windows XP workstations.

Regards,

Dave

Good to hear about auto format. After a quick look I like more heavily indented code.

I like more heavily indented code.

As I mentioned, I do too.

There are lots of things (beyond block indentation widths and bracket-matching) about any IDE editors that I have ever used that limit my productivity. (I don't particularly like the Visual Studio editor either. In fact I usually do my "real" work on Linux, so I'm kind of glad that I didn't fall in love with Microsoft stuff.).

I mean, I'm not trying to talk you into using the Arduino IDE editor, and, in fact there are other things about it that I'm not really fond of, but you did ask.

Anyhow...

Now, I like block indentations of four spaces instead of two, so I went into the Arduino preferences.txt file and changed

editor.tabs.size=2

to

editor.tabs.size=4

Now autoformat blocks it out more to my liking. Note that, since there is a already a line that makes editor.expand.tabs=true, it uses spaces instead of tabs, which is an absolute, non-negotiable requirement for my documentation purposes, regardless of the number of spaces the blocks are indented.

There are other personalizaitons possible that don't show up on the IDE menu but can be changed by settings in preferences.txt

Etc., etc.

Regards,

Dave

My friends preach about "SQL WINDOWS" 20-30 years ago, which was better then than what VS is now. But that's an other story. And VS is here now but SQL W isn't.

Thanks for the tips by the way.

Lots of code formatters out there.

Try Astyle. http://astyle.sourceforge.net/