DEV Community

Discussion on: What simple things annoy you about your favourite programming languages?

Collapse
 
amreis profile image
Álister Machado dos Reis

The fact that, in Python, "joining an array using a given string" is phrased as "use this string to join an array".

# this does not work, sadly
['a','b','c'].join('-')

# this works
'-'.join(['a','b','c'])
Enter fullscreen mode Exit fullscreen mode

Now I'm used to it, but I used to get it wrong all the time, because 'join' is an active verb, so at least for me it makes sense to put it after the thing being joined.

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

Yup, I get that wrong every time I attempt to join an array. Logically join should either be a part of the array type or a standalone function.

Collapse
 
marlysson profile image
Marlysson Silva

I never understand why join is applying in separator passing the list to join them..

Collapse
 
grahamlyons profile image
Graham Lyons

It's because the argument to join can be anything that you can iterate over e.g. list, tuple, array etc. Python tends to make functions take duck-typed arguments rather than having interface-style compatibility on types.