41 ms·
> Mercurial had the strangest and most non-idiomatic Python I'd ever seen. It's not so bad. We just use a lot of abbreviations, but you get used to them. Ther
by jordigh 7y ago
> Mercurial had the strangest and most non-idiomatic Python I'd ever seen.
It's not so bad. We just use a lot of abbreviations, but you get used to them.
There's also a reason for a lot of the ways it's written: backwards compatibility. We supported Python 2.4 until a couple of years ago. This meant you had to do "x and y or z" instead of "y if x else z" because the ternary operator wasn't available in older releases. This wasn't because we like old software, but because our users do. A data-storage solution needs to be stable over very long periods of time. You don't want to be unable to access your repo because you're on an old machine. A DVCS is too important to force your users to be chasing after the latest release all the time.
Another reason for Mercurial's style is to avoid unnecessary function lookups or calls and other quirks of the Python interpreter. Something as simple as
for x in y:
thing.doit(x)
can have a noticeable speedup if you instead do
doit = thing.doit
for x in y:
doit(x)
because Python just takes a while doing function lookups. Our users notice those milliseconds of difference because they want "hg status" or "hg log" to be nearly instantaneous.
- bipson 7y agoMay I ask why you are even using Python, if you need to work around the language in such ways? These non-idiomatic uses might be shedding a few ms, yet they ruin the readability and maintainability of the code, most of all all tools like 2to3? Why not another (non-interpreted and thus faster) language? One where the idoms work in your favor? Also, no need to support releases from 2004 and having to groan about it.