Liste des Groupes | Revenir à cl c |
On 20/06/2024 11:34, David Brown wrote:I haven't given an opinion, no - I am trying primarily to give facts here. This is simply the way Python works, and if it did things differently, it would be a very different language. So I am not sure it makes sense to give an opinion on this aspect of Python alone.On 19/06/2024 23:51, bart wrote:[Discussing Python]
You haven't given an opinion. I think this is an unnecessary aspect of it, which also makes it harder to optimise, and to reason about.Pretty much everything can be assigned to (the only exception is reserved words). Because every user identifer (even if declared with def or class or module) is a variable.>
The concept of "variable" in Python is quite different from that of C. You can pretend they are similar for very simple Python snippets, but then you will end up thinking there are lots of arbitrary rules for when assignment and function parameters are by value or by reference. It is better to think that all "things" in Python are anonymous reference-counted objects on the heap. When it looks like you have a variable, you actually just have a named reference to such objects. Imagine it more like your "variables" are all "void *" pointers or references, while all other types and structures are malloc'd. These references have no type information - but the objects they point to are all strongly typed. And the objects have reference-counted garbage collection.
My languages have perhaps a dozen categories of identifiers, known at compile-time, which include variable names. Python has only one, a 'variable'. It mean this is possible:I seem to remember you getting really worked up about C programmers using the same identifier for structs and variables!
def F(n): return n + 1
...
F = 42
....
F(x) # will not work when F is 42
They include the features they think will be useful and will fit well with the language, yes. Surely that's not surprising?>And /then/ they include the feature! I've long given up keeping track.
Neither Python nor C++ throws in "every feature they can think of" - for both languages, there is a long process of proposals, discussions, testing, and consideration of the impact on the rest of the language, existing code, and possible future language features, before a feature is included.
Both have mutable elements. Neither allow arbitrary attributes (so impossible to misspell member names). And if the FFI demands it, pointers to structs or ints can be passed.You can do all this with Python. I showed you how to have structures with mutable elements - and immutable structures, and structures with or without the ability to add new fields.
But Python even then completely disregarded performance. In the 1990s, if you wrote a loop like this:So your complaint now is that newer versions of Python have made some common tasks more efficient? There's no pleasing some people.
for i in range(1000000):
....
it would actually create an object with a million elements so that you could iterate along it. It sounds absolutely crazy, and it was.
Later they added xrange() which didn't do that, and later on 'xrange' morphed into 'range'.
Les messages affichés proviennent d'usenet.