News for hackers. Stuff that matters.
Re:Verb-Noun vs. Noun-Verb by stouset on Wednesday October 16, 2019 @05:23PM (#21275919)
The Python approach also exposes unnecessary details and by doing so causes a performance hit by forcing you to get a list of keys/values and then find out of what you’re looking for is in them. This is slower than what the dictionary could do internally: hash the key and check if there’s an entry for it in the backing store.
Re:Verb-Noun vs. Noun-Verb by klodolph on Wednesday October 16, 2019 @05:27PM (#21275957)
The .values() method does not return a list, it returns a view object. If you write ‘value in m.values()’, it invokes the __contains__() method.

(Note that this cant be a hash check because it’s not testing the presence of a key.)

(Also note that the story is different if you look at sufficiently archaic versions of Python.)

Re:Verb-Noun vs. Noun-Verb by cortesoft on Thursday October 17, 2019 @12:22AM (#21278887)
This is one of the reasons I like ruby better than python... none of the magic 'dunder' methods... if you want to define a custom adder for your class, so "foo + bar" works, you do "def +()" in ruby instead of "def __add__ ()" in Python.... I love that ruby just uses the actual operator instead of some arbitrary method name you have to remember.
Re:Verb-Noun vs. Noun-Verb by lifthrasiir on Thursday October 17, 2019 @03:15AM (#21279644)
> none of the magic 'dunder' methods

Ruby do have equivalents to Python magic methods... disguised as normal methods. For example Python `__hash__` is Ruby `hash` and both are used by built-in dict/hash values and you should be aware of that fact in both. There are some philosophical differences as well, Python likes to have standalone functions that are customized via magic methods (e.g. `str` vs. `__str__`, you don't normally call the latter) and in Ruby everything is method (e.g. `to_s`). It really seems like a matter of taste.

Re:Verb-Noun vs. Noun-Verb by stouset on Wednesday October 16, 2019 @05:29PM (#21276002)
Fair enough!