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

Amazing. If you need to ask this question I am guessing you have spent too long with Python . No other language uses this underscore madness for special methods or otherwise. Because it’s just , I don’t know a more appropriate word for it , stupid.


What's actually amazing is how you're unable to answer a straight question.

If you call something "stupid" it doesn't really convey anything meaningful, especially not in the way you're using there, it comes across as "I don't actually have a reason I don't like it, I just don't".


Oh yes they do: https://www.php.net/manual/en/language.oop5.magic.php

The programming languages world is broad/varied enough that any statement like "no other language does this!" is almost certainly wrong (outside of esoteric languages, which python and php most certainly are not)


Lua, too:

  __add, __sub, __mul, __div, __mod, __pow, __unm, __idiv
  __band, __bor, __bxor, __bnot, __shl, __shr
  __concat, __len
  __eq, __lt, __le
  __index, __newindex, __call
  __gc, __close, __mode, __name


JS used to have those, now they are deprecated though:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

so it settled on having this syntax for similar cases using "Symbol":

class Foo { *[Symbol.iterator]() { yield 1; yield 2; yield 3; } }

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...


Most C and C++ compilers use similarly named macros:

https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macro...


I mean, Python is dynamic. Here, have this: https://gist.github.com/josiahcarlson/39ed816e80108093d585df...

Now you don't need to write your double-underscore methods ever again, if you don't want to.




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

Search: