TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Parameter or Argument?

55 点作者 nebucnaut将近 9 年前

17 条评论

jdeisenberg将近 9 年前
Using the terms in a consistent manner can avoid confusion. I tell beginning programming students that a Parameter is like a "Placeholder," and the Argument is the "Actual" value that fills it in, emphasizing the first letters of each.
dahart将近 9 年前
It&#x27;s nice to know this distinction when you&#x27;re working with other people who expect this distinction to be followed.<p>Personally, I prefer the softer explanation in Wikipedia that begins, &quot;The terms parameter and argument are sometimes used interchangeably, and the context is used to distinguish the meaning.&quot;<p><a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Parameter_(computer_programming)#Parameters_and_arguments" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Parameter_(computer_programm...</a>
more_original将近 9 年前
One also finds the terms &quot;formal parameter&quot; (for what is called a &quot;parameter&quot; in the article) and &quot;actual parameter&quot; (for what is called the &quot;argument&quot; in the article).<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Parameter_(computer_programming)#Parameters_and_arguments" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Parameter_(computer_programmin...</a>
mistermann将近 9 年前
Could someone offer a good explanation as to why it matters in this specific case? I can&#x27;t think of any way in which a lack of knowledge of the &quot;correct&quot; term could lead to something being done incorrectly.
评论 #12093631 未加载
评论 #12094256 未加载
collyw将近 9 年前
Does it really matter? This is the sort of thing that I would expect to come up in some pedants interview question - it has very little with being able to use the features effectively.
评论 #12093324 未加载
评论 #12093738 未加载
评论 #12093299 未加载
评论 #12093617 未加载
评论 #12093323 未加载
sinatra将近 9 年前
One easy way to remember which is which: Recall the term &quot;command line arguments.&quot; That will remind you that arguments are what&#x27;s passed to the function. So, parameters are what&#x27;s declared&#x2F;defined in the function.
dzdt将近 9 年前
Is there pretty universal agreement on this? I&#x27;ve been around a while but still have the &quot;meh, the words are interchangeable&quot; view.
评论 #12093751 未加载
评论 #12094126 未加载
flipp3r将近 9 年前
&quot;A Parameter is a variable in the signature of a function declaration or definition:&quot;<p>int main (int argc, char <i></i>argv)<p>public static void main(String[] args)<p>static void Main(string[] args)<p>sys.argv<p>Wait a minute...
评论 #12094170 未加载
评论 #12094248 未加载
ajarmst将近 9 年前
This, like basically all terminology&#x2F;jargon distinctions, will be community-specific. This particular distinction is idiomatic primarily in the C family (C, C++, Java, ad n.), primarily inheriting from the declaration&#x2F;definition distinction in the ancestral language. But jargon has dialects---some people will have seen declaration&#x2F;definition above and now be itching to correct me with &#x27;prototype&#x2F;implementation&#x27;. In other development communities (say, lispers), the terms may be different, the distinction may not exist or a different one might take priority (like, say, car&#x2F;cdr). As others have said, what matters is clarity of communication, and part of that is always learning the idiom and norms of your community. Note: in many cases there might be a published standard (eg. K&amp;R C, or Academie Francais French), which can inform usage, but not necessarily prescribe it.
zeveb将近 9 年前
Then there&#x27;s Common Lisp, where a variable is assigned only the first time it&#x27;s defined, while a parameter is assigned every time its definition form is evaluated: <a href="http:&#x2F;&#x2F;clhs.lisp.se&#x2F;Body&#x2F;m_defpar.htm" rel="nofollow">http:&#x2F;&#x2F;clhs.lisp.se&#x2F;Body&#x2F;m_defpar.htm</a>.
评论 #12094514 未加载
Bromskloss将近 9 年前
I have never heard about the distinction anywhere in mathematics. Is this specific to programming?
评论 #12094194 未加载
makecheck将近 9 年前
I’ve also seen and used terms like “option” for command-line values, or “bare argument” for values that are not tied to anything in particular. And in code, if the documentation uses hooks like &quot;@param&quot; then people will naturally think of those as parameters. You can also refer to individual fields of a data structure as “parameters” even if they are passed to a function as one value (and I have never seen people refer to fields as “arguments” in that situation).<p>In the end, I don’t think any term is used consistently enough. People will use whichever words they want, and you have to treat them all as potentially referring to the same thing.
tempodox将近 9 年前
I like to phrase it like this: “A parameter is a local variable that&#x27;s initialized by passing an argument”. That works for functions and C++ templates. It also works in languages like ML, where you can initialize multiple parameters from a single argument (via pattern matching).<p>Consequently, speaking of “passing a parameter” is dead wrong most of the time, except maybe when you&#x27;re writing a function that “defines” other functions, where a parameter of the function to be defined is an argument of the definer function. But I will stop here before it gets complicated.
js8将近 9 年前
Does that really correspond to usage in mathematics? I think that can be where the confusion comes from.<p>Let&#x27;s say: &quot;Here we define a function f(x,y) of two arguments x and y..&quot;
dandare将近 9 年前
Wait, don&#x27;t we have an <i>arguments</i> object in JavaScript that [&quot;is an Array-like object corresponding to the arguments passed to a function.&quot;](<a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Functions&#x2F;arguments" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Referen...</a>)
评论 #12094101 未加载
aethos将近 9 年前
While this is true, be aware that parameter and argument are commonly used interchangeably.
uitgewis将近 9 年前
It takes an argument and you pass it a parameter.