An awkward thing about programming in Python: there are lots of double underscores. For example, the standard method names beneath the syntactic sugar have names like __getattr__, constructors are __init__, built-in operators can be overloaded with __add__, and so on. In the Django framework (at least before they integrated the magic-removal branch), the object-relational mapper used keyword arguments named things like user__id__exact.
My problem with the double underscore is that it’s hard to say. How do you pronounce __init__? “underscore underscore init underscore underscore”? “under under init under under”? Just plain “init” seems to leave out something important.
I have a solution: double underscore should be pronounced “dunder”. So __init__ is “dunder init dunder”, or just “dunder init”.
I’ll leave it to someone else to decide what “dunderhead” means now.
Comments
I like this so much it is now officially in theTabblo hacker's style guidelines.
FWIW, I usually pronouce these constructors as "under under" , and leave off the trailing "under under" (at least when talking to other Python folks). So I'll say "under under init" when talking about __init__, and usually it comes out phonetically like "unnerunner init".
Brilliant. Will you be writing it up as a PEP? ;)
"Dunder" was also suggested on the Python-List a few years ago: http://mail.python.org/pipermail/python-list/2002-September/124640.html
Btw, the name of the paper company on NBC's The Office sitcom is Dunder Mifflin (aka __Mifflin)
Correction: __Dunder__
Geez, Louis.... I meant __Mifflin__
Bob, I think Ned was using Dunder as a noun that described the two underscores not an adjective that describes text flanked by double underscores? Since it's the former I think your first __Mifflin is correct. That means there's an opportunity to create the adjective. I propose dunderuf.
It looks like I'm not the coiner of "dunder". D'oh! Still a good idea (maybe even a better one)!
I have a problem with this protocol; it doesn't unambiguously differentiate between __foo and __foo__. If you ask me to look for "dunder foo", which one should I be looking for? Worse, if you ask me to *implement* "dunder foo", which name should that resolve to?
Ned: I think it's a good idea too.
Now that we have that cleared up, maybe we can standardized how we should say www: double-u, double-u, double-u, dubya-dubya-dubya, dub-dub-dub, triple-dub, wuh-wuh-wuh.....
that's user_id__exact in Django (only one dunder)
Dunders must die. It's a notion for "special" attribute, which shouldn't be used directly in a user-space code, except for very well known cases, such as __init__. So all you library writers abuse us, library users, when you want us to use "dunders".
Bob: "Now that we have that cleared up, maybe we can standardized how we should say www: double-u, double-u, double-u, dubya-dubya-dubya, dub-dub-dub, triple-dub, wuh-wuh-wuh....."
I had always hoped that "sextuple-you" would catch on. It's just so suggestive, and less than half the syllables. ;-)
As for the ambiguity of double-scores at one or both ends, how about "dunder foo" for __foo and "dundunder init" for __init__? It's got alliteration and recursion going for it, if nothing else!
Graham: I've been advocating "wub wub wub" as the pronunciation, but "sextuple-yoo" is wonderfully obscure -- yet entirely accurate :-)
Graham:
> how about "dunder foo" for __foo and "dundunder init" for __init__?
I kinda like "dunder" and, simply, "dundun".
(For www, I'm a huuuge fan of "many-u".)
I do just what Chris does: "under-under init" means "__init__". I rarely ever need to refer to something like "__x" because I just don't use leading-double-underscore-without-trailing-double-underscore. But when I do, I pronounce it "underscore underscore ex" -- the abreviation from "underscore underscore" to "under under" implies trailing as well.
Urban Dictionary and Python Wiki entries :)
Since the use of underscores has well defined syntactic and semantic meanings i fail to see why can't we use that, i.e. i use:
"private foo" for _foo
"hidden foo" for __foo
"special foo" for __foo__
...or alternatively...
"foo hook" for __foo__
I think its cleaner this way.
At baypiggies "magic" has been suggested for this. So, "magic init" means "__init__", etc. I'm not sure he originated this, but I remember Drew Perttula advocating this.
Alex Martelli used dunder in his talk on python design patterns - at about 18:00.
I also kinda like "dunder" and, simply, "dundun".
So finally what is it said now?
Today, after nearly 12 years, I should say that your creation proved to be life-saving for many programmers.
Thanks for naming __init __ as 'DUNDER init'.
Bob's link for some reason is dead, so I did a bit of excavation to find what he was referring to. Funnily enough, "dunder" was suggested independently, 12 minutes apart, on the same thread:
And then:https://mail.python.org/pipermail/python-list/2002-September/155836.html
Mark Jackson, Thu Sep 26 15:27:16 EDT 2002:
https://mail.python.org/pipermail/python-list/2002-September/157561.html
Tim Hochberg, Thu Sep 26 15:39:14 EDT 2002:
Add a comment: