is Python obsolete?
is Python obsolete?
Posted Dec 9, 2017 14:22 UTC (Sat) by FLHerne (guest, #105373)In reply to: is Python obsolete? by HelloWorld
Parent article: Python data classes
There have been a *lot* of languages, almost every problem will have been solved somewhere. The approach of "absorb all the solutions from other languages" leads to C++ or PHP where you have five ways to do everything, none of the constructs fit together well, and it's impossible to have a clean syntax because all the symbols are taken and the new things don't fit pre-existing patterns.
Note -- this proposal doesn't need *any* new syntax, it's just a new standard library module. You could import it in any older version of python3 at least, and I'm sure there'll be such a backported version available. It's not as if Python coders have been missing this functionality, we've just been using 'attrs' and other third-party libs that do the same thing.
--
Parallelism is, as you say, the major Achilles' heel of Python currently. The GIL does make code a lot easier to write and reason about, but it's a nuisance if you really need to run actual Python statements on multiple cores. That's not actually as common a problem as you might think, because both of those requirements need to exist:
- For UIs, network-handling code etc., you need asynchronous code but don't really care if it runs interleaved on the hardware. That's easy now with the async/await statements.
- For maths/scientific/machine-learning code, it would be daft to do the heavy calculations in any interpreted language. There's a huge range of lower-level libraries that can do that (often on the GPU) with good Python bindings, and they drop the GIL while doing that work and/or use parallelism internally, so such things do scale fine across cores.
- For web servers, it's nice to use Python for everything; no cheating and calling out to libs from other libraries. In that case, however, you're handling hundreds of unrelated requests, so each one can have its own process and GIL and again it scales fine across cores.
--
On your specific questions:
> why retain the arbitrary distinction between statements and expressions
- It keeps the parser simple, and helps avoid people writing inscrutable code. Statements that would make sense as expressions already have such a version (comprehensions, lambda).
> Why limit lambdas to a single line?
- Because a lambda is just a function definition, but one that's an expression so it can be written inline. Who wants multi-line functions defined inline? Particularly, who'd want to read that sort of code?
IIRC, Guido's said he wouldn't add 'lambda' at all given another chance.
> Why limit "comprehension syntax" to a fixed number of built-in types (lists, maps and iterators, iirc) when it can easily be generalized to support all sorts of things?
- The generator form already *does* generalise like that. `Zep(foo for foo in bar)` lets you construct arbitrary classes with a comprehension and no intermediate container. Sure, `[foo for foo in bar]` is shorthand for `list(foo for foo in bar)`, but all of () {} [] are used already.
