💭 What is it?

Learners believe that function parameters are read-only and cannot be changed inside the function. They assume that once a parameter is passed into a function, it must remain unmodified, as if it were a constant or a protected value.

For example, they may think the following code is invalid or incorrect:

int doubleValue(int x) {
	x = x * 2; // Learner assumes this is not allowed
	return x;
}

They believe either that such an assignment is not permitted, or that the change to the parameter will not have any effect.


🛠️ Why is it incorrect?

In Processing, function parameters are local variables. When the function is called, a new variable is created for each parameter, initialized with the corresponding argument. Like any local variable, these variables can be read, reassigned, and modified just like any other variable within the function.

For example:

int doubleValue(int x) {
	x = x * 2; // perfectly valid
	return x;
}

Here, since the variable is a primitive type, x is a local copy of the argument passed into the function. Modifying it has no effect on the original variable outside the function, but within the function, the reassignment is entirely valid.

However, it’s helpful to understand the following distinctions:

  • For primitive types (like int, float, boolean), a copy of the value is passed. Changing the parameter only affects the local copy.
  • For reference types (such as arrays or objects), the reference is passed. This means that modifications to the internal state of the object or array do affect the original data.
  • While modifying parameters is valid, overwriting parameter values unnecessarily can reduce code clarity and maintainability, especially in larger functions or when the original input value is still relevant later in the code.

🧩 Typical errors
  1. Creating an extra variable just to avoid modifying the parameter:
int doubleValue(int x) {
	int doubled = x * 2;
	return doubled;
}

🌱 Origin

This misconception may stem from early teaching examples that introduce additional local variables to improve readability. Learners might misunderstand the approach and assume such variables are required rather than optional.

In some cases, teachers may suggest avoiding parameter reassignment to support good style and clarity. Learners may then overgeneralize this suggestion and believe that modifying parameters is not allowed at all, when in reality it’s a stylistic decision, not a rule.

Additionally, learners who have not yet understood the difference between pass-by-value and pass-by-reference may wrongly assume that parameters are “locked” or protected from change to avoid side effects.