News for hackers. Stuff that matters.
Re:Python is not a great programming language by ben509 on Saturday October 12, 2019 @06:05PM (#21236698)
Most of these are pretty dumb, but there are some inadvertently good points.[5]

> The philosophy of "one correct way to do things."

I miss those days. T_T

> A huge ecosystem of good third-party libraries.

Python also has a huge ecosystem of huge ecosystem managers, which is less than ideal.

> Half of each Django app is super().__init__( * args, * * kwargs)

Haven't used Django, but if I were providing a suite of classes people were extending, I'd provide lifecycle hooks.

Using super().__init__ is not a syntax problem as much as it's a semantics problem, because it's so fragile.[1]

> Too many magic __double-underscore__ methods and properties that you have to just memorize.

Yup, dunders are the ugly consequence of duck-typing. Maybe Python could tuck them away in some kind of traits system.

> Too many other weirdo bits of magic syntax, like [list comprehensions].

But the Python syntax is weird:

    [elem for outer in iterable for inner in outer]
Which is essentially:

    for outer in iterable:
        for inner in outer:
            result.append(elem)
It's backwards. The PEP[2] doesn't explain why, but looking at the JS syntax[3] it does seem less worse.

Other weirdo syntax:

    while some_condition():
        if check_a_thing(elem):
            break
    else:
        print("never broke from loop")
The meaning sort of makes sense if you think of `while` as an extension of `if`.

But I would have expected this:

    for x in y:
        do_a_thing()
    else:
        handle_empty_case()
Or, really, a more descriptive keyword.

> You have to cast your data back to a list/tuple after using enumerate() and map().

I thought it was the coolest thing when generators got full support in py3k, but it's horribly broken.

This does not raise an exception:

    x = list(some_generator)
    y = list(some_generator)
y will be empty, which is a completely silent failure. The same is true for iterators. And everyone's been bit by strings being iterable[4].

Sometimes it's useful to do this:

    i = iter(some_generator)
    x = next(i)
    for elem in i:
        ...
But Python should not:

1. make iterators be iterable.

2. allow spent generators to be reused without exception.

3. make strings be iterable.

(All of which could be bypassed with a method call when you really want that behavior.)

> foo['bar'] returns a KeyError, so you have to do foo.get('bar')

LOL, only javascript devs could not have noticed the hours they've spent tracking down the source of some mysterious undefined. Python definitely got this one right.

[1]: https://fuhm.net/super-harmful/

[2]: https://www.python.org/dev/peps/pep-0202/

[3]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

[4]: https://mail.python.org/pipermail/python-3000/2006-April/000...

[5]: Wait, am I talking about the OP or this comment?

Re:Python is not a great programming language by rsinger87 on Saturday October 12, 2019 @06:36PM (#21236849)
I wrote this package to provide model lifecycle hooks (similar to Rails callbacks) because I didn't like the frequency that my codebase was overriding __init__(): https://github.com/rsinger86/django-lifecycle

Django's ecosystem (mainly DRF and django-filters) makes it very productive for me, but I find Django core to be lacking for developer ergonomics in certain areas.

Re:Python is not a great programming language by ben509 on Saturday October 12, 2019 @06:48PM (#21236901)
That's exactly what I was imagining. You can tell it's a nicely designed base class because the dunders are all tucked away so the only thing left is actual logic.