35

What's the best way to create and name a primary source question to redirect the high volume of Python questions asking why calling a string operation doesn't change the string.

Naming this something friendly to new users and new-user searches will be crucial, because a person searching for "String method XYZ doesn't work" will never find "Why are Python strings immutable?" (and even if they somehow could, its title and language won't seem related to answering their issue).

Every day now we're getting new ones, all these duplicates are just clogging the site, in many cases these could be closed-as-duplicate immediately:

The reference question sometimes used e.g. Why are Python string immutable? Best practices of using them is not suitable for this purpose because the name is not intuitive, and it has way too much information for just this specific common issue. New users don't need a bloody essay on immutability and language design philosophies; they just need the one-liner "you need to actually assign the output of the string function/method call to something, it doesn't work just calling it in-place".

UPDATE: Per my answer below, my suggestion is let's use Why doesn't calling a Python string method do anything unless you assign its output? ; I picked this and renamed it from "python string replace" since its answer is short and to-the-point, and it already has upvotes.

11
  • 11
    In theory, after some time all reasonable query terms will have been asked & marked as a duplicate of the reference question, and people searching for those terms end up at the reference question through the duplicates... Mar 1, 2015 at 3:15
  • In JavaScript, the canonical duplicate is just called "Replace method doesn't work" though it could be "Why doesn't the replace method change my string variable?"
    – Bergi
    Mar 1, 2015 at 15:26
  • 2
    The reference question doesn't mention any of the built-in string methods like replace, lower, etc. It would probably be better if there was an answer added to it that better explained the issue with those, so it could actually be used as a duplicate target. Mar 1, 2015 at 16:50
  • 4
    The Python chat room maintains a list of canonical topics; we'd very much welcome discussion on the topic in that room.
    – Martijn Pieters Mod
    Mar 2, 2015 at 9:33
  • @MartijnPieters: that's nice, but never knew it existed till now! Why not integrate question suggestions automatically with Close>Duplicate functionality?
    – smci
    Mar 2, 2015 at 9:43
  • 1
    @smci: I'm not sure what you mean by that. I have asked for [search improvements when looking for duplicates]( Boost duplicate post search results by incoming link count) where often-linked duplicates get a boost in the search results but that hasn't yet come to anything.
    – Martijn Pieters Mod
    Mar 2, 2015 at 10:04
  • @MartijnPieters: ok well I just managed to boost the ranking of that question in the duplicates list from #7 to #3 just by using it 5 times in votes-to-close. So I think that's our solution.
    – smci
    Mar 2, 2015 at 10:05
  • It's not just Python, Java has the same problem.
    – user253751
    Mar 3, 2015 at 3:47
  • @immibis: sure, but please keep the Java canonical duplicates separate.
    – smci
    Mar 3, 2015 at 9:04
  • Not a python person - is X = sometext valid or does it have to be X = "sometext"? If the latter then the posted question should be updated.
    – dav_i
    Mar 3, 2015 at 10:43
  • @dav_i We're in the process of fixing the issues in the question (look at the comments on the answer below). Mar 3, 2015 at 14:02

2 Answers 2

18

Let's use Why doesn't calling a Python string method do anything unless you assign its output?

(I picked this and renamed it from "python string replace" since its answer is short and to-the-point, and it already has many upvotes)

13
  • 1
    If this question is chosen as the canonical it's contents must be gutted and replaced with a less careless asked question.
    – usr
    Mar 2, 2015 at 16:22
  • @usr: well tell us what solution you propose? Want to pick a different question? Rewrite that question? Wait for yet another question?
    – smci
    Mar 3, 2015 at 2:09
  • 1
    I edited the question and the answer to fit better. I'm not sure if you can do two edits together like that, so it may not pass. Pretty radical edits too. Worth a shot.
    – Carl Smith
    Mar 3, 2015 at 2:38
  • @CarlSmith: ok but your edit reads more like an answer, not a question... gotta make it feel like a question (maybe simply "What am I doing wrong?" rather than "Why do I need to assign the output?")
    – smci
    Mar 3, 2015 at 2:41
  • Changed it to What am I missing here?.
    – Carl Smith
    Mar 3, 2015 at 2:43
  • Well, I would at least remove all those paths and leave only a simple two-line code snippet. This question is not being used anymore by its author. It is to be repurposed.
    – usr
    Mar 3, 2015 at 8:59
  • Go ahead and change as you see fit, guys.
    – smci
    Mar 3, 2015 at 9:00
  • I don't know Python but I know the gutting procedure. Or should I say surgery? Crap-ectomy.
    – usr
    Mar 3, 2015 at 9:38
  • At this point I think the question has been rewritten enough to be a good, generic duplicate target. Mar 3, 2015 at 14:11
  • The title you've changed it to doesn't reflect the actual question (i.e. the title includes the answer, whereas the question does not). Might I suggest doing title = title.replace(" unless you assign its output", "")?
    – dav_i
    Mar 3, 2015 at 14:31
  • @dav_i: I don't know, that's up for debate here, I asked how the canonical source should be named...?
    – smci
    Mar 3, 2015 at 14:38
  • Tadeck's answer in that question is not broad enough - need to make it clear this is nothing specific to .replace(), it's true for any of the ~20 Python string methods. So, I still can't accept this answer.
    – smci
    Apr 1, 2017 at 9:02
  • Three years later: I accepted my own answer, and rewrote Why doesn't calling a Python string method do anything unless you assign its output? for clarity and brevity.
    – smci
    Jan 24, 2018 at 22:18
0

I have no problem with the same answer many times for many different questions. I do, however, have a problem with the same question many times. Thankfully they do have the "duplicate question" marker. The best way to handle many of the same question is to just start marking them as such.

To address what you've said above in a direct manner; a custom tailored answer to why "lower" does one thing and "replace" does another, even if they're the same sort of answer or the same answer phrased in different ways should be ok. They really are different questions even if the mechanics behind them are the same.

12
  • 6
    "They really are different questions even if the mechanics behind them are the same." No, they really are the same question; people expecting the method to change the object instead of returning a mutated value. They could trivially solve the question themselves (or at least arrive at a better question) by either reading the docs or spending 2 minutes in the repl. Also, if a user fails to understand how or why their question is a dupe that doesn't mean it's not a dupe. And if custom tailored answers to all special snowflake cases are ok that just means you could do away with dupes completely.
    – l4mpi
    Mar 2, 2015 at 9:43
  • 2
    @l4mpi: we were all new users once, and many issues each of us encountered we were not able to trivially solve by reading the docs or spending 2 minutes in the repl
    – smci
    Mar 2, 2015 at 10:55
  • 2
    @smci speak for yourself - when I started with python, I was able to solve such issues by myself through experimentation. Furthermore, SO is for professional and enthusiast programmers whom I would expect to experiment or at least read the documentation; especially in the case of python where it's extremely accessible (pydoc str.replace -> there's your answer). I can't stand the mentality of "just answer if the question is about strip instead of replace, the user can't be expected to make the mental leap to find out it's the same issue" which is expressed in this post.
    – l4mpi
    Mar 2, 2015 at 11:05
  • @l4mpi: (I did solve many issues by myself, and I read the doc). I agree with you in objecting to wheaties suggestion here, but because it pollutes and diminishes the whole duplicate/redirect thing, which I think should be our primary motivation, not punishing perceived laziness.
    – smci
    Mar 2, 2015 at 11:22
  • @smci why not both? Answering every crap question instead of closing them (as duplicates, or as something else that gets deleted) pollutes and diminishes SO as a whole. But this is a by far broader discussion than the problem at hand here...
    – l4mpi
    Mar 2, 2015 at 11:28
  • @l4mpi ok well my tl;dr is If you see a bunch of duplicate questions in burning need of a primary source, then create one by picking the best one you can find and suitably retitling as necessary, to be more general. (or, fail that, write the answer yourself)
    – smci
    Mar 2, 2015 at 12:23
  • @l4mpi I disagree strongly with the "not same question." If that were the case then almost half of dba.stackexchage would be reduced to a single question.
    – wheaties
    Mar 2, 2015 at 12:48
  • 1
    @wheaties I've only been to dba.SE a handful of times so I can't comment on that, but note that different communities can have different standards for duplicates, just as there are different standards for other types of closure. Doesn't change the fact that these questions are useless - while I can agree it makes sense to keep some of them around as signposts, I don't see any convinving argument for answering all of them; they should IMO be closed with extreme prejudice. Otherwise, I could ask a question about replace and after you answer it ask the exact same question about translate...
    – l4mpi
    Mar 2, 2015 at 14:34
  • 1
    @wheaties there seems to be sufficient disagreement and subjectivity that we have a basis for an even more basic MSO question 'What are some objective standards for classifying "same question/not same question?"' (I searched MSO and don't find any suitable reference for that.)
    – smci
    Mar 3, 2015 at 3:39
  • 1
    @smci an excellent point. I think that is the largest stumbling block on this debate, though I admit from the voting it seems rather one sided and clear what the community thinks.
    – wheaties
    Mar 3, 2015 at 14:17
  • @wheaties: the community needs to actually articulate what those standards are, probably by means of example
    – smci
    Mar 3, 2015 at 14:20
  • 3
    It doesn't matter that an asker wouldn't have been able to find the master question; if they knew how to find the answer, they wouldn't have asked the question at all. There's no significant difference between "The answer is directly below your post" and "...is at the other end of this link on the same website". There are two goals: 1) get this person a solution to their problem 2) maintain a high-quality, easily-searchable archive of the solutions for future readers. Closing as duplicate fulfills both those goals; having answers spread across multiple questions hinders the second.
    – jscs
    Jul 30, 2015 at 19:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .