Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 7th, 2006, 3:07 PM   #1
Eoin
Hobbyist Programmer
 
Eoin's Avatar
 
Join Date: Jun 2006
Location: Ireland
Posts: 152
Rep Power: 3 Eoin is on a distinguished road
Commenting out parameter names in function parameter list?

Here's an example of some WTL code;
cpp Syntax (Toggle Plain Text)
  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.
__________________
Visit my website BinaryNotions.
Eoin is offline   Reply With Quote
Old Aug 7th, 2006, 4:17 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 7th, 2006, 9:04 PM   #3
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
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.
The Dark is offline   Reply With Quote
Old Aug 7th, 2006, 10:32 PM   #4
Twilight
Programmer
 
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3 Twilight is on a distinguished road
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.
Twilight is offline   Reply With Quote
Old Aug 7th, 2006, 10:35 PM   #5
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
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.
The Dark is offline   Reply With Quote
Old Aug 8th, 2006, 3:14 AM   #6
Eoin
Hobbyist Programmer
 
Eoin's Avatar
 
Join Date: Jun 2006
Location: Ireland
Posts: 152
Rep Power: 3 Eoin is on a distinguished road
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.
__________________
Visit my website BinaryNotions.
Eoin is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
dev c++ software, template problem cairo C++ 11 Jun 2nd, 2006 12:42 PM
libraries matko C 1 Jan 22nd, 2006 2:12 PM
Jackpot game zorin Visual Basic 3 Jun 10th, 2005 1:19 PM
User-defined creatNode and deleteNode functions for a doubly-linked list jgs C 2 Apr 28th, 2005 8:53 AM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:47 PM.

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