Live data from Hacker News

5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

codereviewdoctor.medium.com

11–20 of 339 posts

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#11
Literally the second item in the "Zen of Python" (https://www.python.org/dev/peps/pep-0020/):

Explicit is better than implicit.

And yet, s = ["one", "two" "three"] will implicitly and silently do something, that is probably wrong most of the time.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#13
As a comparison, in Ruby

  puts "a" "b" == "ab" # true
and

  puts "a"
    "b" == "ab"
prints "a" with "b" == "ab" evaluated to false and discarded. This could create bugs as with Python. However

  ["a"
     "b"] == ["ab"]
is syntax error at the beginning of the second line. The parser expects a ] It would evaluate to true if it were on one line.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#14
post #12

I am a bit in shock. Accidental string concatenation. Python just lost a lot of reputation in my brain.

Misspelling a variable on the lhs of an assignment just causes a new variable to be created with the new name. That's a lot worse in my book.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#15
post #8

The removal of implicit string concatenation was proposed for Py3k[1], but was rejected. [1] https://www.python.org/dev/peps/pep-3126/

The rejection notice seems completely counter intuitive to me. How is adding a plus "harder" compared to removing a foot gun?

> This PEP is rejected. There wasn't enough support in favor, the feature to be removed isn't all that harmful, and there are some use cases that would become harder.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#16
post #4

This seems like not a big deal. It’s a common mistake and is in 5% of repos but it’s not causing major damage. And there’s no evaluation of importance as to whether these instances are in test files or non-critical code. Packages are big and can have hundreds or thousands of files. It could be that if these mattered, they would have been detected and fixed. A good example for unit tests and perhaps checking to see if…

5% of 'released' software is quite a lot, more importantly it's a class of errors that definitely should not exist. This is a 'bug' in the language effectively there just isn't any real upside.

Python has a few of these things, which is really sad.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#17

I really like the idea of automated code review tools that point out unusual or suspicious solutions and code patterns. Kind of like an advanced linter that looks deeper into the code structure. With emerging AI tools like Github Copilot, it seems like the inevitable future. Programming is very pattern-oriented and even though these kinds of tools might not necessarily be able to point out architectural flaws in a co…

Consider that you may be describing a compiler. Typos are not generally a problem in statically typed languages with notable exceptions such as dictionary key lookups etc.

Even without static typing, argument length verification etc. can be done with a suitable compiler. In python we are left chasing 100% code coverage in unit tests as it's the only way to be certain that the code doesn't include a silly mistake.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#18
Not in Lisp! ("foo" "bar") and ("foobar") are lists of length 2 and 1, respectively.

(Python copies some bad ideas from C. Another one is having to import everything you use. It seems that since Python is written in C, its designer took it for granted that there will be something analogous to #include for using libraries, even standard ones that come with the language.)

Implicit string literal catenation is tempting to implement because it solves problems like:

   printf("long %s string"
          "nicely breaks up"
          "with indentation and all",
          arg, arg, ...)
and if you're working in a language which has comma separation everywhere, you can get away with it easily.

There are other ways to solve it. In TXR Lisp, I allow string literals to go across multiple lines with a backslash newline sequence. All contiguous unescaped whitespace adjacent to the backslash is eaten:

  This is the TXR Lisp interactive listener of TXR 273.
  Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
  TXR needs money, so even abnormal exits now go through the gift shop.
  1> "abcd \
      efg"
  "abcdefg"
If you want a significant space, you can backslash escape it; the exact placement is up to you:

  2> "abcd\ \
      efg"
  "abcd efg"
  3> "abcd    \
     \ efg"
  "abcd efg"
  4> "abcd    \ \
               efg"
  "abcd     efg"
  5> "abcd    \ \
     \         efg"
  "abcd              efg"

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#19
post #4

This seems like not a big deal. It’s a common mistake and is in 5% of repos but it’s not causing major damage. And there’s no evaluation of importance as to whether these instances are in test files or non-critical code. Packages are big and can have hundreds or thousands of files. It could be that if these mattered, they would have been detected and fixed. A good example for unit tests and perhaps checking to see if…

I mean, if you’re ultimately going to combine the list into a string anyway it’s no big deal.

Along those lines. I wonder how many of these come from ad-hoc file path handling instead of using pathlib.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#20
post #3

tl;dr: Python concatenates space separated strings, so ['foo' 'bar'] becomes ['foobar'], leading to silent bugs due to typos. I've been bitten by this one at work, and can't help but think it is an insane behaviour, given that ['foo' + 'bar'] explicitly concatenates the strings, and ['foo', 'bar'] is the much more common desired result. edit: This also applies to un-separated strings, so ['foo''bar'] also becomes ['f…

It's a holdover from C, where implicit string literal concatenation is very useful in the preprocessor.
Post reply on HN