6

I recently was trying to figure out how to do something, and eventually came up with a solution that did work, however the code was quite inefficient and messy. I'm almost positive that there is a better way to accomplish the task, and I am just not thinking along the right lines.

Since I did have working code, I decided to ask my question on Code Review:
Get total count of object's elements and all children objects` elements

Today, however, I came across the following Code Review meta post, which caused me to wonder if the question really belongs on Code Review, or if it would better fit on Stack Overflow:
Why are alternative solutions not welcome?

It's seems like while alternate suggestions, if proposed correctly, can be suggested on Code Review, they are generally not encouraged or wanted.

Stack Overflow, on the other hand, is a platform for asking for complete new solutions of how to do something. The questions, however, usually don't already have working solution without bugs or errors. In the past, I've seen questions that already have a working, but bad solution, closed for not displaying a specific problem or error, or sometimes even as primarily opinion based.

Can the fact that the code is slow or messy be considered a valid "problem"?

Would this type of question be acceptable on Stack Overflow, or does it really belong on Code Review?

7
  • 2
    Does the downvote mean "no, questions like this are not on topic"? I am asking a yes or no question, and not saying "questions like this belong on stack overflow", so I'm not sure what this disagreeing vote means. Can you please explain?
    – Tot Zam
    Commented Aug 24, 2017 at 16:00
  • 1
    These sorts of issues are difficult to specify fully, and SO posters have problems with specifying even simple problems. Example - would a new algorithm be better if it was twice as fast, but only if allowed to use 16 times more memory? If constrained to the same memory, the new algorithm is twice as slow as your original. Do you want it? Commented Aug 24, 2017 at 16:28
  • @MartinJames So would it be okay to ask, "Is there a faster way to do this? I'm okay using more memory."?
    – Tot Zam
    Commented Aug 24, 2017 at 16:34
  • So X comes up with the new method that does use more memory but is claimed to run much faster.. until you test it on your system and find it slower... after time and effort on to-and-fro analysis, X posts: .'what do you mean, you only have two cores? I tested it on my 32-core server and it was much faster'. Commented Aug 24, 2017 at 16:49
  • ..so you go and buy a 32-core server, test it and it's still slower. After time and effort on to-and-fro analysis, X posts: 'what do you mean, your data set has only 5000 records? Obviously, I tested it with 2,000,000 records, and it was much faster'. Commented Aug 24, 2017 at 16:51
  • @TotZam I used a downvote to signify "no, questions like this are not on topic". The way I read it, the real question you posed was Would this type of question be acceptable on Stack Overflow? Commented Aug 24, 2017 at 20:11
  • @silencedmessage Thank you for explaining. I figured that was how users were interpreting the post, but wasn't sure. You comment definitely adds more of an answer than just a downvote.
    – Tot Zam
    Commented Aug 24, 2017 at 20:44

2 Answers 2

7

Are questions asking for alternate, more efficient solutions on topic?

Sort of. If phrased in precisely this way, then no—the question is both "too broad" and too "give me teh codez", which we stridently avoid. However, there are plenty of ways to phrase such a question that would make it on-topic for Stack Overflow.

The purpose of the Code Review site is really, as the name suggests, to review code. Proposals of alternative implementations are welcome, of course, and I've posted many of them there, but only when done as part of a larger effort to review the existing code.

Stack Overflow doesn't work that way. It deals with specific, narrowly-focused problems. You hardly ever want to post your exact code here, and you certainly don't want to post very much of it. Instead, we advise you to create a minimal, complete, and verifiable example. That would never be acceptable on Code Review. Why the difference? Because we don't care about reviewing your code; we care about solving your problem.

Can the fact that the code is slow or messy be considered a valid "problem"?

Yes, absolutely. Both of these are problems that we can resolve here. However, it is rather tricky to write a good, on-topic question about these things because it requires you to be very specific about what you're looking for. (And as Martin James pointed out, askers are rarely very good at being specific.)

