On Thu, Oct 24, 2019 at 2:20 AM Steven D'Aprano firstname.lastname@example.org wrote:
Hand-writing repetitive, dumb, mechanical code is an anti-pattern. I'm sure that, somewhere out there, there's a coder who prefers to write:
[mylist, mylist, mylist, mylist, mylist]
instead of the obvious slice, but most of us didn't become programmers because we love the tedious, repetitive boilerplate.
Siiiiiiiigh... that one actually strikes home with me. Some of my non-Python coding is in a language called SourcePawn, which doesn't have any sort of "bulk operations" like slicing or *args or anything. So I might have code like this:
SmokeLog("[%d-A] Smoke (%.2f, %.2f, %.2f) - (%.2f, %.2f)", client, pos, pos, pos, angle, angle);
where "pos" and "angle" are vectors - arrays of three floating-point values. In Python, a Vector would be directly stringifiable, of course, but even if not, you could at least say *pos,*angle.
So if someone is coming from a background in languages that can't do this sort of thing, then yes, Python's way doesn't "look like what it does". Quite frankly, that's a feature, not a flaw. It looks like what the programmer intends, instead of looking like what mechanically happens on the fly. We don't write code that looks like "push this value onto the stack, push that value onto the stack, add the top two values and leave the result on the stack", even though that's how CPython byte code works. We write code that says "a + b", because that's the programmer's intention.
If your intention is to iterate over a series of words, you do not need all the mechanical boilerplate of constructing a list and properly delimiting all the pieces. In Python, we don't iterate over numbers by saying "start at 5, continue so long as we're below 20, and add 1 every time". We say "iterate over range(5, 20)". And Python is better for having that. (Trust me, I've messed up C-style for loops enough times to be 100% certain of that.) You might argue that a blank-separated words notation is unnecessary, but it should be obvious that it's a valid way of expressing *programmer intention*.