The wonderful KatieKodes wrote a piece on making her minimum viable build tutorials. The process includes staying as far away as possible from the magic keywords inherent in site generators, CMSs, and systems of all types. Words like:
Most tutorials use the generic variable name
file for reading/writing examples. Something like:
with open('input.txt', 'r') as file: # do something with `file`
That's always bugged me. First, I try to make meaningful names. Second,
file feels like it should be a reserved word. It's not, but it feels like it should be. Anyways, what she did was preface it with an underscore.
with open('input.txt', 'r') as _file: # do something with `_file`
I love it.
In python, the leading underscore is used to let developers know the variable is meant for internal use. That's great and all, but I love the visual distinction it makes about not being a keyword.
Combining that and Katie's piece got me thinking about using underscores to de-magic keywords. Instead of using leading underscores (which have implicit meaning in Python), I was thinking of a trailing ones. Turns out, this is not an original thought. It's explicitly listed in Python's PEP 8 style guide.
But, after playing with them, I'm not sure I like the look:
Feels like I didn't finish writing the variable name. It also feels like there's meaning associated with it. Like it's a type of keyword on it's own. Not unreasonable since double underscores in things like
__init__ are meaningful.
So, what if we use the underscore, but in a different place? What if we put it after the first character? We get something like this:
Or, maybe before the last one:
Of course, you could also do every letter:
That looks nicer, but it's super tedious to type.
So, what about prefacing with a letter:
a even provides a little meaning. Or, at least, it's not inaccurate even if it's redundant from a naming perspective.
Or, maybe, use
I really like that one.
Whatever the case, I hadn't thought about these options before.
Definitely something to play with.