Saturday, November 03, 2012

Prettyprinting C++ code

After all these decades, there is still I need for prettyprinters. I am in shock. I was spoilt in java-land, where eclipse takes care of this for you. In C++ it's a different story.

I have to say that these days most C++ is formatted OK. Enough years have gone by that most people recognise that making the source readable to humans is important enough for it to be worth that little bit of extra effort. Sadly, not everyone is enlightened so poorly formatted C++ code is still being written today. C++ IDEs that take care of this issue are not universally used. IDEs themselves are still a bit of an issue since there is no multi-platform IDE that most C++ people can agree on. Eclipse CDT isn't there yet and in my opinion is several years away. So the question is, what to do?

I have given up on GNU indent. It was meant for C anyway rather than C++ so it can easily get confused and do the wrong thing when presented with C++. The GNU project had an appeal a few years ago for a new maintainer, but no-one stepped up to the plate. The project languishes in obscurity now. However, there is a new program called astyle, which stands for Artistic Style. I have been using this recently and find it to be OK; not brilliant but OK. So this is what I will use for now. I think it could do with some of the options/features that GNU indent has but beggars can't be choosers.

A while ago, when I was still in java-land, I thought that the eclipse formatter plugin might be used. It certainly works very well for java. There is a blog entry about this that discusses running the eclipse plugin from the command line for C++ code.

No comments: