Filter by Programming Topic:

Arrays Functions All

Filter by Misconception Type:

Programming Language Code Quality All

Order by:

πŸ”‘ Alphabetical 🎲 Shuffle
πŸ”„ Frequency 🧠 Correction Effort 🚧 Learning Barrier πŸ” Discoverability
🍎 Low Hanging Fruit

Array Init Needs Curly Brackets

πŸ” Discoverability: 1 🚧 Learning Barrier: 3 🧠 Correction Effort: 1.5 πŸ”„ Frequency: Low
Learners believe that curly brackets {} are necessary to create an array of a specific length.
int[] array = { 5 }; // Learners think this creates an array of length 5

Array Indexing Needs Parentheses

πŸ” Discoverability: 3 🚧 Learning Barrier: 1 🧠 Correction Effort: 1 πŸ”„ Frequency: Low
Learners believe that accessing an array element in Processing requires extra parentheses around the index expression.
int[] numbers = { 10, 20, 30 };
println(numbers[(0)]; //technically correct, but unnecessary

Array Length as Number

πŸ” Discoverability: 3 🚧 Learning Barrier: 3.5 🧠 Correction Effort: 2 πŸ”„ Frequency: High
Learners believe that the length of an array an only be accessed using a fixed number, rather than using the .length property.
for (int i = 0; i < 5; i++) { // hardcoded length
	println(values[i]);
}

Array Length Only in Loops

πŸ” Discoverability: 3.5 🚧 Learning Barrier: 3 🧠 Correction Effort: 2 πŸ”„ Frequency: High
Learners believe that the .length property of an array can only be used inside loop conditions.
int[] array = new int[5];
int[] array2 = new int[5];

for (int i = 0; i < array.length; i++) {
	array[i] = i + 1;
	array2[i] = 5 - i; // usage of a constant instead of .length
}

No Function Calls Inside Functions

πŸ” Discoverability: 3 🚧 Learning Barrier: 5 🧠 Correction Effort: 2 πŸ”„ Frequency: Medium
Learners believe that it is not allowed to call a function from within another (custom) function.
void setup() {
	greet(); // Learners think this is allowed
}

void greet() {
	sayHello(); // Learners think this is not allowed
}

void sayHello() {
	println("Hello!");
}

Parameters Must Be Global

πŸ” Discoverability: 2.5 🚧 Learning Barrier: 4 🧠 Correction Effort: 1.5 πŸ”„ Frequency: Medium
Learners believe that parameters used in a function's definition must first be declared as global variables.
String name;

void setup() {
	greet("Alex");
}

void greet(String name) {
	println("Hello, " + name);
}

Return Does Not Terminate Function

πŸ” Discoverability: 2.5 🚧 Learning Barrier: 3 🧠 Correction Effort: 2 πŸ”„ Frequency: Low
Learners believe that the return statement in a function only sends back a value, but does not end the function's execution.
int doubleValue(int x) {
	return 2 * x;
	println("Doubled the value");
}

Parameters Arguments Match Name

πŸ” Discoverability: 2.5 🚧 Learning Barrier: 4 🧠 Correction Effort: 1.5 πŸ”„ Frequency: Medium
Learners believe that when calling a function, the names of the arguments must exactly match the names of the parameters defined in the function header.
void setup() {
	String username = "Alex";
	greet(username);
}

void greet(String username) {
	println("Hello, " + username);
}

Data Types in Function Calls

πŸ” Discoverability: 1.5 🚧 Learning Barrier: 3 🧠 Correction Effort: 1 πŸ”„ Frequency: Low
Learners believe that when calling a function, they must include data types with the arguments, as if they were redeclaring the parameters.
void setup() {
	String name = "Alex";
	greet(String name);
}

void greet(String name) {
	println("Hello, " + name);
}

No Nested Function Calls

πŸ” Discoverability: 3 🚧 Learning Barrier: 3.5 🧠 Correction Effort: 3 πŸ”„ Frequency: Medium
Learners believe that function calls cannot be nested, meaning one function cannot be called inside the argument list of another function.
String username = getUsername(user);
println(username);

Functions Cannot Use Global Data

πŸ” Discoverability: 3.5 🚧 Learning Barrier: 4 🧠 Correction Effort: 2 πŸ”„ Frequency: Low
Learners believe that functions can only use data defined inside themselves, and cannot access global variables or other globally defined functions.
int counter = 0;

void increment() {
	counter++; // Learner assumes this is not allowed
}

Return At The End

πŸ” Discoverability: 4 🚧 Learning Barrier: 3.5 🧠 Correction Effort: 2.5 πŸ”„ Frequency: High
Learners believe that the return statement can only be used at the very end of a function.
int absolute(int x) {
	if (x < 0) {
		return -x; // Learners assume this is not allowed
	}
	return x;
}

Return Value Must Be Global

πŸ” Discoverability: 3.5 🚧 Learning Barrier: 4 🧠 Correction Effort: 1.5 πŸ”„ Frequency: Medium
Learners believe that the return value of a function must first be declared as a global variable.
int result;

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

Return Outside Loop

πŸ” Discoverability: 3.5 🚧 Learning Barrier: 3.5 🧠 Correction Effort: 3 πŸ”„ Frequency: Low
Learners believe that a return statement can only be used outside of a loop.
float firstNegative(float[] a) {
  float first = 0;
  for (int i = 0; i < a.length; i++) {
    if (a[i] < 0) {
      first = a[i];
      break; // used instead of directly returning
    }
  }
  return first;
}

Function Calls Read Outside In

πŸ” Discoverability: 4 🚧 Learning Barrier: 3.5 🧠 Correction Effort: 3 πŸ”„ Frequency: Low
Learners believe that when reading or evaluating nested function calls, they must start from the outside and work inward.
println(getName()); // Learners assume println runs first

One Return per Function

πŸ” Discoverability: 3.5 🚧 Learning Barrier: 3.5 🧠 Correction Effort: 2.5 πŸ”„ Frequency: Low
Learners believe that a function is only allowed to contain one return statement.
int findFirstNegative(int[] array) {
	for (int i = 0; i < array.length; i++) {
		if (array[i] < 0) {
			return array[i]; // Learners assume this is incorrect
		}
	}
	return 0;
}

Return Multiple Values

πŸ” Discoverability: 1 🚧 Learning Barrier: 2 🧠 Correction Effort: 1 πŸ”„ Frequency: Low
Learners believe that a function in Processing can return multiple values at once.
int addAndMultiply(int a, int b) {
	return a + b, a * b;
}

No Direct Value Return

πŸ” Discoverability: 3.5 🚧 Learning Barrier: 1.5 🧠 Correction Effort: 1.5 πŸ”„ Frequency: Medium
Learners believe that a function's return value must always come from a named variable, and that it's not allowed to return a value directly using an expression.
int square(int x) {
	int result = x * x; // Learners think the variable is necessary
	return result;
}

Signature Without Function Name

πŸ” Discoverability: 2.5 🚧 Learning Barrier: 3.5 🧠 Correction Effort: 2 πŸ”„ Frequency: Medium
Learners believe that a function's name is not part of its signature, and that only the parameter types determine whether two functions are considered the same or different.
void drawCircle(int x, int y) {
	circle(x, y, 50);
}

// Learners think this is invalid
// as another function with these parameter types already exist
void drawSquare(int x, int y) {
	square(x, y, 50);
}

Signature Without Parameter Order

πŸ” Discoverability: 2.5 🚧 Learning Barrier: 4 🧠 Correction Effort: 2.5 πŸ”„ Frequency: Low
Learners believe that the order of parameters in a function does not matter when defining or calling it.
void drawCircle(int x, float size) { ... }

void drawCircle(float size, int x) { ... } // Learners think this is the same

Parameters Immutable

πŸ” Discoverability: 4 🚧 Learning Barrier: 1.5 🧠 Correction Effort: 1 πŸ”„ Frequency: Low
Learners believe that function parameters are read-only and cannot be changed inside the function.
int doubleValue(int x) {
	x = x * 2; // Learner assumes this is not allowed
	return x;
}

Return Parentheses

πŸ” Discoverability: 3 🚧 Learning Barrier: 1 🧠 Correction Effort: 1 πŸ”„ Frequency: Low
Learners believe that the expression following a return statement must be enclosed in parentheses.
int square(int x) {
	return (x * x); // Learners assume parentheses are required.
}

Parameters Allowed to Change

πŸ” Discoverability: 3 🚧 Learning Barrier: 4 🧠 Correction Effort: 4 πŸ”„ Frequency: Low
Learners believe that function parameters can always be freely modified without negative consequences.
int[] numbers(int start, int len) {
  int[] a = new int[len];
  for (int i = 0; i < len; i++) {
    a[i] = start;
    start++; // parameter is modified directly
  }
  return a;
}

Functions Should Be Context Specific

πŸ” Discoverability: 4.5 🚧 Learning Barrier: 4.5 🧠 Correction Effort: 2.5 πŸ”„ Frequency: Low
Learners believe that functions should be created only for one very specific purpose or context, and that they are tightly bound to the situation in which they were first written.
void drawCloud1() {
	ellipse(30, 30, 40, 20);
}

void drawCloud2() {
	ellipse(60, 30, 40, 20);
}

Inner Arrays Uniform

πŸ” Discoverability: 5 🚧 Learning Barrier: 2 🧠 Correction Effort: 4 πŸ”„ Frequency: Low
Learners believe that in a multidimensional array, all inner arrays must have the same size.
// Learners assume this is invalid:
int[][] jagged = new int[3][];
jagged[0] = new int[2];
jagged[1] = new int[5];
jagged[2] = new int[1];

Arrays Empty At Beginning

πŸ” Discoverability: 2.5 🚧 Learning Barrier: 2 🧠 Correction Effort: 2 πŸ”„ Frequency: Low
Learners believe that arrays are completely empty after being created.
int[] values = new int[5];
for (int i = 0; i < values.length; i++) {
    values[i] = 0; // Learners think they have to set the values manually to 0
}

Arrays Always Contain Data

πŸ” Discoverability: 2.5 🚧 Learning Barrier: 4.5 🧠 Correction Effort: 2.5 πŸ”„ Frequency: Low
Learners believe that arrays are automatically populated with meaningful or usable values immediately after declaration
Ball[] balls = new Ball[3];
println(ball[0].x); // Learners expect balls[0] to be an object of type Ball

Loops for Array Index Access

πŸ” Discoverability: 4.5 🚧 Learning Barrier: 2 🧠 Correction Effort: 2.5 πŸ”„ Frequency: High
Learners tend to believe that a loop is always needed to access an element of an array, even if the index of the respective element is already known.
int[] numbers = {180, 250, 25, -134, 0, 25};
int index = 3;
// here a loop is used to access an element with a known index
for (int i = 0; i < numbers.length; i++) { 
    if (i == index) {
        println(numbers[i]);
    }
}

One Loop per Array

πŸ” Discoverability: 3.5 🚧 Learning Barrier: 3.5 🧠 Correction Effort: 2.5 πŸ”„ Frequency: High
Learners believe that separate loops are required to iterate over arrays, even when those arrays are logically connected and of the same length.
PVector[] position = new PVector[10]; // position of 10 balls
PVector[] speed = new PVector[10]; // speed of 10 balls

for (int i = 0; i < position.length; i++) {
    position[i] = new PVector(random(width), random(height));
}
for (int i = 0; i < speed.length; i++) {
    speed[i] = new PVector(random(5), random(5));
}

Arrays Grow

πŸ” Discoverability: 2 🚧 Learning Barrier: 4 🧠 Correction Effort: 2.5 πŸ”„ Frequency: Medium
Learners believe that the length of an array is flexible, so they can freely add or remove elements.
int[] array = {15, 24, -12}; 

array[3] = 105; // OutOfBounds
array[4] = 40; // OutOfBounds