Re: Function prototype vs implementation mismatch in C++

From: jeffc (nobody_at_nowhere.com)
Date: 05/17/04

  • Next message: Jerry Coffin: "Re: Choice of smart compiler"
    Date: Mon, 17 May 2004 14:55:05 -0400
    
    

    "News" <NoMail@127.0.0.1> wrote in message
    news:cw8qc.353$Id4.120@newsfe6-gui.server.ntli.net...
    > class test
    > {
    > public:
    > void display(const int x);
    > };
    >
    > void test::display(int num)

    By the way, on a tangent, I found it curious that you named those parms as
    you did - "x" in the declaration, and "num" in the implementation. You
    don't need a name in the declaration. The only purpose for putting one
    there would be to inform the user of the API (header file). Even then, it's
    only to save writing the comment. Theoretically, it's consistent with OO
    philosophy to *not* name the parameter, since that is an implementation
    detail. You could write

    void display(const int); // the number to display
    to save the comment
    void display(const int numToDisplay);

    Then the developer is free to use whatever name is most appropriate. In
    some cases, it could be that one name is appropriate for the user interface
    (to make it easier for callers to understand), and for whatever subtle
    reason a slightly different name might be more appropriate. I can't think
    of any reason to make the more obscure name to be in the header file though
    :-)


  • Next message: Jerry Coffin: "Re: Choice of smart compiler"

    Relevant Pages

    • Re: C Programming
      ... > reason for why it matters. ... There are books around that carefully do not teach bad practice, ... this book doesn't use void main. ... is int mainor int main. ...
      (Fedora)
    • Help in Java swings(internal Frame)
      ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
      (comp.lang.java.programmer)
    • [PATCH] get rid if __cpuinit and __cpuexit
      ... unsigned long action, void *hcpu) ... unsigned int cpu = hcpu; ... -static int __cpuinit ... __cpu_up(unsigned int cpu) ...
      (Linux-Kernel)
    • [PATCH,RFC 2.6.14 09/15] KGDB: SuperH-specific changes
      ... This adds basic support for KGDB on SuperH as well as adding some architecture ... -static int kgdb_uart_getchar ... -static void kgdb_uart_putchar ... * The command-line option can include a serial port specification ...
      (Linux-Kernel)
    • problem in java swings
      ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
      (comp.lang.java.programmer)