News for hackers. Stuff that matters.
Re:A Critical Look at MCP by Timwi on Saturday May 10, 2025 @10:17PM (#43950734)
Static functions (len, map/filter,...) that should have been methods on objects.
Re:A Critical Look at MCP by azeirah on Sunday May 11, 2025 @05:23AM (#43952534)
This one frustrates me so, so much.
Re:A Critical Look at MCP by aerhardt on Sunday May 11, 2025 @02:15PM (#43955730)
What’s the root cause?

It certainly makes functional semantics in Python suck. Comprehensions don’t make up for it.

Re:A Critical Look at MCP by int_19h on Monday May 12, 2025 @07:12PM (#43968316)
How so, given that those are also free-standing functions in most languages that are considered purely or mostly functional? (e.g. ML, Haskell)
Re:A Critical Look at MCP by volemo on Monday May 12, 2025 @02:59AM (#43960318)
I don’t mind those, tbh (maybe because I came to Python from C and Lisp).

Contrary, I dislike NumPy’s decision to make reduce/accumulate methods of operations (e.g. np.add.reduce and np.mul.accumulate), not higher order functions or methods of NumPy arrays.

Re:A Critical Look at MCP by int_19h on Monday May 12, 2025 @07:19PM (#43968357)
map() and filter() work on any iterable, so it's not clear which type you'd expect them to be methods on (keeping in mind that the notion of "iterable" in Python is expressed through duck typing, so there's no interface like say .NET IEnumerable where they would naturally belong).

len() guarantees that what you get back is an integer. If some broken type implements __len__() poorly by returning something else, len() will throw TypeError. You can argue that this is out of place for Python given it overall loose duck typing behavior, but it can still be convenient to rely on certain fundamental functions always behaving well. Similar reasoning goes for str(), repr(), type() and some others.

One can reasonably argue that Python should have something similar to C# extension methods - i.e. a way to define a function that can be called like a method, but which doesn't actually belong to any particular type - and then all those things would be such functions. But, given the facilities that Python does have, the design of those functions makes sense.