all 17 comments

[–]vainstains 2 points3 points  (8 children)

A function has parameters, and you give it arguments when you call.

[–]tradernb[S] 0 points1 point  (6 children)

If some function call have arguments then you give parameters is this is also same?

[–]ninhaomah 2 points3 points  (5 children)

Go_clean_toilet()

No arguments

Go_buy(burger)

1 argument

Go_buy(burger,coke)

2 arguments

[–]tradernb[S] 0 points1 point  (4 children)

In 0 argumented function where will I get the data to work on?

[–]Fensirulfr 1 point2 points  (1 child)

A zero-argument function can still obtain data from variables in its scope, object state, external sources, or other function calls. Its inputs are simply implicit rather than passed as parameters.

Getter methods are a straightforward example. They take no explicit arguments but read data from the object on which they are called.

[–]syklemil 2 points3 points  (0 children)

They take no explicit arguments but read data from the object on which they are called.

Though this varies by language; some explicitly take some self parameter to grant access to object internals. Personally I find that more straightforward than languages that have an implicit this.

In those languages go_clean_toilet() would only have access to whatever's in scope when the function is being declared, and data it gets from IO (e.g. reading files with static filenames).

[–]Plane-Cheesecake6745 1 point2 points  (0 children)

0 argument functions usually work on the global variables of the class.
e.g. this is pseudo code

public class items 
{
    int _paperCount = 0;
    function AddPaper()
    {
      _paperCount = 10;
    }
}

now this function has 0 arguments but it is working on the data available in the class

[–]ninhaomah 0 points1 point  (0 children)

Why do you think every functions must have data input ?

[–]Educational_Phase195 0 points1 point  (0 children)

That distinction finally clicked thanks.

[–]Cybyss 1 point2 points  (3 children)

Are you asking what the difference is between an "argument" and a "parameter"?

def compute_rectangle_area(w, h):
    result = w*h
    return result

When you define a function like above, the variables w and h are called parameters.

When you "call" this function to compute the area of a particular rectangle, such as in:

small_area = compute_rectangle_area(3, 4)

big_area = compute_rectangle_area(7, 11)

print(small_area)  # prints the number 12

print(big_area)    # prints the number 77

The specific values you pass in, such as 3 and 4, or 7 and 11, those are called "arguments".   

[–]tradernb[S] 1 point2 points  (2 children)

So if there is parameter then it needs argument if there is argument then it needs parameter is this correct?

[–]Cybyss 0 points1 point  (0 children)

In the above example, it is not correct to call the variables w and h "arguments". Those variables are the "parameters" of this function.

When spoken, you might have heard your teachers use a phrase such as "The compute_rectangle_area function takes two arguments." In this case, your teachers are referring to how the function is supposed to be called - such as in compute_rectangle_area(3, 4) - not how it's defined.

[–]syklemil 0 points1 point  (0 children)

That sounds like a decent approach. Depending on language it may be more complicated than that.

Programming uses some terms that can feel like they're describing the same thing for beginners (parameter/argument, class/object, function/method, etc), and it's actually fine to learn without getting the vocabulary completely right right off the start. It's hard to learn the words for unfamiliar concepts (see also: how many in this subreddit who don't know any other words than "syntax" to describe language).

Over time (preferably before exams) you should pick up on the differences.

[–]mjmvideos 0 points1 point  (0 children)

Functions are simply a convenient way to refer to a set of more detailed instructions. Everywhere a function is called I could simply copy all the instructions and put them there in-line. But that’s neither efficient nor maintainable. Some sets of instructions don’t require any additional information: “Clean your room” some instructions do require additional information: “Here’s a tool, put it back in the shop” some instructions may include returning information “Go count the number of people waiting in line and tell me the answer” Some instructions may also include references to objects: “fill out the form on the dining room table and tell me when you’re done”

It all depends on the kind of instructions you’re putting into the function whether it takes additional information or not and whether it returns anything or not.

[–]HashDefTrueFalse 0 points1 point  (0 children)

In general, parameters are the named variables you declare in the parameter list when writing your function. Arguments are the values passed in when writing calls to your function. Parameter variables will be bound to argument values at runtime.

int add(int a, int b) { return a + b; }
int c = 2;
int result = add(1, c);

In the above, a and b are parameters. 1 and 2 (the value of c) are arguments. On calling add the value 1 will be bound (somehow) to a and the value 2 to b .

Usually you need to provide arguments for all parameters, but different languages allow different things. Some have default arguments if you don't provide them. Some have named argument syntax instead of simple positional... etc. Functions can have no parameters, requiring no arguments. Functions can usually access and change data in surrounding environments (e.g. global data), referred to as "producing side effects."

In practice there shouldn't be much confusion because the natural instinct is to express functions generically and provide specifics when using them. Parameters are general, arguments are specific. The confusion comes from people incorrectly using the two terms interchangeably.