Hacker News new | ask | show | jobs
by TBurette 2687 days ago
I like the clean look and the overall way it is presented. The examples using angle brackets (eg.: <list>.append(<el>) ) is highly legible and the one column format is faster to scan.
1 comments

I came here to say exactly the opposite. The angle brackets mean that every single example is a syntax error.

If you are going to write a cheatsheet with samples of Python code, why not write it in valid Python?

This is clearly aimed at beginners as the samples are or very basic things, yet this is going to be confusing to them as they will think that `<list>` is syntax.

Have a look at the Python docs for much better ways of doing this

I think the author of this document is trying to differentiate between types (broad notions of course -- there's no type called 'num' in Python).

The Python docs (example here[1]) on the other hand limit themselves to {}, [] and () to differentiate between dicts, lists and tuples, but doesn't really differentiate between these and the more generalized notions of collections/iterators/element, etc.

As someone who codes in statically typed languages and has an intuitive sense of upcasting / downcasting / contravariance / covariance, this level of precision makes sense to me and enhances my appreciation for Python types.

That said, I've also been writing Python professionally since 2005 so I'm comfortable with not worrying too much about types in Python -- with dynamic typing things just work as long as they have the right shape and behavior.

[1] https://docs.python.org/3/library/threading.html#threading.T...

But he could achieve exactly the same thing by using descriptive variable names without the angle brackets. Admittedly he can't use `list` as it's a built-in but `a_list` or `list_` would be much better than `<list>`.
My personal opinion is that `list_` is among the worst possible variable names (together with `bar` and `foo`). It's non-descriptive, ugly, hard to recognize, looks scary to beginners and maybe worst of all it's easy to forget the underscore when typing.
That's exactly what he's used, but with angle brackets around it. What do you think he should have done instead.
Good point. For list, one could still use the name "lst" and get the point across.