2 ms·
I used to program in Python, and found Ruby as a language to give me everything Python provides but with a more Programmer friendly syntax. I never understood
by xtracto 8y ago
I used to program in Python, and found Ruby as a language to give me everything Python provides but with a more Programmer friendly syntax.
I never understood why you would use a function like len() in an Object Oriented Language (instead of x.len ) or having to explicitly add self to every method...
- orf 8y ago> I never understood why you would use a function like len() in an Object Oriented Language (instead of x.len ) or having to explicitly add self to every method... The answer is simple: there is a x.len function. It's just x.__len__, the protocol. Forcing it to be exposed on every type is a waste: do you use .len, .length, .size? This duck-typing allows any object that supports the length protocol to be passed to `len()`. Simple. Having it add itself to every object is.... not what you want at all. Some objects don't have a length.