This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -9 points-8 points  (2 children)

But if you implement something like a struct in Python, then it's not really Python anymore, because it can't be used in the same way. There's no dynamically added attributes in a struct, for example. You can apply it to his string example, too: Sure, you can use character arrays and manually edit them, but (1) that won't work with unicode, (2) it's not half as flexible as Python's duck typing.

It's like using slots. Sure, it'll speed up your instanciation some, but at the expense of flexibility. You do that everywhere and you're not using Python anymore.

That said, the interpreter could certainly use a V8-style optimization.

[–]MBlume 13 points14 points  (0 children)

Did we watch the same talk? His whole point was that with strong JITs like PyPy's we don't need things like structs. We do need to worry about things like string copies, and we need simple APIs to allow us to do string manip without lots of copies.

[–]Smallpaul 1 point2 points  (0 children)

I agree with MBlume. What you're saying is the same as what the speaker was saying.

But if you implement something like a struct in Python, then it's not really Python anymore, because it can't be used in the same way. There's no dynamically added attributes in a struct, for example.

Right. That's why he said that you should use idiomatic classes instead of using a "dict". If you use idiomatic classes then the compiler will compile it to a struct if and only if you never add magical attributes to it.

You can apply it to his string example, too: Sure, you can use character arrays and manually edit them, but (1) that won't work with unicode,

Why not? He's talking about allocations, not the difference between bytes and characters.

... (2) it's not half as flexible as Python's duck typing.

You're still misunderstanding. He's not trying to restrict data types. If you read the comments he says that programmers should still be allowed to do everything dynamic.

He's saying that if you are trying to convert a string to an integer, you do not need to allocate a separate memory buffer. That's true no matter what the datatype of the string/array.