Jump to content
  • Advertisement
Sign in to follow this  
RealMarkP

[C++] Code Beautification Tools

This topic is 3156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using Visual Studio 2008 with VisualAssistX. I'm wondering, is there a tool to reformat my code and do things like: - Indent code properly - Move braces around from inline (on an if or for statement) to the next line down - Rename all variables of [type] to always start with a certain prefix (ie. all floats have a 'f' prefix, all chars have a 'ch' prefix) - Add white spaces so code doesn't look all crammed (ie. instead of 'if(var==1)' it would be 'if (var == 1)') Any of these in one or more tools would be great. Plugins for VS2008 are also welcome but not required. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Visual Studio can do all of that but the third (which I think is gross anyway) itself; look in the keyboard settings for what you have bound to "Format Document" and in the text editor settings for C++ for formatting control options.

You could achieve your icky Hungarian notation refactoring with a macro and a regular expression search/replace or tow.

Share this post


Link to post
Share on other sites
Quote:
Rename all variables of [type] to always start with a certain prefix (ie. all floats have a 'f' prefix, all chars have a 'ch' prefix)


This could be dangerous, but if you followed stringent coding conventions where you can seperate variable names from type names (very subtle!), you could use regex replace.

The less dangerous method is to visit each relevant declaration, and do a refactor/rename.

Share this post


Link to post
Share on other sites
Quote:
The less dangerous method is to visit each relevant declaration, and do a refactor/rename.


This is what I've been doing thus far and it's really time consuming.

EDIT:

Quote:
look in the keyboard settings for what you have bound to "Format Document" and in the text editor settings for C++ for formatting control options.

When I use Ctrl-K, Ctrl-D it gives me an error: "(Format Document) is not currenty available"

Share this post


Link to post
Share on other sites
Quote:
Original post by RealMarkP
Quote:
The less dangerous method is to visit each relevant declaration, and do a refactor/rename.


This is what I've been doing thus far and it's really time consuming ...

let me finish that sentence: "... and worth mostly nothing".

Personally, as long as the interface of a class does not need to change, I just keep and stick to the naming conventions used inside that class (this is why I still have the one or another class that uses m_ prefixes, other classes use _ postfixes, and yet other ones don't have special conventions at all). That pretty much conforms to the YAGNI methodology.

Share this post


Link to post
Share on other sites
Quote:
Original post by RealMarkP
Quote:
The less dangerous method is to visit each relevant declaration, and do a refactor/rename.
This is what I've been doing thus far and it's really time consuming.
Let me get this straight, you have a large codebase containing nice, clean code, and you want to convert it all to hungarian notation?

I think you will find that potential coworkers/collaborators will run for the hills. Hungarian notation went out of style a long time ago, and (IMHO) for good reason. [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Quote:
Original post by RealMarkP
Quote:
The less dangerous method is to visit each relevant declaration, and do a refactor/rename.
This is what I've been doing thus far and it's really time consuming.
Let me get this straight, you have a large codebase containing nice, clean code, and you want to convert it all to hungarian notation?

I think you will find that potential coworkers/collaborators will run for the hills. Hungarian notation went out of style a long time ago, and (IMHO) for good reason. [smile]


Now that you mention coworkers: You probably annoy them with a lot of diff-noise and merge-hell.

Share this post


Link to post
Share on other sites
Quote:
Let me get this straight, you have a large codebase containing nice, clean code, and you want to convert it all to hungarian notation?

I have a large codebase of nasty looking code that all members of the team have been (up to this point) trying to clean up. One of the major issues is whitespace. The Hungarian notation thing is an added bonus, but not as critical.

I didn't write the coding standard that we follow, I just merely enforce it.

EDIT: and by 'enforce' I mean 'abide'.

Share this post


Link to post
Share on other sites
If you still can't persuade Visual Studio to format it for you, there's always GNU Indent - http://www.gnu.org/software/indent/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!