Follow

programming vs inuitivity 

which of these two do you find more intuitive?

>>> ["elements", "in", "list"].join(",")
'elements,in,list'
>>>

or

>>> ",".join(["elements", "in", "list"])
'elements,in,list'
>>>

re: programming vs inuitivity 

@meena i prefer neither tbh

re: programming vs inuitivity 

@dysfun @meena the join is an operation on the list, not on the delimiter - the only reason the python function is on the delimiter is because they didn't want to tie a string return to their spaghetti iterable interface

programming vs inuitivity 

@meena i think the fact that 94% of responses are programmers really says a lot about fedi

re: programming vs inuitivity 

@132ikl the first person i asked was my parter, who is not a programmer, and… not on fedi…

programming vs inuitivity 

@meena Intuitively I said 1, but I think 2 would actually make more sense. In 1 the join function is part of array, but you can have arrays with elements that maybe cannot be converted to strings. In 2 join is part of string and you can force the function to take only string convertable array arguments.

re: programming vs inuitivity 

@lilianalytic i would expect this to just work:

>>> (",").join([1, 1.3, False, None])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected str instance, int found

because all these things easily convert to string:

>>> str(1)
'1'
>>> str(1.3)
'1.3'
>>> str(None)
'None'
>>> str(False)
'False'
>>>

re: programming vs inuitivity 

@meena yes, me too.
[a, b].join(",") might not work if a and b cannot be converted into a string and I would just expect a function of array to work for every array.

re: programming vs inuitivity 

@lilianalytic @meena

In Rust and other languages you can make the 1st defined only on arrays of string, or "arrays of stuff that can be joined"

re: programming vs inuitivity 

@Nocta @meena ah oki I didn't know that! I don't know if I would utilize that but maybe that's just because I'm inexperienced in that languages :blobCat_paw:

re: programming vs inuitivity 

@ihabunek yeah, from a purely types perspective — if we're following Python's argument, then Clojure's way makes more sense, because we invoke a string function, to create a string

programming vs inuitivity 

@meena tbh I have a hard time believing that anyone legitimately finds the second more intuitive; like it's easier for me to believe that all the replies for 2 either misread the question, or their finger slipped, or something like that

Sign in to participate in the conversation
Cathode Church

A place for trans makers, coders, tinkerers and dreamers.