News for hackers. Stuff that matters.
Re:Rails is not written in Ruby by int_19h on Friday February 04, 2022 @06:29PM (#30215007)
It's not just sugar; it also does things like ensuring that the value is actually a nonnegative integer.

And for other unary "magic methods", the disconnect can be even bigger. E.g. iter(x) is not just a synonym for x.__iter__() - it can also produce an iterator for something that only provides __len__ and __getitem__.

Re:Rails is not written in Ruby by dragonwriter on Friday February 04, 2022 @07:57PM (#30215830)
This is, I think, largely a result of Python not idiomatically using mixins as much as Ruby (since it has multiple inheritance, it supports them, and they are sometimes used, but Ruby leans into them hard in the core.)

In the Ruby way, with otherwise similar setup, you would have a mixin that provided __iter__() given __len__() and __getitem__(), and classes that had the last two but wanted the behavior of the first would just include that mixin class as a parent, rather than having a separate branch in iter() to handle the different cases. (Ironically, its one way that Ruby is less TMTOWTDI than Python is.)

Re:Rails is not written in Ruby by progval on Monday February 07, 2022 @05:31PM (#30252320)
> In the Ruby way, with otherwise similar setup, you would have a mixin that provided __iter__() given __len__() and __getitem__(),

Python does have such a mixing, it's collections.abc.Sequence https://docs.python.org/3/library/collections.abc.html#colle...