>>> ', '.join(['1', '2', '3'])
'1, 2, 3'
>>> '1, 2, 3'.split(', ')
['1', '2', '3'] >>> ', '.join(['1', '2', '3'])
'1, 2, 3'
>>> '1, 2, 3'.split(', ')
['1', '2', '3']I read the first as the concat symbol applied to an iterable leads to string concated by the concat symbol.
I read the second as an iterable broken by split symbol leads to an iterable of the chunks.
In the first case, I want to do something to a list: join it into a string. So, clearly, I need a list method? But no, I need to engage in some form of indirection; for some reason, I need to reach for a string method. Even if there is no string that I want to use as a delimiter. In that case, I need to use a string method on an empty string.
OK, I’ll play along. Now I want to take the string and split it into an array. Now that I’ve been educated, I know better than to try the sensible thing. Pre-enlightenment, I would have reached for a method applied to the thing that I wanted to transform. But now I know I should think backwards, and use a method applied to the delimiter. OOPs.
julia> join([1 2 3], ", ")
"1, 2, 3"
julia> split("1, 2, 3", ", ")
3-element Vector{SubString{String}}:
"1"
"2"
"3"
Note how they are both functions. The data that they operate on is the first argument, in both cases. The optional second argument is the obvious next most important thing, the delimiter. Other optional arguments come after that. There is nothing to remember, because it makes sense.You'll have to decide if you find that convincing. I understand your point and kind of wish I hadn't read this thread because I'm more torn than before.
This could have easily been avoided if `join` would have been a method of the list object, not the string object. But we're stuck with this now.
Maybe it would be better as a standalone function. But then you'd either have to import it or it would pollute the global namespace.
Other OOP models offer different solutions.
https://arstechnica.com/science/2020/10/the-unreasonable-eff...
Not in CLOS, from which Julia's mechanisms are derived (which leads to the question why not CLOS but Python of all things should be used as a source of "normal sense" of anything Julia-related). In CLOS, classes bind together data, generic functions name abstract operations, and methods represent specific code that deals with implementing a generic function for a particular combination of type arguments.
> which is what leads to all the problems
I don't think anyone is disputing that here. There's a reason why CLOS didn't do any of that.
> In Julia functions are generic, and specialized to methods acting on arbitrary combinations of types; they are freed from the data.
...yes, just like in CLOS (unsurprisingly, given Julia's heritage), and those types are effectively CLOS classes.
Although multiple dispatch in CL (and Perl) predates Julia, I was not aware that Julia’s design derived from it. Do you have a reference that traces this?
Interestingly enough, in Julia's documentation, the section "Noteworthy Differences from other Languages" (https://docs.julialang.org/en/v1/manual/noteworthy-differenc...) compares Julia to only several relevant languages, which are: Matlab, R, Python, C/C++, and...Common Lisp, of all things. I very strongly doubt that this is a coincidence.