It's rare to come by a speaker like Brandon Rhodes. I've learned so much from this single individual throughout the past decade of working with Python. Thanks Brandon!
Hmm... += on strings has been optimized for a long time and is generally O(n)... I know the myth that it's O(n**2) persists, but it hasn't been true since 2.6 (maybe 2.5). At least for CPython, it is special-cased. Might not be in PyPy. Teaching people to avoid += for strings should have gone away a long time ago.
the problem with "+", "+=" is that it has to create a copy of the string for each addition operation and that's the reason you should use string interpolation
If you really want to squeeze out performance from your computer, then you really should not be using Python in the first place. Use C++ for performance (or C, if you're like Linus Torvalds and hate C++).
Well you certainly don't have to take my word for it: "A string is generally understood as a data type and is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding." (en.wikipedia.org/wiki/String_(computer_science))
Strings in Python are *not* just an array of bytes. They are implemented as an array of bytes, but so is every type in every programming language on a (modern) computer: some number of bytes. Strings in C are *just* an array of bytes that ends in a NUL, but they aren't *just* an array of bytes in Python, they are an array of bytes *with an abstract interface on top*.
It's rare to come by a speaker like Brandon Rhodes. I've learned so much from this single individual throughout the past decade of working with Python.
Thanks Brandon!
what a great talk! thank you!
The parentheses tax is something I'm fully willing to pay for the savings in braces that Python gives me. :)
bytearray vs str reminds me of Java's StringBuffer vs String.
Hmm... += on strings has been optimized for a long time and is generally O(n)... I know the myth that it's O(n**2) persists, but it hasn't been true since 2.6 (maybe 2.5). At least for CPython, it is special-cased. Might not be in PyPy. Teaching people to avoid += for strings should have gone away a long time ago.
the problem with "+", "+=" is that it has to create a copy of the string for each addition operation and that's the reason you should use string interpolation
Yes += is O(n)... and what happens when you add O(n) operation inside an O(n) loop (which was the case in the presentation)?
everything is arrays
If you really want to squeeze out performance from your computer, then you really should not be using Python in the first place. Use C++ for performance (or C, if you're like Linus Torvalds and hate C++).
Thanks for the tip, i'll just spend another 2 years mastering c++ and then maybe I'll get a working programm.
bytearray isn't a mutable string. It's not a string. It's an array.
Miles Rout A string is an array of bytes.
No
Well you certainly don't have to take my word for it: "A string is generally understood as a data type and is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding." (en.wikipedia.org/wiki/String_(computer_science))
Strings in Python are *not* just an array of bytes. They are implemented as an array of bytes, but so is every type in every programming language on a (modern) computer: some number of bytes. Strings in C are *just* an array of bytes that ends in a NUL, but they aren't *just* an array of bytes in Python, they are an array of bytes *with an abstract interface on top*.