Live data from Hacker News

Python's “disappointing” superpowers

lukeplant.me.uk

81–90 of 264 posts

Re: Python's “disappointing” superpowers

#81
post #73

Metaprogramming does not require dynamic types, but this post seems to equate them. As far as I can see all this could be done in e.g. Java (and probably is). IME this kind of "magic" very quickly loses its appeal when you have to debug it. The author's idea of libraries wrapping this stuff up so users don't have to care about it just doesn't pan out at all in my experience.

LISPs are the quintessential metaprogramming languages, and they learnt the lesson of "use macros sparingly and only as the last resort" very early on.

I mean, you aren't wrong. But most of what they learned was "step debugging is hard in the presence of macros." And step debugging has largely been tossed out of the window in many modern setups. Just look at Java's "stream" apis. I swear they did what they could to replicate the LOOP macro.

Re: Python's “disappointing” superpowers

#82

I maintain Python code bases for a living, and feel that the language has simply been pushed too far. Static typing in Python doesn't give you the advantage of actually static typing and even IDE support is -- well it's not terrible, just not great. The thing is, once we go through all this static typing exercise in Python, we get no performance advantages, and the whole thing seems bolted on, with worse semantics th…

I also maintain a large python codebase at work, typing makes things simpler. For example using pydantic 90% of serialization code just goes away. Mypy eliminates a large number of bugs. Also when working with multiple people in the same codebase typing makes intent so much clearer. The type system itself is not perfect but it's a clear improvement of not having it at all.

Re: Python's “disappointing” superpowers

#83
post #75

All these features are nice and stuff... But they are often runtime features... At compile time Python doesnt tell you wether a program is correct. Which is fine for small programs or small services. But any big system is written in python is really hard to maintain without LOTS of unit tests... Static typing, compile time checks just win in the long run. And with languages like kotlin you still have all the advantag…

What does "compile time" even mean for Python?

Re: Python's “disappointing” superpowers

#84
post #81
post #73

Earlier quoted context omitted.

LISPs are the quintessential metaprogramming languages, and they learnt the lesson of "use macros sparingly and only as the last resort" very early on.

I mean, you aren't wrong. But most of what they learned was "step debugging is hard in the presence of macros." And step debugging has largely been tossed out of the window in many modern setups. Just look at Java's "stream" apis. I swear they did what they could to replicate the LOOP macro.

I am very rarely concerned about debugging my usage of Java streams, and step debugging works fine in the context surrounding them.

Re: Python's “disappointing” superpowers

#85

Earlier quoted context omitted.

That's also true of Typescript, which has been wildly successful and taken over the javascript ecosystem. The main advantage of types is that it makes your code more maintainable by adding guardrails. You'll still possible run into issues at runtime and they're not perfect, but they're better than not having types at all.

Typescript really rarely feels bolted on to JavaScript. That also has to do with typescript introducing new syntax to JS.

There's very little new syntax added by TS

Re: Python's “disappointing” superpowers

#86

Metaprogramming does not require dynamic types, but this post seems to equate them. As far as I can see all this could be done in e.g. Java (and probably is). IME this kind of "magic" very quickly loses its appeal when you have to debug it. The author's idea of libraries wrapping this stuff up so users don't have to care about it just doesn't pan out at all in my experience.

I also strongly dislike the idea that static type systems are only being added to Python because spoilsports from other languages are forced to use Python and don't want to. Not true. That's especially strange considering Python is one of the only traditionally dynamic languages that has mostly led it's own static typing system, joined mainly by just PHP in that regard. Why does it not support features like kwargs? Dunno. TypeScript has no trouble supporting tons of JavaScript patterns you could never do in other languages, even C# from which it is heavily influenced due to its heritage, and TypeScript is a fully separate effort from JS.

