Comment by librasteve
6 days ago
Well sure - being in a rut is good. But the language is the medium in which you cast your idiom, right?
Here's a Python rut:
n = 20 # how many numbers to generate
a, b = 0, 1
for _ in range(n):
print(a, end=" ")
a, b = b, a + b
print()
Here's that rut in Raku:
(0,1,*+*...*)[^20]
I am claiming that this is a nicer rut.
> I am claiming that (0,1,+...*)[^20] is a nicer rut.
If it's so fantastic, then why on earth do you go out of your way to add extra lines and complexity to the Python?
Complexity-wise, this version is more complicated (mixing different styles and paradigms) and it's barely less tokens. Lines of code don't matter anyway, cognitive load does.
Even though I barely know Raku (but I do have experience with FP), it took way less time to intuitively grasp what the Raku was doing, vs. both the Python versions. If you're only used to imperative code, then yeah, maybe the Python looks more familiar, though then... how about riding some new bicycles for the mind.
> Complexity-wise, this version is more complicated (mixing different styles and paradigms)
Really? In the other Python version the author went out of his way to keep two variables, and shit out intermediate results as you went. The raku version generates a sequence that doesn't even actually get output if you're executing inside a program, but that can be used later as a sequence, if you bind it to something.
I kept my version to the same behavior as that Python version, but that's different than the raku version, and not in a good way.
You should actually ignore the print in the python, since the raku wasn't doing it anyway. So how is "create a sequence, then while it is not as long as you like, append the sum of the last two elements" a terrible mix of styles and paradigms, anyway? Where do you get off writing that?
> Lines of code don't matter anyway, cognitive load does.
I agree, and the raku line of code imposes a fairly large cognitive load.
If you prefer "for" to "while" for whatever reason, here's a similar Python to the raku.
The differences are that it's a named sequence, and it doesn't go on forever and then take a slice. No asterisks that don't mean multiply, no carets that don't mean bitwise exclusive or.
> If you're only used to imperative code, then yeah, maybe the Python looks more familiar, though then... how about riding some new bicycles for the mind.
It's not (in my case, anyway) actually about imperative vs functional. It's about twisty stupid special symbol meanings.
Raku is perl 6 and it shows. Some people like it and that's fine. Some people don't and that's fine, too. What's not fine is to make up bogus comparisons and bogus implications about the people who don't like it.
5 replies →
err - I cut and pasted the Python directly from ChatGPT ;-)
But it doesn't do the same thing at all as the raku.
It doesn't build a list, rather it dumps it as it goes.
It has an explicit print.
It uses a named constant for 20 rather than a literal.
etc, etc...