3 ms·
Syntax is pretty much one of the downsides of Python. Especially the new additions, including f-strings, match-case, type annotations, async-await, data-classes
by crabbone 3y ago
Syntax is pretty much one of the downsides of Python. Especially the new additions, including f-strings, match-case, type annotations, async-await, data-classes etc. The largest downside is that they hugely blew up the language complexity for no tangible gains. It's like you had a crappy bicycle before, but after an "upgrade", you have a crappy bicycle that doubles as a crappy ice-cream maker.
This means that anyone who wants to write a parser for Python from scratch is screwed. The language was garbage before, and writing a parser for Python was already very difficult, but after more junk was added to it, it just became unnecessarily more difficult. So, if you might have had a glimmer of hope to have tools that analyze the source code and do something with it, even as trivial as highlighting... well, there's less and less hope of that happening.
So, OPs complaint about f-string is sort of valid. OP didn't really look for a very bad example though, but bad examples are hard to refine into more concise form. Fundamentally, what sucks about f-strings beyond them being completely unnecessary is the situations where one has to deal with multiple incoherent escaping rules, s.a. when one has to interface with, eg. logging module or string.Template or str.format() or % in general. Another vomit-inducing combo is raw strings combined with f-strings (i.e. building regular expressions through interpolation).
Yet another downside of f-strings is the departure from object-oriented approach. The benefit of str.format() was it being object-oriented, which allowed for extensions in the same way objects can be extended. f-strings are an extension of the language syntax, but Python doesn't have an easy general way to extend its syntax (barring the fact that you can abuse the import system to import altered Python sources s.t. they have desired syntax).
But, again, these disadvantages are hard to present as a one-liner, and for many simple uses of the language, which is the majority of its uses they are inconsequential. Unfortunately, that majority of uses is also transient and contributes nothing back to the language... so, it could be confusing to rely on the majority's opinion when it comes to judging the quality of various language features.
- mixmastamyk 3y agoYou don’t write a parser from scratch, you use the ast module. The rest of this is excessive negativity trying to sound superior while ignoring history. (I even agree about the match statement and walrus, but fstring is a very useful compromise.)
- otherme123 3y agoI'm using walrus a lot, can't find any negative: it's clear what it does, and the code feels cleaner.
- mixmastamyk 3y agoPython already had the “as” and assignment statements so didn’t need three ways to do it. Remember the Zen? (99% of the time walrus is used in “if” or “while” with one expression, which as handles fine.) Also, along with typing contributes to the excessive “colon blow” of modern Python.
- memefrog 3y agoThere's no 'as' in Python if or while statements, only with. >>> if True as a: File "<stdin>", line 1 if True as a: ^^ SyntaxError: invalid syntax
- mixmastamyk 3y agoIndeed. Coulda been.
- michaelcampbell 3y ago> Remember the Zen? Like Django's "explicit is better than implicit... no, wait, hold my beer" magic.
- crabbone 3y agoWhy would I write it in Python? It's the worst language to do that...