3 ms·
Compared to what, though? I really like how everything is a method in Ruby as compared to, say, Python where it seems completely random if something is or isn't
by jhbadger 9y ago
Compared to what, though? I really like how everything is a method in Ruby as compared to, say, Python where it seems completely random if something is or isn't -- for example, I have to constantly remember that to get a length of an array in Python I have to do len(x) rather than x.len().
Although I like what Rust and Nim are doing with making the method/function distinction irrelevant -- there, x.f() is just syntactic sugar for f(x) -- so you can use whichever you prefer.
- flavio81 9y ago>I have to constantly remember that to get a length of an array in Python I have to do len(x) rather than x.len() On the other hand, in Python lists, tuples and arrays are fundamental data types and thus len() is defined as a fundamental built-in function. I think it makes sense. What i didn't like was when map() and reduce() were moved away from the basic functions.
- bhaak 9y ago> On the other hand, in Python lists, tuples and arrays are fundamental data types and thus len() is defined as a fundamental built-in function. I think it makes sense. But len() is only a fundamental built-in function for fundamental data types and you can implement it on any class by implementing the method __len__(self). For those it doesn't make sense any longer to be able to do len(x).
- flavio81 9y agoI'm afraid you're right...
- steveklabnik 9y agoSmall note about Rust; you're not 100% right. For example, method syntax will do auto ref/deref on the reciever, for most methods, it'd be f(&x), not f(x), though if f took self by value, it would be! It is true that you can invoke it either way if it's a method, but you cannot if it's a function, as well.
- norswap 9y agoCompared to most everything (PHP is probably worse, and there might some that I don't know). I'm not saying it's surprising because it's different, rather it's surprising because it doesn't seem to be very internally consistent. Lots of complicated rules instead of a few simple ones. As I pointed out in another comment, the way lookup is handled for instance is really a clusterfuck (http://norswap.com/ruby-lookups-scopes/ http://norswap.com/ruby-lookups-scopes/) Other OO languages like Java or Smalltalk (the more direct Ruby inspiration) do much better in this regard of having simple rules for lookup (and other things).