On the contrary, static typing in Python is still extremely nice to have. When I was at the peak of my Python career, I had a bug where I changed the return type of a function to be a tuple, and somehow unit tests missed one of the worst possible invocations, leading to an awful failure that occurred after a payment was processed but before actually completing the task, causing it to be retried repeatedly. To be clear, like any failure of this nature, it is one caused by many different problems, and we employed many different solutions; we started paying attention to test coverage, we began using MyPy (it was still quite new; this was also in Python 2 so it needed type erasure compilation among other things) and we made our payment processing logic more robust to prevent processing the same payment twice even in the case of everything else (like retry logic) failing to stop it again. But the thing that sucks is, fairly simple type inference without any additional type annotations could've detected that sort of bug without a potential for false positives.

So I feel like it's silly the way that some dynamic language proponents feel like static typing systems on top of dynamic languages is all from outsiders. On the contrary, the relative weakness of MyPy is actually what ultimately made me quit using Python, and if I had to use it today, then yes, of course I would opt for the highest degree of type safety, as a primary concern above being "pythonic." I like pretty code, but I like correct code more.

Sometimes this does prevent "better" solutions from working, but in my opinion nearly 100% of the time that this is the case, it's because:

- The type system in question is not sufficiently advanced to express the types elegantly.

OR

- The approach is inherently not safe and probably not a good idea. Like patching the request object inside of middleware in Django, for example.

I think TypeScript proves that with a sufficiently advanced type system, even arguably bad ideas can be type safe. For example, the ability to express dotted object paths safely in modern TypeScript is pretty impressive, and lets you map out older JS that does this accurately, but in general that seems like an unnecessary trick that will just make your code slower at runtime for the slightest terseness improvement over alternatives, lacking a language with sufficiently advanced metaprogramming.

The thing is though, eventually this thought process comes true. If a given programming language community winds up bleeding members who are moving on due to the lack of better static type checking systems, then the people left will invariably be much more likely to be against static type systems.

Re: Python's “disappointing” superpowers

#87

Metaprogramming does not require dynamic types, but this post seems to equate them. As far as I can see all this could be done in e.g. Java (and probably is). IME this kind of "magic" very quickly loses its appeal when you have to debug it. The author's idea of libraries wrapping this stuff up so users don't have to care about it just doesn't pan out at all in my experience.

Isn't the C preprocessor a type of metaprogramming?

Re: Python's “disappointing” superpowers

#88

Earlier quoted context omitted.

Could you give an example of a type of application where typing is a hindrance?

Not a hindrance but I work with image data a lot. Usually what comes in is any kind of Numpy array and what comes out at the end is either statistics or a Numpy array. I try to type hint everywhere I can but I feel stupid doing so because all I do is work with arrays. Maybe I’m not proficient/knowledgeable enough though so take it with a grain of salt.

If it's truly "any" kind of Numpy array typing won't help much there I agree.

But often it can be helpful to know the shape of the input and the shape of the output. Eg are we working with a 2D,3D or ND array.

Before 3.11 it was not simple (possible?) To type this. But https://peps.python.org/pep-0646/ makes it possible. If somewhat clunky on the definition side.

Re: Python's “disappointing” superpowers

#89
post #66

Earlier quoted context omitted.

The benefits of typing for certain kinds of applications . Many people in the Python community simply aren't writing those kinds of applications. They're writing applications where typing is not a benefit, it's a hindrance, so they don't use it, and Python makes that easy.

Could you give an example of a type of application where typing is a hindrance?

I did a fairly detailed breakdown regarding the Python library Parsy: https://lukeplant.me.uk/blog/posts/python-type-hints-parsy-c...

This is not to make the general claim "Typing is a hindrance in parsing applications", or anything close. It's saying "the current static type system(s) available in Python would have made this Python library much worse".

Re: Python's “disappointing” superpowers

#90

Metaprogramming does not require dynamic types, but this post seems to equate them. As far as I can see all this could be done in e.g. Java (and probably is). IME this kind of "magic" very quickly loses its appeal when you have to debug it. The author's idea of libraries wrapping this stuff up so users don't have to care about it just doesn't pan out at all in my experience.

Isn't the C preprocessor a type of metaprogramming?

[deleted]
Post reply on HN