The technique you are calling "extension methods" is known as 
"monkey-patching" in Python and Ruby.

With respect to a fine language, Kotlin, it doesn't have the user-base 
of either Python or Ruby. Python does not allow monkey-patching builtin 
classes, but Ruby does:

https://avdi.codes/why-monkeypatching-is-destroying-ruby/

A cautionary tale. So what does Kotlin do to prevent that sort of thing?

Can you use a regular function that takes a list as argument, instead of 
monkey-patching the list class to add a method?

The beauty of a function is that every module is independent, so they 
can add their own list extensions (as functions) without stomping over 
each other. Whereas if they add them directly on to the list class 
itself, they can clash.

As for code readability, I don't think that this:

    mylist.first_or_none()

is particularly more readable than:

    first_or_none(mylist)


Not everything has to be wrapped in a class.

https://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/2RI34EPKL2MLZTOFB2XM6KCAUXW3CDSD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to