3 ms·
> a + is way more readable. I believe it works much like a self-fulfilling prophecy. Language designers think that it is more readable, so they do it. Language
by ordu 5y ago
> a + is way more readable.
I believe it works much like a self-fulfilling prophecy. Language designers think that it is more readable, so they do it. Language users use it and became habituated to it. So it becomes more readable because some people believe that it is more readable.
What is unreadable with:
a.extend(b)
c = a.clone().extend(b);
Programmer have all the control of memory management, and at the same time she is free to do any operations on lists, to chain operations, to do everything. And all her intent is here, it is written, it is obvious. While a += b... It leads to a need to write articles describing the difference between + and += and how could I possibly know did programmer who wrote the code read all such articles? Did he wrote he intended to, or what is nicey looking, but not great semantically? Did I read all these articles or I missed something?
Even if it is more readable, does it justify all the obscurity?
- account42 5y agoDo you also believe all built-in types like integers should use named functions instead of operators?
- ordu 5y agoNo. I even believe that non-builtin types behaving like numbers might use operators. But lists, arrays, strings behave not like numbers. They allocate memory, they reuse memory for values, they have operations of non O(1) complexity, and so they shouldn't be using operators. If one really wants to, then he might invent new operators for this, like concatenation-operator. I didn't see any reasonable way to do it, but it doesn't mean that such way cannot be devised.
- c-cube 5y agoNumbers in python also allocate memory. Integers are arbitrary precision, so the difference between + and += might also be very relevant for them. And of course there's numpy and matrices which also behave like numbers, or at least like mathematical objects.