You cannot simply say, "How can I make this code faster?" You need to define what "faster" means to you. You would ideally do that by telling us what the performance characteristics of your current code is, giving us sample data that you used to obtain those numbers, and then describing what your target performance is. We get a fair number of performance-oriented questions here, and I personally find them a fascinating break from the drudgery of "debug my code for me"-style questions. There's a lot that can be learned from the answers, with very broad appeal and applicability to a wide variety of situations.

At the risk of it being heavily downvoted by some of the more dogmatic members of Meta, I think this question is a pretty well-asked optimization question. (Full disclosure: I answered it.) It's very specific, in that it's isolated to only a very small bit of code and a clear purpose, which is explicitly presented in the question. The asker also goes on to explain what his thoughts were (i.e., what he tried). Some might trigger a bit at the last paragraph, where he requests "any guidance and assistance", but that's just a turn of phrase. If you read and understand the question, and the relevant technologies, it is not prohibitively broad.

Here's another example, this one taking the highly unusual tact of asking for counter-optimizations. This question was actually the subject of its own uproar on Meta, but I like it and think it represents some of the best of Stack Overflow. (Well, after it was edited into shape; the original version is an example of how not to do it.) It is admittedly somewhat broad, but not broad in a bad way or for any of the reasons that we discourage broad questions.

(Note that neither of the above two cited questions would be remotely suitable for Code Review.)

"Messy" is even more difficult, as it requires that you establish an objective metric for cleanliness (or whatever the opposite of messiness is). This can be done, though, and if done, it would form the basis of a valid, on-topic question for Stack Overflow. Best is to contextualize this in terms of a specific problem that you're having when it comes to improving the code. "My code looks ugly, please rewrite it" will never be an on-topic question. (A good hint is that it isn't actually a question at all.) But I can imagine, in the not-so-distant past, a C++ question being presented with an ugly for loop, asking for a cleaner solution that retains the same behavior, and being answered with a suggestion to use a range-based for loop.

That said, I would recommend not asking one of these types of questions until you become an experienced question-asker. Asking good questions is hard enough; don't take on any additional challenges until you have demonstrated the ability to handle it.

...does it really belong on Code Review?

Please be careful about recommending Code Review to people. I've handled several flags recently from people who asked that their question be migrated to Code Review after being told by some helpful person in the comments that they should have asked it there. In the majority of cases, I've felt compelled to decline. Code Review is not simply a dumping ground for questions that you think might be too "opinion based" for Stack Overflow. Even more so than us, Code Review has very specific standards for what types of questions are on-topic there, and unless you write your question with Code Review's standards in mind, it's exceedingly unlikely that it will meet those standards. Most importantly, you need to be presenting the complete, actual code, it needs to be code that you maintain, and it needs to be code that is working.

1
4

A question about the aesthetics of a solution aren't going to be on topic. That's going to be entirely opinion based.

If you're able to explain what your solution does, how it performs, what your performance requirements are, and how your code doesn't meet them, along with all of the necessary information to reproduce that situation, while also keeping the whole question sufficiently narrowly scoped (namely limiting the question to a small enough portion of the application for the performance evaluations to be reasonable), then it could be on topic. But that's...not easy to do.

5
  • 2
    What do you mean by "aesthetics of a solution"?
    – Tot Zam
    Commented Aug 24, 2017 at 16:03
  • 1
    In the question I linked, I am just asking about a short method, not a whole application. The performance part is more stating that LINQ and .Contains() methods are slow, and not talking about a specific time frame. Based on your answer, I'm still not clear if that question would be okay or not to ask on SO.
    – Tot Zam
    Commented Aug 24, 2017 at 16:09
  • @TotZam Did you explain how well your solution performs, what your performance requirements are, in what ways your solution doesn't meet them, and provide enough information for others to replicate your failed performance tests?
    – Servy
    Commented Aug 24, 2017 at 16:11
  • I agree. Also, if someone simply says "here's what I have, what's a better way to do this?", then that's basically "gimme teh codez," which obviously isn't allowed on SO. Commented Aug 24, 2017 at 22:23
  • @EJoshuaS I don't think that is the same as "I researched how to do something. I came up with a solution. Here is what I have. This is what is bothering me about the code. How can I improve it?"
    – Tot Zam
    Commented Aug 25, 2017 at 0:51

You must log in to answer this question.

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