Results 1 to 5 of 5

Thread: function prototype variable declaration

  1. #1
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default function prototype variable declaration

    When declaring a function, do you put the variable name ?

    Qt Code:
    1. void somefunction(int &, double, int);
    2.  
    3. or
    4.  
    5. void somefunction(int &a, double x, int b);
    To copy to clipboard, switch view to plain text mode 
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: function prototype variable declaration

    I do, because then I can better see for what the parameters are without having to look in the sources. So in your case I would use non of your, but
    Qt Code:
    1. void somefunction(int &currentSpeed, double acceleration, int distanceInMeters);
    To copy to clipboard, switch view to plain text mode 
    ... or something like that.

  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: function prototype variable declaration

    I prefer the name too, and another argument for that is the auto-complete (with tool-tips) that many IDE's have, offers a big advantage for you or others when you use that function, the tool tips have meaning not just type.
    See attached picture... params.jpg

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: function prototype variable declaration

    I use Visual Studio, so it makes it a lot easier if you do use the variable name. That way you can just fill in the class declaration in the .h file and empty methods are created automatically in the .cpp file. If I'm not using VS, then I typically copy and paste, so having the names helps there also.

    Like other people have said, it also helps with parameter completion.

  5. #5
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: function prototype variable declaration

    Thanks for sharing your opinions guys. Always nice to see how other people work.
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

Similar Threads

  1. static building qt, error: declaration of c function conflicts
    By BlueWizard in forum Installation and Deployment
    Replies: 4
    Last Post: 30th July 2010, 12:50
  2. Replies: 22
    Last Post: 8th October 2008, 13:54
  3. static declaration
    By jhearon in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2008, 21:37
  4. call variable from other function
    By walito in forum Newbie
    Replies: 7
    Last Post: 31st August 2007, 18:36
  5. Declaration not working
    By kenny_isles in forum Newbie
    Replies: 1
    Last Post: 1st March 2007, 10:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.