Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't think you really mean "object orientation" so much as "a byzantine object hierarchy" (stereotypically associated with Java, of course). To me, Ruby's object-oriented string functions are a lot easier to keep track of than PHP's:

x.length vs strlen($x)

x.gsub('foo', 'bar') vs str_replace('foo', 'bar', $x)

x.strip vs trim($x)

x.upcase vs strtoupper($x)

All four of the PHP functions use a different form: strX, str_X, X, and strtoX. Some of this could be solved with consistent function names, like always using str_X, but then that makes me wonder why one wouldn't just want to have all string functions available as object-oriented methods on strings. Python takes a different tactic, and has a non-object-oriented len() method, but this isn't just used to get the length of a string, it will also get you the length of a list, tuple, or dictionary.



     Python takes a different tactic, and has a 
     non-object-oriented len() method
What do you mean?

In Python len() is just a standard protocol for getting the length of something, but len() itself is calling obj.__len__() if it is defined. You can even override or replace it in an object instance, returning whatever you want.

You can argue that these protocols are a bad idea, or maybe a useless one since Ruby does just fine without such hardcoded conventions, but since it relies on runtime adhoc polymorphism, it is as object oriented as it gets.


I meant it only in the superficial sense, that the call of len() is called as len(foo), not foo.len().

I guess this is another example of why using the term "object-oriented" at all can be unhelpful, as it may mean so many different things to different people depending on the particular situation.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: