2019-06-24
The convenience (for me) of people writing commands in Python
The other day I was exploring Certbot,
which is more or less the standard and 'as official as it ever gets'
client for Let's Encrypt, and it did something that I objected to.
Certbot is a very big program with a great many commands, modes,
options, settings, and so on, and this was the kind of thing where
I wasn't completely confident there even was a way to disable it.
However, sometimes I'm a system programmer and the particular thing
had printed a distinctive message. So, off to the source code I went
with grep
(okay, ripgrep),
to find the message string and work backward from there.
Conveniently, Certbot is written in Python, which has two advantages here. The first advantage is that I actually know Python, which makes it easier to follow any logic I need to follow. The second is that Python programs intrinsically come with their source code, just as the standard library does. Certbot is open source and I was installing Ubuntu's official package for it, which gave me at least two ways of getting the source code, but there's nothing like not even having to go to the effort.
I was going to say that this is intrinsic in Python being an interpreted language, but that's not necessarily the case; instead, it's that way for both cultural and technical reasons. Java is generally interpreted by the JVM, but that's Java bytecode, not Java source code. Javascript is interpreted from its source code, but people who ship Javascript often ship it in minimized and compacted form for performance reasons, and in in practice this makes it unreadable (at least for my purposes).
(And then there's WebAssembly.)
Another cultural aspect of this is that a lot of commands written
in Python are written in relatively straightforward ways that are
easy to follow; you can usually grep
through the code for what
function something is in, then what calls that function, and so on
and so forth. This is not a given and it's quite possible to create
hard to follow tangles of magic (I've sort of done this in the
past) or a tower of classes inside
classes that are called through hard to follow patterns of delegation,
object instantiation, and so on. But it's at least unusual, especially
in relatively straightforward commands and in code bases that aren't
too large.
(Things that are part of a framework may be a different story.)
PS: Certbot is on the edge of 'large' here, but for what I was looking for it was still functions calling functions.
PPS: That installing a Python thing gives you a bunch of .py
files
on your filesystem is not a completely sure thing. I believe that
there are Python package and module distribution formats that don't
unpack the .py
files but leave them all bundled up, although the
current Wheel format is apparently purely for distribution, not
running in place.
I am out of touch with the state of Python package distribution,
so I don't know how this goes if you install things yourself.