The term comes from assembly language. I can't verify the etymology, but my guess is that the name comes from the other use of the section. Whereas the
.data section denotes variables that can change during the course of execution, the
.text section contains data that doesn't change during execution, allowing it to be put into ROM if needed. That makes it useful for code, yes, but also makes it useful for strings of text that don't change. That's probably where the term came from.
To address Griffin's comment about first class functions, consider the following python 3 code:
x = 0
x += y
The code you actually execute for
increment ends up looking internally something like:
self.func_dict['x'] += y
That executable code can be put into ROM. It never changes throughout the execution of the program, no matter how many times you call
counter(). What does change is the
self pointer and its member variables. Those must be put into
.data. When you
return increment, you are actually returning a new instance of an increment function object. You are not dynamically creating new executable code every time. The code itself is immutable even though the pointer to it is not.
The only code that must be stored in the
.data section is that generated by
eval(), because it is not known to the compiler or JIT compiler at the start of the program. However, even that code is immutable. If you change the string and call
eval() again, you're not changing the code from the previous time you called
eval(), you're creating a whole new set of code.
Although the programming model may make it kind of feel like code is mutable, actual self modifying code at the processor instruction level is dangerous and rarely found outside OS voodoo topics like process context switching.