On 1 June 2018 at 22:57, Chris Angelico <ros...@gmail.com> wrote: > How will a method be worse than a standalone function? Please explain > this.
Because the standalone function already exists (in the textwrap module). There's nothing wrong with adding string methods, but where they don't add anything that can't be done already within the core language and stdlib, then they have to get past the hurdle of "status quo wins". > A method is a lot easier to discover than a stdlib module > function, If you're using Google or the python docs, I'm not sure it is easier, and I'm certain it's not a *lot* easier. If you're using the REPL, then yes, finding a string method is easier than hunting out a random function that takes a string argument. > which is in turn IMMENSELY more discoverable than anything > on pypi. True. But discoverability of anything gets a lot better when it's more widely used, so if this is a common need, I'd hope that discoverability of any approach would improve over time. > If you dislike adding features to a language on the basis that it > makes the language harder to learn, remember that you instead force > one of three even worse options: > > 1) Messy code because people unindent inside their source code, > creating wonky indentation (which Python usually avoids) > > 2) Forcing readers to look up the third-party module you're using > before they can understand your code > > 3) Forcing readers to look up your ad-hoc function before > understanding your code. > > All of these make it harder to understand your code, specifically > BECAUSE the language doesn't have the requisite feature. Well-written > language features are good, not bad, for readability. You missed the option that's actually the case: 0) Expecting readers to look up a stdlib module in order to understand your code. And you aren't comparing like with like, if this were a string method users would have to look up that method, just as much as they would have to look up a stdlib function. But honestly, if someone needs to look up the definition a function or method called "dedent", then either there is something more than normally complex going on, or they are not a native English speaker and this is the least of their worries, or something similar. No-one is saying a method is *worse* than a standalone function - they are just saying it's *not sufficiently better* to justify creating a string method that replicates an existing stdlib function. Paul -- https://mail.python.org/mailman/listinfo/python-list