Dunder

Monday 22 May 2006

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.

tagged: » 21 reactions

Comments

[gravatar]
Antonio 4:52 PM on 22 May 2006

I like this so much it is now officially in theTabblo hacker's style guidelines.

[gravatar]
Chris McDonough 5:25 PM on 22 May 2006

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".

[gravatar]
Alan Green 6:57 PM on 22 May 2006

Brilliant. Will you be writing it up as a PEP? ;)

[gravatar]
Bob 8:11 PM on 22 May 2006

"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)

[gravatar]
Bob 8:19 PM on 22 May 2006

Correction: __Dunder__

[gravatar]
Bob 8:20 PM on 22 May 2006

Geez, Louis.... I meant __Mifflin__

[gravatar]
Pete Lyons 8:42 PM on 22 May 2006

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.

[gravatar]
Ned Batchelder 9:37 PM on 22 May 2006

It looks like I'm not the coiner of "dunder". D'oh! Still a good idea (maybe even a better one)!

[gravatar]
Ben Finney 10:08 PM on 22 May 2006

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?

[gravatar]
Bob 2:15 AM on 23 May 2006

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.....

[gravatar]
Dagur 8:40 AM on 23 May 2006

that's user_id__exact in Django (only one dunder)

[gravatar]
zgoda 2:55 PM on 23 May 2006

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".

[gravatar]
Graham 4:25 PM on 23 May 2006

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!

[gravatar]
Ben Finney 1:06 AM on 24 May 2006

Graham: I've been advocating "wub wub wub" as the pronunciation, but "sextuple-yoo" is wonderfully obscure -- yet entirely accurate :-)

[gravatar]
Filip Salomonsson 11:44 AM on 24 May 2006

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".)

[gravatar]
Michael Chermside 8:53 AM on 25 May 2006

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.

[gravatar]
daniel 12:58 AM on 2 Jun 2006

Urban Dictionary and Python Wiki entries :)

[gravatar]
requiem 12:24 PM on 9 Nov 2007

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.

[gravatar]
David Montgomery 4:11 PM on 9 Nov 2007

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.

[gravatar]
Bill Mill 3:38 PM on 27 May 2008

Alex Martelli used dunder in his talk on python design patterns - at about 18:00.

[gravatar]
Margareta 1:00 PM on 16 Dec 2009

I also kinda like "dunder" and, simply, "dundun".

Add a comment:

name
email
Ignore this:
not displayed and no spam.
Leave this empty:
www
not searched.
 
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.