iTranslated by AI
Better Abstraction Through Returning to the Core Concept of Functions
What "Function" Is in the First Place and the Points of Abstraction
It seems that a function refers to the following:
Function (English: function) is the action of a thing[1]. It is the specific role carried by each element or part of a whole that is interconnected and constitutes that whole[1]. Also, the fulfillment of such a role[1]. In simple writing, the Yamato word "hataraki" (action/work) is often used for expression or notation, and even when using kanji expressions, it is often simply referred to as a "yakuwari" (role). Also called "sayou" (action/operation).
https://ja.wikipedia.org/wiki/機能
There are two important points here.
- When talking about functions, a "whole" implicitly exists.
- A function is a specific "role" carried by a component within that whole.
In other words, a function does not exist independently on its own, but refers to a role within some kind of whole (which could also be called a context). When talking about functions, it is okay even if there are no actual components. To use an image, perhaps the job requirements on a resume are the functions, and the people who actually apply and meet those requirements are the components?
This becomes the point for skillful abstraction.
(Since the word "function" inevitably brings to mind an image accompanied by real components, from here on, I would like to use the word "role" instead of "function." Also, in the sense of something that realizes a role, I would like to use the word "entity" for components instead.)
To see how this leads to abstraction, please look at the examples.
Example 1:
Heart
Role: Circulate blood
Entity: Heart
Example 2:
Sewing scissors
Role: Cutting fabric in the context of sewing
Entity: Scissors
Anything is fine as long as it can fulfill the role, so the entity can actually be anything. Instead of a heart, an artificial pump is fine (if technically possible). Instead of sewing scissors, a cutter or even biting it off with your teeth is fine.
The Properties of Entities and the Topic of Reusability
I would like to dive a little deeper into sewing scissors.
Why were sewing scissors chosen as the entity for the role of "cutting fabric"?
It is because the property of scissors—"cutting things with two blades"—was optimal for that role.
Our ancestors felt that scissors were better than cutters or biting with teeth, and so sewing scissors, specialized for the ease of cutting fabric, were born from existing scissors.
Since this seems applicable to the concept of reusability in programming, let's explore it a bit more.
There are two types of properties:
- Those specialized for a specific context
- Those that are cross-contextual
For example, the heart is specialized for circulating blood within the body. While it is often compared to a pump, it cannot actually be used as a pump if taken out of the body (a somewhat macabre thought).
Scissors are relatively cross-contextual. The property of "cutting things with two blades" may have high versatility. For instance, consider the types of scissors you have at home:
- Stationery scissors
- Sewing scissors
- Kitchen shears
- Eyebrow and nose hair scissors
- Haircutting scissors
Recently, there are even scissors specifically for cardboard. Because the properties of scissors are appropriate for each required role, they have been specialized and reused.
Similarly, in actual programming, when considering reusability, it seems beneficial to think about whether something is context-specific or cross-contextual.
Discussion