Since the introduction of soft keywords
, I have been wondering more and more whether some of the existing keywords could be made soft keywords.
One benefit of being a soft keyword is, it can be a valid identifier. And one of the existing keywords that I would really like to be able to use as an identifier is class
. class
is a very frequently used term, and is meaningful in all sorts of ways. Since it is almost unavoidable, many programmers find different spellings to solve this, such as:
regex used
language:Python /[^a-zA-Z_]{alternate class spelling}\b/
I could not find a proper regex to search for cls
but I assume it is quite high.
While it is not a debilitating issue, it does kill the charm in many cases. e.g. in fastHTML it breaks the 1:1 mapping with HTML:
@app.route("/")
def get():
return (Title("Hello World"),
Main(H1('Hello, World'), cls="container"))
other potential candidates
I am not opposed to making more existing keywords into soft keywords, e.g. I would find the following quite useful as well:
if
:do(something, if=predicate)
async
:some_func(*args, async=True)
from
:case_converter_factory(from="pascal", to="snake")
in
:find(needle, in=haystack)
I am advocating for only class
here, because that is the one I find myself needing most often. And I donât feel thereâs any chance of it being confusing if it were made a soft keyword.
In terms of backwards compatibility, the only concern in my opinion is existing educational material. Here, I am a bit unsure whether the tradeoff is worth it. If this change were made, I donât think out-of-date educational material will have any adverse impact in practice.