What does HackerNews think of wtfpython?

What the f*ck Python? 😱

Language: Python

#31 in Python
I don't find that so bad. They look complicated but behave as expected, and would only be a problem if you inherit a code base from a lone wolf without common sense.

Python has plenty of warts[1], but I don't think the syntax is one of them (yet). Some of the more concerning warts:

    # Mutable defaults in function parameters.
    def fn(arg=[]):
        arg.append(1)
        print(arg)

    fn() # [1]
    fn() # [1, 1]
    fn() # [1, 1, 1]

    # Loop variables are shared across executions.
    lambda_list = [lambda: print(i) for i in range(5)]
    for fn in lambda_list: fn()
    # 4
    # 4
    # 4
    # 4
    # 4

    # Iterating over an exhausted generator yields an empty list.
    numbers = (i for i in range(5))
    assert 1 in numbers
    print(list(numbers))
    # []
    # I hate this one because it could have easily been an error, it's 
    # hard to track down, and lots of stdlib functions return generators.


    # Chained operators can sometimes be very unintuitive.
    should_be_ascending = True
    assert 1 < 2 == should_be_ascending
    # AssertionError because it was interpreted as
    # `(1 < 2) and (2 == should_be_ascending)`
[1]: https://github.com/satwikkansal/wtfpython
See https://github.com/satwikkansal/wtfpython

"Mutating the immutable" is my personal favourite - the second line of code fails with an exception despite having already succeeded:

    >>> t = ([1, 2], 5, 6)

    >>> t[0] += [3, 4]
    TypeError: 'tuple' object does not support item assignment

    >>> print(t)
    ([1, 2, 3, 4], 5, 6)
I've never been a fan of the decision to have `a += b` sometimes do `a = a + b` and sometimes update `a` in place. My objection was initially just due to theoretical inelegance - but this code shows that decision directly causing a concrete problem.
See also related:

"What the fuck Python?"

https://github.com/satwikkansal/wtfpython

Along with the corresponding HN discussion:

https://news.ycombinator.com/item?id=31566031 (450 points, 153 comments)

In a similar vein you may like "WTF Python: Exploring and understanding Python through surprising snippets":

https://github.com/satwikkansal/wtfpython

HN thread: https://news.ycombinator.com/item?id=26097732 (163 comments)

PS: found with a site I'm building: https://discussions.xojoc.pw/?q=Understanding+Python+through...

Python had their smearing campaign claiming TIOOWTDI against Perl's TIMTOWTDI, and dubious claim's of sigils (`@$`) hurt readability. But once Python had the ecosystem going, it brought back `@`, `{}`, numerous `_`, fanciful `:=`. And, of course, there always is more than one way to do it in Python.

Python's "easy to use" is just a lie, https://github.com/satwikkansal/wtfpython

The common lisp CFFI module is nothing short of Python's.

But, I know, people hate to put their `(` in front of their function names, and people hate to omit `,` between there function arguments.

Yes, of course.

BTW, that's not the "biggest" WTF feature; it's just my favorite. There's a long list of WTF features here:

https://github.com/satwikkansal/wtfpython

Otherwise, I agree, it's a pretty good going :-)

Here's some more:

* https://dabeaz-course.github.io/practical-python/Notes/Conte... by David Beazley --> covers foundational aspects of Python programming with an emphasis on script writing, data manipulation, and program organization

* https://python-patterns.guide/ by Brandon Rhodes --> inspired from Gang of Four book

* https://github.com/satwikkansal/wtfpython (this is more of a collection) --> Exploring and understanding Python through surprising snippets

Also, my ebook Python re(gex)? covering re and regex modules is free to read online: https://learnbyexample.github.io/py_regular_expressions/ (pdf/epub is paid, available via leanpub/gumroad)

> It's the combination of a really wide range of skill and a really big difficulty assessing that skill from just the resume.

If you know what skills you are looking for (hint: lots of companies and recruiters don't), this is not actually that hard.

For every skill, there are questions that should be really easy to answer for everybody with expertise, but are suprising/hard to answer for everybody who pretends to have knowledge. This enables you to check quite quickly whether the claimed skills are actually there or not.

For example, the easier sections in

> https://github.com/satwikkansal/wtfpython

might give you a hint for topics that most seasoned Python programmers should know blindfolded while they are probably rather surprising for anybody with shallow Python knowledge. Let the applicant explain how they came up with their solution for, say, some of the problems, and you will see rather fast whether the claimed skills are actually there or not.

I'm not so sure. A couple times I've shown WTFpython [0] to a co-worker, who after spending a bit of time skimming through it mentions that they finally understand a bug they had when they were learning python. And which entry it is is usually different between them.

[0] https://github.com/satwikkansal/wtfpython

This repo may be helpful to you: https://github.com/satwikkansal/wtfpython

It’s a collection of snippets to explain behaviors that may be considered unexpected.

> Python is a good language because it's readable and writeable.

https://github.com/satwikkansal/wtfpython