01 logo

How Are Parameters & Arguments Different In Functions

Hint: One is a contract and the other data conforming to the contract

By Felix OtooPublished 2 years ago 3 min read
Like
Photo by Oladimeji Ajegbile from Pexels

An image of developer staring at his laptop with a confused facial expression

Photo by Ajegbile from Pexels

How many times have you heard software developers interchangeably use the terms “parameter” and “argument” whiles talking about functions?

Only a few days ago, I had a code review session with a mentee developer who has been in the software development space for just a little over a year. This young fellow is smart, intelligent and his growth mastering the concepts and principles related to programming has been remarkable.

I’m quite jealous of his fast-paced learning experience. I can recall how challenging and frustrating my introduction to software development was then.

Across Skype, I listened and watched him run me through features he’s implemented for an application he's working on. He explained, line by line, his implementations, explaining his thought process and decision-making on the code he has written.

Much of what he had implemented looked alright. But in his presentation though, I noticed him constantly muddle up the two words “parameter” and “argument”. Times I expected him to use “parameter”, it was “argument” and vice versa.

He made statements like

“I have a function A with arguments A1 and A2”

“I called the function A passing the parameters A1, and A2”

As much as I was concerned, it didn't entirely surprise me because even developers who have years of software development under their belt are plagued by the same confusion of these two programming terms.

For the benefit of my mentee and hopefully yours as well, in the rest of this article, I will explain the differences between the two terms “Parameter” and “Argument” in functions.

What is a function parameter?

A function parameter is part of a function signature. In another article, I expound on what a function signature is. Check that article for information about functions noob programmers must know.

Function parameters define the inputs and nature of inputs of a function. They define a contract for what a function accepts as inputs. Parameters also describe the arrangements in which a function receives inputs.

In summary, function parameters :

  • Define the inputs of external data the function receives.
  • Define the arrangement and order of these inputs.
  • Define default values, which permit the omission of some expected function inputs.

What is a function argument?

An argument is not relevant in the definition of a function. It doesn’t form part of a function’s signature. If you don’t know about function signature, don’t worry. I explained it, including other important things to know about functions here.

Arguments are only relevant during a function invocation. We only pass arguments to a function during a function invocation or function call.

Arguments are external states or data that are passed to a function and influence the function’s operation and output.

An argument must conform to the contract or constraints of its parameter. We specify this contract as part of the function definition, also called function signature.

There is always a one-to-one mapping between parameters in a function definition and arguments passed during a function invocation.

A function defined with three parameters in the order p1: integer, p2: string, p3: string would expect three arguments in the same order: a1: integer, a2: string, a3: string to be passed during the invocation of the function.

Failure to match the order of the parameter and their defined types would raise an error.

In static languages like Java, functions parameters define the data types they expect. During the invocation of the function, there is a strict check to ensure matching arguments conform to the expected data type. An argument’s failure to meet the type defined by its parameter results in a function call error.

Weakly typed languages like JavaScript and PHP don’t enforce type checks on arguments.

Closing Words

Hopefully, this article brought clarity to the confusion on “arguments” and “parameters”. You now know the difference between the two. Yes! nobody loses their job for interchanging these programming terms, but it’s super nice to use them appropriately when communicating with other developers.

If you made it all the way down here, then thank you.

I hope you found this article helpful. Wish you the best and see you again some time.

how to
Like

About the Creator

Felix Otoo

Software Engineer, Writer, Lofi Music Lover

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

There are no comments for this story

Be the first to respond and start the conversation.

Sign in to comment

    Find us on social media

    Miscellaneous links

    • Explore
    • Contact
    • Privacy Policy
    • Terms of Use
    • Support

    © 2024 Creatd, Inc. All Rights Reserved.