Click here to Skip to main content
15,035,508 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
See more:
Hi All,

Does anybody have idea about source code which would generate a Comment block for each and every function and data memeber in CPP/Header and JAVA files?

I would really appereciate a quick help. It would be great if the code is a batch file

Thanking you in advance.
Updated 4-Mar-21 2:26am
Nagy Vilmos 11-May-11 4:26am
Moved answer to here.

Doxy Comment is an add-ons for VS
May be this will help you.
NewBie in Coding 10-May-11 2:58am
Hi ShilpiP,

Thank you for your answer, but actually I would like to add comment blocks added not through visual studio, the entire process should be in batch mode. besides I want to add comment block for Java files also.
Is it possible through DoxyComments?
Stefan_Lang 11-May-11 5:24am
It is a very bad idea to create comments in batch mode. All it does is interpret the information that is already there, and then convert it into some other form. All this achieves is increasing the size of the files, and giving the false impression the code is commented well - when in truth nothing has really been commented.
Stefan_Lang 11-May-11 5:05am
I don't know if this toll or any other would let you do this in batch mode, but neither do I think that would be a good idea to start with. Just adding auto-generated comment lines does not really comment your code! If you comment a function you should at least hint at the assumed preconditions and expected post conditions, give valid ranges for parameter values, list possible causes for failure and exceptions, and describe the meaning of certain output values. None of that can be done automatically. You can only comment what is already obvious from looking at the function declaration. And there is no value in that, except as a starting point to fill in the sort of information I outlined above.

[edit]sorry, this should have been in reply to NewBie, not to you[/edit]
If you use Eclipse for java coding, you'll have always the option of adding auto comments by default. Check your preference settings for this. Also the dialogs always provide the option of "adding auto comments".

Adding comments later is a not so good option - you will not do it or just do it because you're forced to do it. But those comments will never be that good as if you've written them directly.

I think you should consider how much work it would require to write a batch file which would autocomment source files in a reasonable fashion... I assume you would need complex comments including each parameter - if so, what you are requesting is closer to a compiler than a simple script (a small exaggeration, but some serious parsing would definitely be involved :)
My advice is to use the solutions provided by TorstenH and ShilpiP.
NewBie in Coding 11-May-11 4:29am
Thank you for your comments,

I have started using eclipse for java development and would consider adding comment as serious affair in future.

Agreed its a complex thing but unluckily, I'm in situation where I need it.

I know its tough job having batch file return, but I have some java file and few CPP/H files in my solution set.
I missed adding comment block ahead of all functions/data members.

Even if it is not complete(exact arguments type and number) atleast I wish to have block comment ahead of each method to start with.

How about reading a text file containing template comment blocks and code just adding them in front of methods/data members.
Stefan_Lang 11-May-11 5:30am
Again, there is no point to auto-create comments and leave them as is. If they are meant as a starting point, create them one at a time, and immediately fill them with meaningful text. If you do not do it that way, you will never get around to complete the auto-comments later. Even worse, you will later never even notice how many functions you failed to comment properly.
NewBie in Coding 11-May-11 6:15am
I guess many ppl suggested many things I agree with all us suggested and that ist better to comment when code is written etc.

My question still is unanswered, does any body have any standalone functionality that adds comment comment in C++ and Java file???
As others have stated, it is going to be better to comment as you go.
If you need t add them post-coding then it is better to go in, look at the method and add a comment.
Netbeans and Eclipse can both be set to add a tempate method comment with the names of parameters and return added for you in the correct syntax.

I'd also read this[^]
TorstenH. 11-May-11 7:08am
*lol* I'd suggest this one:
Make bad code good @[^]
Nagy Vilmos 11-May-11 7:26am
Dem's good ideas!
NewBie in Coding 12-May-11 5:39am
Well All,
Thank you for your inputs ... I have got good responses but no solution. and as I depart from this thread with no solution, I will surely share code that I write after it is working for me on same thread. Adieu!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900