Live data from Hacker News

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

codereviewdoctor.medium.com

281–290 of 339 posts

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

#281

I can see the value of a lint (if there's a newline without a comma, warn), but concatenating strings by multiplication is the correct thing to do (since it's also used this way in mathematics of parsers). Using the plus operator to concatenate strings is just weird. Think of the usual algebraic properties these operators are supposed to have. "+" always is supposed to be commutative--so "a"+"b" = "b"+"a", if those m…

Juxtaposition is not multiplication in this context - you can't write (2 3), for example, it has to be (2 * 3).

Furthermore, Python already uses * for strings to indicate repetition: ("foo" * 2 == "foofoo").

String concatenation really just needs its own separate operator. & is an obvious candidate, if only it wasn't so commonly appropriated for bitwise AND - which is a very poor use of a single-char operator as it's not something that you need often, especially in a language like Python.

On the other hand, D uses binary ~ for concatenation. That has a neat mnemonic: it's a "rope" that "ties strings together".

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

#282

Earlier quoted context omitted.

> This jaw-droppingly moronic. It can be slightly inconvenient but doesn’t feel moronic to me. It means that except for the built-in functions, everything can be traced to either a definition or an import. Makes tracking code much easier.

Why not import the built-in functions too? The only thing not requiring import can be import. from python import def # now you can def That should be even easier to track things; now you don't have to deal with the difficulty of def not being defined anywhere in your code. It's traced to an import, which is telling you that def comes from python, liberating you from having to know that and remember it.

"def" is not a function. It's not even an identifier.

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

#283

Earlier quoted context omitted.

Why not import the built-in functions too? The only thing not requiring import can be import. from python import def # now you can def That should be even easier to track things; now you don't have to deal with the difficulty of def not being defined anywhere in your code. It's traced to an import, which is telling you that def comes from python, liberating you from having to know that and remember it.

"def" is not a function. It's not even an identifier.

This exercise requires you to imagine a somewhat different Python in which you can (and must) do from python import def if you are to use def.

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

#284
post #268

I can see the value of a lint (if there's a newline without a comma, warn), but concatenating strings by multiplication is the correct thing to do (since it's also used this way in mathematics of parsers). Using the plus operator to concatenate strings is just weird. Think of the usual algebraic properties these operators are supposed to have. "+" always is supposed to be commutative--so "a"+"b" = "b"+"a", if those m…

Which invertible commutative string operation would you choose for + ? This might be nice from a math point of view, but I think users are going to be confused using "string"^3 for repetitions (instead of "string"*3). + and * make too much sense to the unwashed masses. At any rate, explicit is better than implicit.

There is no reason you couldn't use str * str for concatenation and str * integer (or even string * real) repetition.

Well, except if you wanted to support user classes that could duck type as both strings and numbers, which it would make awkward.

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

#285
post #230

Earlier quoted context omitted.

> ...it's pretty tough to argue such languages really shouldn't exist. "Shouldn't exist" is too strong. Dynamic languages that let you create a new variable via assignment shouldn't be used to create non-trivial software. How about that? Scripting languages have a place. That place is 100% in creating quick-and-dirty scripts and tools. Or in doing some kind of one-off data transform (as is common in machine learning…

I've been building non-trivial software in dynamic languages for twenty years. They work great. I'd take a project in a dynamic language with a decent test suite over a project without tests in a statically typed language any day of the week.

> I'd take a project in a dynamic language with a decent test suite over a project without tests in a statically typed language any day of the week.

I'd take the opposite. I've read too many useless tests in python codebases that can be accomplished by a static type checker. "Decent" does a lot of heavy lifting in your comment. And what about a dynamically typed codebase without any tests? I'm sure they exist.

I'd rather dive into a big ball of mud with a compiler that will help point me to my mistakes before I release them, than having to sift through a ball of mud trying to find that mistake with production services flailing.

That all being said I've worked with both types of languages in successful projects. But I prefer the development experience of the statically typed variety.

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

#286
I often use split().

Instead of:

  s = ['a', 'b', 'c']
I'll type:

  s = 'a b c'.split()
For multiline lists where I want to get rid of leading whitespace I'll add lstrip():

  lines = """line 1
             line 2
             line 3
  """.split('\n')
  lines = [line.lstrip() for line in lines]

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

#287
post #230

Earlier quoted context omitted.

> ...it's pretty tough to argue such languages really shouldn't exist. "Shouldn't exist" is too strong. Dynamic languages that let you create a new variable via assignment shouldn't be used to create non-trivial software. How about that? Scripting languages have a place. That place is 100% in creating quick-and-dirty scripts and tools. Or in doing some kind of one-off data transform (as is common in machine learning…

I've been building non-trivial software in dynamic languages for twenty years. They work great. I'd take a project in a dynamic language with a decent test suite over a project without tests in a statically typed language any day of the week.

But a dynamic language needs all the tests a compiled language needs AND type/syntax tests (that are handled by the compiler in a static language).

There are reasons dynamic language (or specifically Python), but I haven't heard one explanation how it helps writing fewer tests.

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

#288
post #162

Most of the "bugs" caught here (including in TensorFlow and in my own project, Xarray) seems to actually be typos in the test suite. This is certainly a good catch (and yes, linters should check for this!), but seems a little oversold to me.

Same :P I'm actually responsible for one of these ( https://github.com/pytorch/pytorch/issues/70607 ), but it's a typo in a list of tests to skip.

A typo in a list of tests to skip means tests are run that are not intended to be run. This can lead to unexpected failures, so in my opinion is not the same as the errors in test suites where tests run with other test data than intended but should still pass.

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

#290

Earlier quoted context omitted.

Complex: consisting of many different and connected parts. Complicated: consisting of many interconnecting parts or elements; intricate. Nothing specifically artificial about either one. Software that is well decomposed is Complex (made of many smaller connected parts). Software that is is poorly decomposed is Complicated (made of many smaller interconnected parts). Connected vs interconnected? Interconnected: connec…

Complicated: this mutha is hard all by itself Complex: we took all of these simple steps, lumped them together, now we have this

Yeah that was what I was trying to say!
Post reply on HN