News for hackers. Stuff that matters.
Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by colpabar on Friday January 07, 2022 @01:04PM (#29842422)
I was going to comment something like "who would even use this?" and then I remembered that I have in fact used that feature :) It's a somewhat "nice" way to write long strings and keep the code from getting too wide. I never did it inside an array, but I found breaking up a long string into smaller ones and wrapping them in parens without a comma was convenient, for things like error messages.

But that's just what comes with a hyper flexible language like python. You can do lots of things in lots of different ways, but you can also screw things up just as easily, and your IDE won't tell you because technically it's valid code.

Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by oaiey on Friday January 07, 2022 @01:09PM (#29842515)
I completely get that. That is a very nice feature for building DSL or libraries with special needs. But it makes the overall language very dangerous.

Is this "operator" overloadable on each type in Python?

And that scares me a lot. I think I have to reevaluate my position towards Python.

Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by housecarpenter on Friday January 07, 2022 @03:16PM (#29844155)
It's not really an operator. It's part of the syntax of string literals. "foo" "bar" is an alternative way of writing the string literal "foobar". If foo is not a string literal, foo "bar" is invalid syntax.
Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by oaiey on Friday January 07, 2022 @04:59PM (#29845405)
Okay... So it is not a implicit operator. That is good. Some small reputation points are regained.

Thanks.

Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by silisili on Friday January 07, 2022 @01:10PM (#29842524)
Why not just use plusses? Or perhaps a join func, which would accomplish the same.

I get the use case as you described it, but it just seems like minimal effort to accomplish and have some semblance of explicit/safety.

Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by dnautics on Friday January 07, 2022 @01:13PM (#29842563)
or if that's the use case, require the whitespace to include a \n or \r\n... It's not like python doesn't have significant whitespace already.
Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by ErikCorry on Friday January 07, 2022 @01:23PM (#29842712)
That wouldn't fix most of the cases highighted by the tool in the article.

So strange that Python has completely different syntax from C, but they chose to copy this obscure syntactic feature _even though they have the plus operator on strings_.

Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by BeetleB on Friday January 07, 2022 @02:41PM (#29843717)
Heh. I use it all the time the way you do and didn't realize this is alien to many developers (no one in my team every complained about it).

It's common in some languages and used the way you use it. I looked in PEP8 and it seems they don't discuss this.

I think it's a perfectly valid use case, but clearly there are two camps to this. If this is so contentious, I would recommend PEP8 be revised to either explicitly endorse it as a way to split long lines or to explicitly discourage it and recommend the + operator instead.

Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by shultays on Friday January 07, 2022 @01:13PM (#29842566)
You could have the same behavior by enforcing + operation in between

  mylongstring = "hello" +
    "world"
No idea if python's way of indentations allows this but sounds like it should
Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by ReleaseCandidat on Friday January 07, 2022 @01:19PM (#29842658)
No, it doesn't:

    mylongstring = ("hello" +
       "world")
or, without `+`

      mylongstring = ("hello"
       "world")
Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by fragmede on Friday January 07, 2022 @01:26PM (#29842753)
Use \

    mylongstring = "hello " \
      "world " \
         "my " \
     "name " \
    "is"*
Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by BeetleB on Friday January 07, 2022 @02:37PM (#29843671)
The use of \ is discouraged in Python. From PEP8:

> The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.

Re:5% of 666 Python repos had comma typo bugs (inc V8, Tenso... by contravariant on Friday January 07, 2022 @07:29PM (#29847078)
See I knew Python just wants to be more like lisp.