Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Commenting out parameter names in function parameter list? (http://www.programmingforums.org/showthread.php?t=10983)

Eoin Aug 7th, 2006 4:07 PM

Commenting out parameter names in function parameter list?
 
Here's an example of some WTL code;
:

  1. LRESULT MainDialog::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/,
  2.         LPARAM /*lParam*/, BOOL& /*bHandled*/)
  3. {}


Notice that the parameter names are commented out. I am sure I came across an explanation of why this is a good thing to do but can't for the life of me remember what it was or where I heard it. Anyone know why this is done and is it good practice? WTL code (from codeproject at least) is full of this.

DaWei Aug 7th, 2006 5:17 PM

The prototype only requires the types. One wouldn't want to suggest that you have to use specific names, but the commented names are suggestive of the purpose of the argument. It's exemplar. You should use names (despite the fact that they aren't required) that provide useful commentary in your particular application.

The Dark Aug 7th, 2006 10:04 PM

I think also if you comment out the parameter name, the compiler won't complain that the parameter is unused. In this example, nothing is used, so they are all commented out. Mind you the compiler should still be complaining about not returning a valid return value.

Twilight Aug 7th, 2006 11:32 PM

The parameter is used plenty Dark, it's just that the compiler doesn't care about the name of the variable at that point. You can write:

:

LRESULT MainDialog::OnInitDialog(UINT, WPARAM ,LPARAM, BOOL&)
{}


And the thing will still run fine. The commented out names just suggest the purpose to the programmer before it looks through all the code. When you do the actual function definition, all the variables will still need names so that you can access them.

The Dark Aug 7th, 2006 11:35 PM

Quote:

Originally Posted by Twilight
The parameter is used plenty Dark, it's just that the compiler doesn't care about the name of the variable at that point. You can write:

:

LRESULT MainDialog::OnInitDialog(UINT, WPARAM ,LPARAM, BOOL&)
{}


And the thing will still run fine. The commented out names just suggest the purpose to the programmer before it looks through all the code. When you do the actual function definition, all the variables will still need names so that you can access them.

Really? Can you point to the place in the code you just posted where any of those parameters are used? Here's a hint - {} doesn't contain much code.

Eoin Aug 8th, 2006 4:14 AM

Quote:

Originally Posted by The Dark
I think also if you comment out the parameter name, the compiler won't complain that the parameter is unused.

That rings a bell, I think that was the reason I heard of originally, thanks :) . Oh and my bad for leaving out the return statement, I was removing the body of the function to avoid confuing things but should have left the return in.

Thanks all for your replies.


All times are GMT -5. The time now is 12:17 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC