Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Naming Function Parameters

Author
Message
AncientGamer
14
Years of Service
User Offline
Joined: 10th Jan 2010
Location: United States
Posted: 28th Oct 2013 02:27
Hey everyone! I wasn't sure about this so I thought I would put it on the forum. When passing a parameter to a function, if what you are passing is a variable is it okay to name it the same thing as the parameter in the function, such as passing number(size) to FUNCTION number(size). See how the variables are the same name? I tested it and it works, but wanted to make sure this wasn't taboo or something. Thanks!
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 28th Oct 2013 05:31
Absolutely, nothing wrong with doing that.
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 28th Oct 2013 08:36 Edited at: 28th Oct 2013 08:36
That should work; the function will use its local version (the parameter) when you refer to size in it. This holds true even if you have a global variable named size.


"Why do programmers get Halloween and Christmas mixed up?"
AncientGamer
14
Years of Service
User Offline
Joined: 10th Jan 2010
Location: United States
Posted: 28th Oct 2013 20:17
Thanks for answering my question, it is appreciated.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 11th Nov 2013 01:31
It's fine, but ideally function parameters have abstract, generic names (since functions are for generic purposes), whilst common variables have more descriptive, context-specific names.


Formerly OBese87.

Login to post a reply

Server time is: 2024-04-20 12:25:01
Your offset time is: 2024-04-20 12:25:01