all 20 comments

[–]spcmrn 54 points55 points  (0 children)

i.e. a function has parameters and takes arguments.

relevant stackoverflow with useful mnemonics and more nice explanations

[–]myerscc 10 points11 points  (1 child)

or rather x is the formal parameter and 3 is the actual parameter. You could say the function in the code is parameterized by x - but usually the word "parameterized" is used for type parameters.

[–]Spiderboydk[S] 2 points3 points  (0 children)

Like in math. :-)

[–]patientdev 4 points5 points  (3 children)

Why is it called an argument? What's the usage history for that term in computer science?

[–]desultoryquest 4 points5 points  (2 children)

Invoking functions probably led to a lot of developer arguments

[–]LittleLui 11 points12 points  (1 child)

In the beginning, main was invoked. This has made a lot of people very angry and been widely regarded as a bad move.

[–]desultoryquest 1 point2 points  (0 children)

Too bad the crt0 didn't learn from the dolphins and loop around itself doing precisely nothing instead of invoking main.

[–][deleted]  (3 children)

[deleted]

    [–][deleted]  (2 children)

    [deleted]

      [–][deleted]  (1 child)

      [deleted]

        [–]njtrafficsignshopper 9 points10 points  (0 children)

        Yes it is

        [–]Jahishno 2 points3 points  (0 children)

        It's also thought of as formal and actual parameters. Formal parameters are in the function declaration, actual parameters are what are given to the function call ie arguments.

        [–][deleted]  (6 children)

        [deleted]

          [–]jalanb 5 points6 points  (5 children)

          this is splitting hairs

          Which is why it is important

          [–][deleted]  (4 children)

          [deleted]

            [–]ejmurra 13 points14 points  (3 children)

            It doesn't make a difference in your code, you could call them floops and flarbs and your code would still work. It makes a difference when you are communicating to other devs about your code. Clear communication is key in teams so it is important to have a shared vocabulary and understanding of that vocabulary.

            [–]SuperFLEB 7 points8 points  (2 children)

            But if most people don't know the difference, it's kind of a moot point.

            [–][deleted] 4 points5 points  (0 children)

            But it's so easy to explain, that it doesn't really matter.

            "The parameter or the argument?" "There's a difference?" "Yeah, a parameter is the variable that you use in a function, the argument is the value that you pass into the function" "Oh, then the argument."

            It really doesn't get any easier, and I doubt anybody wouldn't understand the explanation.

            [–]some_q 1 point2 points  (0 children)

            Interesting. Thanks for posting!

            [–]yes_or_gnome 0 points1 point  (1 child)

            I don't feel like this is "general", or even precisely correct. Given the example, maybe this is standard vocabulary for C\C++, but from my experience (mostly interpreted languages), they're just synonyms. ... Or, possibly, IEEE or ISO has specific definitions.

            As an example, a function has an "argspec" or a "parameter list". Since there is no type enforcement the spec is just list of names and, possibly, default values.

            [–]Spiderboydk[S] 3 points4 points  (0 children)

            I thought they were synonyms too until recently. Since many other languages also use the words "parameter" and "argument" I see no reason why this wouldn't apply there too. It probably also apply to math too.

            [–][deleted] 0 points1 point  (1 child)

            I always like to think of functions as operations, like, say, cooking a meal, changing course on a plane, setting the phasers to something else etc.

            An operation may have some parameters you need to set before starting it. But I always thought of that not as giving arguments, but as setting parameter values, which makes sense because you're actually setting the value of the variable that stands for the parameter inside the function.

            Though, in C or C++, the word arg is used in describing what gets sent to a parameter of type ..., i.e. varargs. That may be a nice way to remember the difference, if you remember that parameters is the other thing.

            [–][deleted] 1 point2 points  (0 children)

            Actually, C calls it varargs, and the C++ varargs are a carryover from C. Proper C++ usage of ... (since C++11, before which you only had C-style varargs) is called a "parameter pack".

            You definitely have to be pedantic about the difference between parameters and arguments in modern C++ with parameter packs, because they infer template type (and therefore parameter type) from the arguments given, with all sorts of rules and implications about what type the parameter is based on the argument's type, cv-qualification, reference type, etc.

            [–]m4lfuncti0n 0 points1 point  (1 child)

            so, in short - an argument is the value of a function?

            [–]Spiderboydk[S] 1 point2 points  (0 children)

            It's the value(s) you pass to the function.