I am aware of a similar question for C#. I downloaded and tried NArrange and UniversalIndentGUI but both do not sort functions of C++ code per name. Does anyone know a non-commercial tool that does this job?
-
3Out of interest: Why do you want to do this? Usually, you want to have related functions together, not functions whose names happen to be similar.– Oliver CharlesworthNov 9, 2011 at 10:44
-
2I have to deal with code which I want to structure better. Related functions are all in the same file and those shall be sorted alphabetically.– Michael S.Nov 9, 2011 at 11:17
-
@OliverCharlesworth Another reason to do this: I have some python code that generates C++ headers based on some protocol reference information... I want to diff an old generated C++ header with one generated now off the new protocol reference, but there's probably an extra message or two - and/or a difference in the way the python interpreter I'm using this time hashes or chooses bucket counts, such that iteration to print the functions now produces a different pseudo-random ordering. If I could sort new and old generated headers, I could get a nice clean diff.– Tony DelroyDec 27, 2022 at 2:02
1 Answer
Unless you're under orders to rearrange the code to conform to an arbitrary coding standard, my advice is do not do this. I've seen people do it before, and the results are not pretty. The file will look completely different after you're done, and you'll have effectively trashed all of the edit history in source control. Any diffs between this version and any version that came before it will look like a jumbled mess. In the long run, having a clear diff history is worth more to you and your team than some measure of code cleanliness.
-
4
-
And so I am "under orders to rearrange the code to conform to an arbitrary coding standard" how do I do this? (This is the actual case, not just hypothetical)– ValityMar 8, 2017 at 22:07