method commenting

This is a discussion on method commenting within the C++ Programming forums, part of the General Programming Boards category; Hi,i got a method Code: void searchStaff(string staffID){ } I want to write a comment on top to describe the ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    58

    method commenting

    Hi,i got a method

    Code:
    void searchStaff(string staffID){
    }
    I want to write a comment on top to describe the method.

    i did this:

    Code:
    /*searchStaff(string staffID) function searches a staff.
    @staffID is id of staff to be found*/
    
    void searchStaff(string staffID){
    }
    is this correct way to specific wat the method parameter is for?

  2. #2
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    I suppose your double-post is a mistake. Maybe make the comment cleaner and separate explanation, arguments and the function name. Such as:

    Code:
    /* void searchStaff(std::string staffID): Search staff with ID staffID
       Parameters:
           - staffID: The ID of the staff to be found
    
    ... long explanation here */
    Actually, everything is a matter of personal preference. That was just an example.

    PS: Are you working with global variables? Because search functions normally do return a value.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    139
    Code:
    /****************************************************************************
     *
     * NAME:  Enable_Device(arguments)
     *
     * DESCRIPTION:
     *          Data message processor callback.  This function processes
     *          any incoming data - probably from other devices.  So, based
     *          on cluster ID, perform the intended action.
     *
     *  Param: pkt - incoming message
     *
     *
     * RETURNS:
     *         none
     *
     ****************************************************************************/

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,630
    *Moved to C++ programming forum*

    Quote Originally Posted by rahulsk1947
    I want to write a comment on top to describe the method.
    One approach is to document the pre-conditions and post-conditions of the function.

    Quote Originally Posted by rahulsk1947
    is this correct way to specific wat the method parameter is for?
    If you are using a documentation generation tool that recognises @staffID then yes, that is probably what you can do. On the other hand, the name is reasonably descriptive, so restating the parameter name in a comment does not really add information.

    Aside from Brafil's observation, I note that you most likely should be passing the std::string by const reference.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    Consider making whatever style you go for compatible with say Doxygen
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. on method pointers and inheritance
    By BrownB in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2009, 06:50 PM
  2. stuck on display method
    By shintaro in forum C++ Programming
    Replies: 2
    Last Post: 02-01-2009, 04:17 PM
  3. Best communication method to thousand childs?
    By Ironic in forum C Programming
    Replies: 8
    Last Post: 11-07-2008, 11:30 PM
  4. C# method
    By siten0308 in forum C# Programming
    Replies: 6
    Last Post: 07-15-2008, 07:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21