I'm feeling some hesitation on flagging an accepted answer on the basis of either "Newer, more efficient" or "poses a risk", and would like to have further elaboration on the criteria for flagging accepted answers when other answers might be slightly more efficient or slightly less risky.
I'm considering the answer here regarding putting data into a CSV format. The accepted answer is correct in that it solves the OP's specific question (hence accepted). However, as indicated in the comment, and the other answer to this question, there is a more robust way of solving the problem that should work in general. Using StringIO
is probably more efficient, but for small files, not by enough to be a big deal. Similarly, using CSV is a bit safer in terms of handling things that can mess up CSV formatting. But, in my opinion, neither are deal-breakers for the use case exemplified in the question.
In my mind, the accepted answer is not "outdated" in that it does solve the OP's problem, even though there are better ways to skin this cat.
Though the accepted answer is sub-optimal relative to the other one, I thought that the point of having separate "accepted" and "upvote" options was precisely to preserve the information on which answers were actually used; so I'm particularly suspicious of flagging accepted answers.
var found = "find Waldo".indexOf("Waldo") !== -1;
because I knowindexOf
returns -1 when the string is not found. Maybevar found = ~"find Waldo".indexOf("Waldo");
is more "efficient" but it's far too clever for its own good. Of course now I'd use"find Waldo".includes("Waldo")
and call it a day :).