I use QtCreator for my C++ development IDE. It is very good. But it doesn’t always lay out my C++ code the way I want it to. In particular the refactoring operations mess up my white space. I want my code to look like:
void foo( int* x, int& y )
But it keeps changing it to:
void foo(int *x, int &y)
Grrrrrr.
So I am constantly battling with QtCreator to layout my code how I like it. There are plenty of C++ pretty printers around. I played with some of the leading ones using UniversalIndentGUI, but I couldn’t get any of them to layout my code quite how I wanted. Maybe they could have done it, but I got fed up with fiddling with the settings.
What I need is a code pretty printer that I can configure to layout my code exactly how I want without me having to tweak 100 settings.
Ideally I want a code pretty printer that I can train. So I just point it at a few files of my code that are laid out how I want and it works out all my preferences (where to put braces, how to indent case statements, where to put the * for a pointer declaration etc) and can then apply them to any other code. It wouldn’t need a GUI. Or perhaps just enough to select the training files and then preview the results on other files.
I have no idea if this is a viable product idea. But I would pay $100 for it, if it worked well. Perhaps bigger software companies would pay a lot more? Or maybe something like this already exists and I just don’t know about it?
QtCreator is right. No space after open paren and before close paren. :-P
But if you want a code pretty printer that you can train, consider Emacs. No need to pay for it even $1. :-)
Adding to the above:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Program-Indent.html
And if Emacs Lisp is too cumbersome for you, you may want to look at this SO search:
http://stackoverflow.com/search?q=%5Bc%2B%2B%5D+beautifier
Good luck!
I’m not good at remember keystroke combinations, so Emacs definitely isn’t the tool for me.
1+ for Software Candy. Your code is an abomination – at least it’s rather ugly :-).
I might think the same about your code!
AStyle can add those extra spaces and attach *’s and &’s to the typename. http://astyle.sourceforge.net/
If so, maybe someone could write a front-end to AStyle that reads a code sample and configures AStyle?
How about Code::Blocks, http://codeblocks.org/ ?
I like the idea of a trainable tool, having also struggled unsuccessfully to get QtCreator to do it The One True Way (i.e. *my* way), so I currently have to fight it for every brace.
Funny how we all have such strong (and different) views. It my case, I’m still using the house-style of the first company I worked for, which I left nearly 20 years ago. Pug ugly to anyone but me and anyone else who used to work there. Banner indents, especially:
int DoSomething(int *iPtr, char *szString) {
if (*iPtr == 1) {
// Do something
} // End ‘if’
} // End ‘DoSomething()’
…and even worse when not formatted at all, as per the above… [twitch, twitch]
I think wordpress has probably messed up the formatting.
Oh the irony! In an earlier article about being a “Lifestyle programmer” you said one of the advantages was that “No-one can tell me where to put my curly braces ….”
But it appears that one can never escape code-format wars …. even if it’s just with the IDE!
Thankfully QtCreator doesn’t move my braces around. That would be more than I can bear!