Hello! First of all, good job on Elixir. It really is a joy to build
applications with it.
Now about my proposal. I think that the function "duplicate/2" in the
module String can be a bit confusing with the current naming. When I read
"duplicate", the thing that immediately pops into my mind is "make a copy
of", "multiply by two" etc. so when I'm working with String.duplicate I'm
always a bit confused as to what is going to happen with my string.
If I call String.duplicate("a", 2) to me it looks like the end result is
going to be "aaaa", because we take "a", we duplicate it (so it's "aa") and
then we duplicate that again (because n=2), and return "aaaa". Of course
this assumption is wrong as the end result is "aa".
What String.duplicate actually does is *multiply the string n times*.
Python (the language) has this simplified to the point where you actually
write "a" * 2, to get the result "aa".
I suggest we do something similar with Elixir and come up with a better
name for the duplicate function. I propose String.repeat or String.multiply
but I am also open to other ideas if you think this might cause extra
confusion. The most technically correct version of the name in my opinion
would be String.multiply, because even with String.repeat there could be
some confusion: does String.repeat("a", 1) return "a" or "aa"?
I would like to make a pull request with the new function but first I want
to hear what the community thinks about this idea.
Another version of the name could be "times". String.times("a", 1) would in
my opinion clearly return "a". String.times("a", 3) would clearly return
"aaa".
Anyway this post is long enough as is 😅.
Thanks again for the wonderful work so far!
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/d4559b21-7bc5-4359-923a-34510709629a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.