8 comments

  • madprops1 minute ago
    Great new way to write blog posts!
  • PyWoody3 minutes ago
    Whenever I read people's takes about Python on HN, I always feel like I'm using an entirely different language.
  • dwdz1 hour ago
    I&#x27;m not a fan of f-strings.<p>I feel like 90% of new Python features in the last 10 years just increased language complexity without any benefit.
    • ForceBru36 minutes ago
      I&#x27;m a HUGE fan of f-strings and I think they should be added to more or less every language in existence. (This is just to show how much I like f-strings, not to be taken literally) `printf`-style format strings seem outdated: why use format strings when I can put my variables IN THE STRING? I want the result of `x+y` to be put {HERE} in this string. Well, just write `&quot;This is here: {x+y} blah&quot;` — it makes perfect sense and immediately lets me see what the resulting strings generally look like.<p>Basic usage is a no-brainer: write your string, put variables or short expressions in curly braces, add `printf`-style format specifiers after the colon. This is also great because it&#x27;s a natural extension of `printf`-style format strings.<p>Of course you can write complicated and confusing f-strings. But then you can write complicated and confusing... anything, really. Many programming languages have extremely weird quirks and cases where basic syntax can be transformed into an unreadable monstrosity, like C syntax for pointers to functions and arrays.<p>Sure, this increases the language&#x27;s complexity, but you don&#x27;t have to use all of it to reap the benefits.
    • ajrouvoet32 minutes ago
      It is baffling to me that Python seems to insist on reinventing language features and coming up with the most incomprehensible of designs. The whole dataclass and serialisation ecosystem comes to mind, as well as the evolution of typing.<p>The language exposes so much of its internals that even if the design were consistent, the ecosystem of (buggy) libs and tools makes it inconsistent.
      • LPisGood31 minutes ago
        PKL files and the entire multiprocessing paradigm is one of the worst experiences I’ve ever had with a programming language feature. Surely there has to be a better way.
    • analog3148 minutes ago
      Indeed, and I get that one can ignore those features (I do), but finding them in existing code or having the AI coding agent use them diminishes the &quot;easy for beginners&quot; aspect.
      • orf21 minutes ago
        Are f-strings not easy for beginners? What would you prefer instead?
  • cocodill4 minutes ago
    do not get the funny part of the pythons string.
  • phyzome21 minutes ago
    Goofy edge cases aside, I think f-strings are great.
  • xg152 days ago
    <i>here&#x27;s a valid f-string:<p>&gt;&gt;&gt; f&#x27;{&#x27;}&#x27;}&#x27; &#x27;}&#x27;</i><p>Huh? I remember learning the rule that you can&#x27;t nest quotes inside fstrings if they are the same kind (unlike in bash) - e.g<p><pre><code> f&quot;{mydict[&quot;foo&quot;]}&quot; </code></pre> would be a syntax error, but<p><pre><code> f&quot;{mydict[&#x27;foo&#x27;]}&quot; </code></pre> or<p><pre><code> f&#x27;{mydict[&quot;foo&quot;]}&#x27; </code></pre> would be valid.<p>The reason being the same like for the rstring weirdness: The lexer comes first and identifies the string literal, then for fstrings, the python parser is invoked again for each {...} expression to parse it.<p>This is unlike other nested expressions, which are already split up by the lexer and then parsed in one go.<p>Did that change at some point?
    • xg152 days ago
      Update: They really changed it! (in python 3.12)<p>There was a PEP about it:<p><a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;78388333&#x2F;nested-quotes-in-f-string-with-python-3-12-vs-older-versions" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;78388333&#x2F;nested-quotes-i...</a><p><a href="https:&#x2F;&#x2F;docs.python.org&#x2F;3.12&#x2F;whatsnew&#x2F;3.12.html#pep-701-syntactic-formalization-of-f-strings" rel="nofollow">https:&#x2F;&#x2F;docs.python.org&#x2F;3.12&#x2F;whatsnew&#x2F;3.12.html#pep-701-synt...</a>
  • TZubiri29 minutes ago
    Been using python for almost 10 years. I never use any of the funky strings.<p>Instead of reading like 10 PEPs for f strings, I just use the + operator on strings and backslash escaping, big whoop.
    • PyWoody5 minutes ago
      Instead of 10 PEPs, you could read one helpful cheatsheet: <a href="https:&#x2F;&#x2F;www.pythonmorsels.com&#x2F;string-formatting&#x2F;#cheat-sheets" rel="nofollow">https:&#x2F;&#x2F;www.pythonmorsels.com&#x2F;string-formatting&#x2F;#cheat-sheet...</a>.
    • andai11 minutes ago
      age = 32<p>print(f&quot;Age: {age}&quot;)<p>Thus concludes the lecture on f-strings.
    • smohare16 minutes ago
      [dead]
  • smitty1e1 hour ago
    Whenever I&#x27;m building a JSON document, I revert to the old %s syntax just because it&#x27;s more tidy than an f-string.
    • folkrav1 hour ago
      Am I understanding that you’re building JSON with string interpolation? If so any special reason you wouldn’t build a dict and json.dumps() it?