Why we don't use underbars
mpm at selenic.com
Thu May 5 21:24:10 CDT 2011
On Thu, 2011-05-05 at 20:48 +0200, Sune Foldager wrote:
> On Thu, May 05, 2011 at 01:38:49 -0500, Matt Mackall wrote:
> >On Thu, 2011-05-05 at 12:12 +0200, Sune Foldager wrote:
> >> On Thu, May 05, 2011 at 10:59:26 +0200, Benoit Boissinot wrote:
> >> >On Wed, May 4, 2011 at 11:42 PM, Sune Foldager <cryo at cyanite.org> wrote:
> >> >> # HG changeset patch
> >> >> # User Sune Foldager <cryo at cyanite.org>
> >> >> # Date 1304544568 -7200
> >> >> # Node ID 7f2e8ed280a6b1c272ec080fd2ca2315a0d264e7
> >> >> # Parent 39f6e0127ff15c5ad82b989d387402ec83ea30d4
> >> >> revlog: support reading general deltas
> >> >>
> >> >> Parentdelta (per entry) takes precedence over generaldelta (per revlog).
> >> >>
> >> >> diff --git a/mercurial/revlog.py b/mercurial/revlog.py
> >> >> --- a/mercurial/revlog.py
> >> >> +++ b/mercurial/revlog.py
> >> >> @@ -28,10 +28,11 @@
> >> >> REVLOGNG = 1
> >> >> REVLOGNGINLINEDATA = (1 << 16)
> >> >> REVLOGSHALLOW = (1 << 17)
> >> >> +REVLOG_GENERALDELTA = (1 << 18)
> >> >
> >> >Please keep the coding style consistent.
> >> If only it were to begin with... notice we have:
> >> # revlog index flags
> >> REVIDX_PARENTDELTA = 1
> >> REVIDX_PUNCHED_FLAG = 2
> >> REVIDX_KNOWN_FLAGS = REVIDX_PUNCHED_FLAG | REVIDX_PARENTDELTA
> >> ..one has '_FLAG' at the end, all have _'s. And:
> >> REVLOGNGINLINEDATA = (1 << 16)
> >> REVLOGSHALLOW = (1 << 17)
> >> REVLOG_GENERALDELTA = (1 << 18)
> >> REVLOG_DEFAULT_FLAGS = REVLOGNGINLINEDATA
> >> REVLOG_DEFAULT_FORMAT = REVLOGNG
> >> REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS
> >> REVLOGNG_FLAGS = REVLOGNGINLINEDATA | REVLOGSHALLOW | REVLOG_GENERALDELTA
> >> ..some have, some don't. I would prefer using _ in all of them. Thoughts?
> >The standard is: don't use underbars in identifiers. Believe it or not,
> >this standard was conceived with full awareness that there are in fact
> >lots of underbars in the current code. That is the whole point: to get
> >rid of them.
> Yes, lovely. It looks cool with REVLOGDEFAULTVERSION and such; it's not
> like the letters run together or anything ;-).
I'm perfectly aware of that, but I've made a conscious and measured
evaluation that being able to remember that "foo bar baz" is "foobarbaz"
and not "foo_bar_baz" without needing a reference and without getting
runtime errors completely trumps the minor readability nuisance.
Here are the quiz answers:
"has key" -> dict.has_key (now deprecated)
"call tracing" -> sys.call_tracing
"get recursion limit"
"raw input" -> raw_input (only instance in __builtins__)
"get default encoding"
"version info" -> sys.version_info
"api version" -> sys.api_version (compare sys.hexversion)
"path hooks" -> sys.path_hooks
"set debug level" -> set_debuglevel (explain that one!)
But I've actually cherry-picked the rare exceptions here to demonstrate
how arbitrary they are. The vast majority of Python's core avoids
underbars. So if we're going to write in Python, we're going to not use
underbars to minimize the amount of trivia we have to remember. If we
were writing in an environment where underbars was the prevailing
standard (like the Linux kernel), then we'd stick to that.
 Feel free to pick a more readable, shorter, lowercase name for these
 And if you can remember all of them effortlessly, then I suspect you
are also a rare exception.
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel