9

Prompted by the recent-ish question How to scramble a word, keeping first and last characters the same? (JS), and today's MSE post about it: Question closed as off-topic after following suggestion in Meta.

I assume we closed this question because it was focused on why a specific piece of code did not run fast enough, which is normally a StackOverflow question. Based on this user's meta post, it is now retroactively obvious that the user was more interested in improving the algorithm than in JS-specific optimizations, and had reason to believe his question would be accepted here.

While it's probably too late to undo the damage (judging by the user's displeasure with us), it does seem like it wouldn't have been terribly difficult to edit the question into one focusing on the algorithm rather than the code. I was honestly a bit surprised to see my name on the list of close voters.

As you can see, the question got good answers, and the answers were about the algorithm rather than the specific code. In other words, the apparent off-topicness of the question did not encourage any off-topic answers (as so often happens with unclear/broad/POB questions).

While the question as written is a better fit for StackOverflow, it's so easy to edit it into a good fit for Programmers that I think we messed up on this one.

tl;dr:

Whenever we see a question about fixing/improving code that can easily be interpreted as asking us to suggest a better algorithm, should we edit it to focus on the algorithm instead of closing it as off-topic?

7

Stating that a question about code performance being off-topic here / belonging on Stack Overflow is inherently wrong. Those types of questions should be posted here ("software architecture and design", "algorithm and data structure concepts") or Code Review ("Performance"). My philosophy on migration is that we should assume that the person posted it on the correct Stack Exchange. As such, we should provide answers within the context of our community, focusing on design and algorithm improvements. I do think that it's very much OK for language-specific questions, as detailed design decisions are driven by the language - some things that make sense in C don't make sense in Java and things that make sense in either don't make sense in JavaScript.

I think that we (all of us, especially those power users and everyone with edit rights - myself included) need to be better at reading between the lines and err on the side of caution. If we see a new post that may be construed as off-topic here, we should edit (or leave clear and specific comments) to bring out the aspects that are on-topic for us before answers are posted. This will provide better guidance to new users as to the type of questions we accept and hints to potential answerers as to the kinds of answers we want.

My tl;dr: Yes, edit questions to better fit things that are on-topic for us. That doesn't mean that you shouldn't also vote to close to prevent answers, especially if a discussion is needed.

6

While the answers in the question were in reasonable P.SE style, I had trouble with this particular question.

At its core, its asking for someone to read it and profile it, and yes, debug it too (for a minor bug).

The answer that the OP edited into the question was pure code.

Algorithm questions are ok. But I believe that once you start asking for 'make this code faster' the balance of the scale tips to one of the sites that focus on code rather than algorithms.

As written, the question appears to be one that would have accepted code only answers. Thus a key part (I believe) in getting it to be a good P.SE question is to rewrite it so that it describes the algorithm used (fortunately neither of the answers are too picky about the code).

6

I made an edit attempt to focus the question to being one of the best algorithm approach that would result in the least amount of operations worse case. I also reopened it, it was close to being reopened anyway by the community.

The OP did provide code which is allowed for context, as long as the question and answers address the algorithm and pseudo code instead of the code itself. The accepted answer approaches this as an algorithm question and not a code question so the edit I feel is a good one. I also notified the user on Meta.SE about this change for input.

Pseudo code is preferred on questions like this, but merely the existence of code in a question or answer does not mean it is unsalvageable.

6

Whenever we see a question about fixing/improving code that can easily be interpreted as asking us to suggest a better algorithm, should we edit it to focus on the algorithm instead of closing it as off-topic?

Yes, I think so, but only if

  • it can easily be interpreted as asking us to suggest a better algorithm (which is, I guess, not the case for the majority of fix-my-code requests here om Programmers)
  • the problem solved by the algorithm is not too trivial or specific to the asker, so it has at least a slight potential to be useful for someone else

IMHO the second point is debatable for the word scrambling question you linked to.

  • I agree with this. My anecdotal experience suggests must are more "plz fix my code!" but since definitely are "this is my code I'm trying to do X." – enderland Dec 22 '15 at 15:23

You must log in to answer this question.

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