News for hackers. Stuff that matters.
Re:Ask HN: How did Python become the lingua franca of ML/AI? by danwills on Wednesday November 10, 2021 @01:40AM (#29171789)
It's called 'monkey patching' and python does make it particularly easy, simply:

class.methodName = newMethod

.. kinda thing, future callers now get your method instead of the original.

This does seem a fair bit easier than other languages make it to do?

Re:Ask HN: How did Python become the lingua franca of ML/AI? by alanfranz on Wednesday November 10, 2021 @02:57AM (#29172198)

  class.methodName = newMethod
 
> .. kinda thing, future callers now get your method instead of the original.

Which is as powerful as it is a problem, since doing such kind of monkeypatching will change the behaviour all other instances, including already-created ones, that know nothing about your trick.

Any part of the program can modify any other part of the program in a significant way, making local reasoning and debugging very hard.

So, great for quick-and-dirty single-file scripts/ipython notebooks. Terrible for large systems.

That's the very issue with Python. The way it doesn't enforce sane, clean programming behaviour makes it easy for a beginner/non-programmer to work with it. But a large system with a lot of external libraries is very hard to maintain.

Source: Python user since ~2004

Re:Ask HN: How did Python become the lingua franca of ML/AI? by dragonwriter on Wednesday November 10, 2021 @10:44AM (#29175908)
> It's called 'monkey patching' and python does make it particularly easy

Inheritance and overriding method in the descendant class is cleaner, and more broadly supported. When you need monkey patching, sure, its nice that most modern dynamic OO languages support it quite naturally. (Ruby even supports scoped monkey patching via refinements, as well as classic monkey patching and per-object overrides.) But this is not at all unique to Python.

Re:Ask HN: How did Python become the lingua franca of ML/AI? by perth on Wednesday November 10, 2021 @01:44AM (#29171806)
You see exactly what I mean!