I'd probably have chosen String.repeat, however String.duplicate makes
sense to me grammatically as well as duplicating tends to be used 'as'
multiplication in common speech (around where I am anyway, central USA).
On Thursday, January 18, 2018 at 2:59:32 AM UTC-7, Timotej Fartek wrote:
>
> 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/fafc4269-6a54-48da-81fe-2de1788b5d12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.