Hacker News new | comments | ask | show | jobs | submit login

This is a pretty good list of gotchas, but it's important when writing something targeted at beginners to be as precise and clear as possible. Nearly every section here either uses terminology poorly, is slightly incorrect, or has difficult examples.

  Python supports optional function arguments and allows default values to be 
  specified for any optional argument.
No, specifying a default is what causes an argument to be optional.

  it can lead to some confusion when specifying an expression as the default value
  for an optional function argument.
Anything you specify as a default value is an expression. The problem is when the default is mutable.

  the bar argument is initialized to its default (i.e., an empty list)
  only the first time that foo() is called
No, rather it's when the function is defined.

  class variables are internally handled as dictionaries
As dictionary keys, and that's still only roughly correct.

In "Common Mistake #5", he uses both a lambda and array index based looping, neither of which are particularly Pythonic. A better example of where this is a problem in otherwise Pythonic code would be good.

In "Common Mistake #6" he uses a lambda in a list comprehension -- for an article of mistakes mostly made by Python beginners, this is going to make it tough to follow the example.

In "Common Mistake #7", he describes "recursive imports" where he means "circular imports".

In "Common Mistake #8" he refers repeatedly to "stdlib" where he means the Python Standard Library. Someone is going to read that and try to "import stdlib".

Hey, thanks for the great feedback! We agreed with (almost :-) ) all of your comments and have made corresponding mods/corrections to the post. Thanks again!

[Toptal blog editor]

Good changes. One more issue (I believe recently introduced): LEGB ends with "Built-in", not with "Module". It's also good to note in the blog post that it's been updated.

Doh. You sure it doesn't stand for "Mbuilt-in"? ;-)

Again, thanks for the attention to detail. We've fixed this as well.

Just to notice: this text is not targeted at beginners, in my opinion. These are upper-intermediate to advanced level gotchas.

Did they add in "(Note: This article is intended for a more advanced audience than Common Mistakes of Python Programmers, which is geared more toward those who are newer to the language.)" later?

Because it states it right near the top of the article.

That note has been in the post since it was first published.

1, 2, 4, 5, and 8 all seem to me like mistakes only / primarily made by beginners. I can't see an article aimed at primarily intermediate Python users spending time on them.

3 is a really easy mistake to make for anyone (which is why the syntax was changed).

6, 7, 9 and 10 are more obscure, and where I really appreciate this article -- and they definitely can be issues for more experienced Python devs.

Applications are open for YC Summer 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact