[Proposal] Enum.split_with/2 to Enum.split_by/2

57 views
Skip to first unread message

eksperimental

unread,
Dec 31, 2018, 6:59:58 AM12/31/18
to elixir-l...@googlegroups.com
I would like to propose the renaming of Enum.split_with/2 to Enum.split_by/2, as it doesn't follow the naming rationale we currently have.

Taken from https://github.com/eksperimental/elixir_inconsistencies#elixir-inconsistencies

Affected: Enum.split_with/2.

Proposed: Enum.split_by/2.

Precedents: `Enum.chunk_by/2`, `Enum.dedup_by/2`, `Enum.group_by/3`, `Enum.max_by/3`,
`Enum.min_by/3`, `Enum.min_max_by/3`, `Enum.sort_by/3`, `Enum.uniq_by/2`,
`Stream.chunk_by/2`, `Stream.dedup_by/2`, `Stream.uniq_by/2`.

Rationale: The suffix "_with" in functions is only used in three functions: `String.ends_with?/2`,
`String.starts_with?/2` and `List.starts_with?/2`; and these are describing the content of
elements. On the other hand, the suffix "_by" is used in the numerous functions mentioned in
*Precedents*, and they are used to filter content based on the function provided.

José Valim

unread,
Dec 31, 2018, 7:20:05 AM12/31/18
to elixir-l...@googlegroups.com
Thanks Eksperimental!

From your group of functions, I would argue that only chunk_by is similar to similar split_with, as the other functions are about computing a property from the data. So they may use the same suffix but the suffix may not necessarily mean the same thing.

I would love to hear from native speakers too, specially if split_by and split_with have different connotations. It is worth mentioning that split_with splits it only in two parts and chunk_by into multiple.

Finally, I would like to have a very strong reason for us to push yet another deprecation into users. Especially because "split_with" already came from a deprecated Enum.partition function. As far as inconsistencies go, this is a very minor one, and I will be glad to live with it.

José Valim
Skype: jv.ptec
Founder and Director of R&D

eksperimental

unread,
Dec 31, 2018, 7:52:08 AM12/31/18
to elixir-l...@googlegroups.com
On Mon, 31 Dec 2018 13:19:51 +0100
José Valim <jose....@plataformatec.com.br> wrote:
> From your group of functions, I would argue that only chunk_by is similar
> to similar split_with, as the other functions are about computing a
> property from the data. So they may use the same suffix but the suffix may
> not necessarily mean the same thing.

Thank you José for taking the time to answer.
My main point here is tthat "_with" in the String and List
modules is used to compare terms directly, and functions with the "_by" suffix accept a function
and process info based on that.

The connotation that "_with" has on me is that an argument contains this term;
while "_by" implies to do something like split, sort, group based on this condition/rule which
happens to always be a function, not a term to compare to.

I would also love to hear the opinion of native speakers.

José Valim

unread,
Dec 31, 2018, 9:44:32 AM12/31/18
to elixir-l...@googlegroups.com
> My main point here is tthat "_with" in the String and List modules is used to compare terms directly, and functions with the "_by" suffix accept a function and process info based on that.

I don't think we can consider the suffixes in isolation. That would be an unnatural way to organize the API. How "_with" is used in start_with? is a different meaning than split_with which is marked by the preceding verbs. So unless the preceding word is also in the same category, like max/min/uniq which are aggregations, I believe we are comparing apples and oranges.

José Valim
Skype: jv.ptec
Founder and Director of R&D
--
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 elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/20181231195201.1b3d1c08.eksperimental%40autistici.org.
For more options, visit https://groups.google.com/d/optout.

Allen Madsen

unread,
Dec 31, 2018, 10:27:09 AM12/31/18
to elixir-l...@googlegroups.com
I'm a native speaker.

`starts_with?` reads as `adjective` followed by a `preposition`.
`split_with` reads as `verb` followed by a `preposition`.

So, this wouldn't be confusing to me.

As far as `_with` vs `_by`, I think `_by` has a slight leaning to element wise operations, whereas `_with` has a slight leaning towards operations that work on multiple elements, such as specifying the sorting function which would compare two elements together. However, there are many cases where they could be interchangeable.


Randy Creasi

unread,
Dec 31, 2018, 11:59:00 AM12/31/18
to elixir-lang-core
I'm a native English speaker and I would have a very hard time trying to formalize when to use "by" rather than "with."
The two words have numerous and varied usages and there's a lot of overlap. If I were to try to generalize, I'd say:
"By" tells you what method is being used to perform an action.
"With" tells you which tool is being used.

Example:
I split the apple by cutting it.
I split the apple with a knife.

But that leaves out a lot nuance and many other ways the two words can be interpreted.
Because of the ambiguity I don't think renaming the function would accomplish much in terms of clarification.

eksperimental

unread,
Jan 8, 2019, 12:43:00 PM1/8/19
to elixir-l...@googlegroups.com
Thank you everyone for your input.
I guess we can just leave the function as it is.
> >> *José Valim*
> >>> an email to elixir-lang-co...@googlegroups.com <javascript:>.
> >>> To view this discussion on the web visit
> >>> https://groups.google.com/d/msgid/elixir-lang-core/20181231195201.1b3d1c08.eksperimental%40autistici.org
> >>> .
> >>> For more options, visit https://groups.google.com/d/optout.
> >>>
> >> --
> >> 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 elixir-lang-co...@googlegroups.com <javascript:>.
> >> To view this discussion on the web visit
> >> https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BiA1nJooFZDUhN8xhjGWeedo2-jNEQu4z%2Bfa6YCMS-sg%40mail.gmail.com
> >> <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BiA1nJooFZDUhN8xhjGWeedo2-jNEQu4z%2Bfa6YCMS-sg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> >> .
Reply all
Reply to author
Forward
0 new messages