💭 What is it?

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.

As a result, they avoid writing general-purpose or reusable functions. Instead, they write highly specific versions such as:

void drawCloud1() {
	ellipse(30, 30, 40, 20);
}

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

They assume that these functions are only valid for drawing one particular cloud at a fixed position. Instead of making the original function more flexible, they create multiple similar functions for every small variation.


🛠️ Why is it incorrect?

In Processing and programming in general, functions are not tied to a single context. A key goal of writing functions is to promote reusability and abstraction, making code easier to maintain, test, and extend.

A well-designed function can often be made more general by introducing parameters:

void drawCloud(int x, int y, int w, int h) {
	ellipse(x, y, w, h);
}

This version is more versatile and can be used to draw a cloud at any location and in any size.

Overly specific functions lead to code duplication and reduced flexibility. Making functions general-purpose not only improves clarity, but also supports key programming principles like modularity and separation of concerns.


🧩 Typical errors
  1. Writing a separate function for each slight variation:
void drawEnemyTopLeft() {
	image(enemy, 0, 0);
}

void drawEnemyBottomRight() {
	image(enemy, width, height);
}
  1. Avoiding the use of parameters because the original context “worked”:
void drawCircle() {
	ellipse(50, 200, 40, 40);
}

🌱 Origin

This misconception may stem from early examples, where functions are introduced only in context of a specific use case (e.g., drawHouse() or showScore()), without showing how they could be generalized.

Learners may also confuse a function’s name with its intended use, believing that a descriptive name like drawSun() restricts the function to that one purpose.

Additionally, learners who are still developing a sense for abstraction and generalization may view functions as static snippets that solve a fixed task, rather than as tools designed for flexible and reusable problem-solving.


🧩 Related Exercises
7.2e) Greeting with gender
Winter 2024/25

Exercise 7.2e Screenshot

7.4j) Swap array elements
Winter 2024/25

Exercise 7.4j Screenshot