Live data from Hacker News

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

codereviewdoctor.medium.com

321–330 of 339 posts

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

#321
post #273
post #99

Earlier quoted context omitted.

The lack of a static type-system is IMO what makes these one-character mistakes very annoying. The compiler can't tell you something is wrong, so you're just left to figure out why things are broken, just to realize it was the smallest of typos.

Fully agreed. If python had a proper static type system, those typos would hardly matter, and you'd have the best of both worlds: Convenient, concise syntax, but still confidence in your code. I say "had a proper type system", but actually it turns out that it does have something like that: When I use python for anything else than a most tiny script now, I use "mypy"[1] which implements static typing according to som…

I’m not clear how a type system would pick up a missing comma in a list of strings, unless the type was specific enough that the contents of the list or the length was encoded in the type.

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

#324
post #292

Earlier quoted context omitted.

The "trailing comma creates a tuple" bug actually comes from a disconnect between what people think defines a tuple (parenthesis) and what really does (comma). I always put parenthesis around a tuple for clarity.

whats the reason for allowing like foo, to be a tuple? why not make this a syntax error? is there a use for single value tuples?

Yes, single tuple values are useful for example for passing to a function which expects a tuple (because it might expect zero, one or multiple values).

The thing is, your example is the way tuple should be defined. The parenthesis are merely allowed (and ignored). Why? I see this as a mistake of language creators. But to be fair, it is difficult to make a perfect language (or anything really), and Python is pretty close imho.

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

#325
post #179

Earlier quoted context omitted.

I love how simple and forgiving Python is for small projects. The "trailing comma creates a tuple" situation comes out of, as far as I can tell, a desire to create maximally convenient syntax in the scenarios where tuples are intended. I think that's great for small code! I just wish that the core team would take that same zeal for a "pythonic" experience with small code and use it to develop more scaled-up systems f…

If you use mypy (as anyone should for any non-hobby Python usage) then Python has one of the strongest type systems available. Optional types, generics, "Any" escape hatches, everything you could want.

> one of the strongest type systems available.

This is simply not true - Python with mypy isn’t even as strong as Typescript, let alone Rust, F#, Haskell and so forth.

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

#326
post #316

Earlier quoted context omitted.

Why should function arguments be delimited by parentheses? We don’t do that in Bash or Objective-C, for example

to be able to detect the difference between "this expression is a function" and "this expression is the result of the computation of a function" the parentheses are not for function arguments, are for "invocation".

Can you show an example of how they could be confused?

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

#327
post #241
post #99

Earlier quoted context omitted.

The lack of a static type-system is IMO what makes these one-character mistakes very annoying. The compiler can't tell you something is wrong, so you're just left to figure out why things are broken, just to realize it was the smallest of typos.

C lets me do this, and doesn't say much about it. char ch_arr[3][10] = { "uno", "dos" "tres" };

What does this do?

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

#329
post #316

Earlier quoted context omitted.

Why should function arguments be delimited by parentheses? We don’t do that in Bash or Objective-C, for example

to be able to detect the difference between "this expression is a function" and "this expression is the result of the computation of a function" the parentheses are not for function arguments, are for "invocation".

> to be able to detect the difference between "this expression is a function" and "this expression is the result of the computation of a function"

If function (or method) arguments don't require parenthesis, referring to (rather than calling) a function/method usually requires quite distinct syntax, so it's quite easy to it apart from a call.

It may not be familiar to people coming from languages where no-parens refers to the function and parens call it, but being clear and distinct and being intuitive to people indoctrinated in contrary syntax are not the same thing.

E.g., in ruby (which has methods but not functions in the strict sense) I can call a method with:

  thing.square # or thing.square()
Or access the corresponding method object with:

  thing.method :square # or, thing.method(:square)
Either of the former options are distinct from both of the latter.

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

#330
post #316

Earlier quoted context omitted.

Why should function arguments be delimited by parentheses? We don’t do that in Bash or Objective-C, for example

to be able to detect the difference between "this expression is a function" and "this expression is the result of the computation of a function" the parentheses are not for function arguments, are for "invocation".

A syntactic feature like this can only be judged in the context of the language. I'm sure there's languages where parentheses around function arguments prevent ambiguity, but there's also languages where it's very unambiguous, or the opposite might be true.

For other examples of languages where invocations don't use parentheses for arguments, OCaml and Haskell. In fact, I'd argue that if they tried to add that feature to those languages (parens around arguments to a function), it'd make things very confusing given the way functions and tuples work.

Post reply on HN