I have a piece of code, I don't know if it creates the error or not. Can I ask Stack Overflow if I wrote the code correctly? I mean if the usage of a class is correct.
-
I think you can ask about the problem which your code solves, and include your own solution to the problem in your question, people will try to come up with better ideas eventually.– mehmetseckinCommented Jul 1, 2015 at 8:55
-
16How about you test it yourself?– user1228Commented Jul 1, 2015 at 16:03
-
3You have asked 163 questions on SO... you may want to review some of your unanswered questions to see if they should be on code review instead.– Display Name is missingCommented Jul 1, 2015 at 19:31
-
1I suspect that the way you phrased the question does not reflect what you wanted to ask ... Sounds like you are trying to ask "if it is ok to particular usage pattern of class/library is correct" rather than "is my code correct" which sounds pretty wrong to start with.– Alexei LevenkovCommented Jul 1, 2015 at 20:00
5 Answers
Lots of people do ask this kind of stuff on Stack Overflow. If the code is generating an error, it is probably suited, otherwise there is https://codereview.stackexchange.com/ which might be appropriate.
-
5It might be suited, if it is reduced to an MCVE. You are quite right codereview is probably suited when it's his code and he's reasonably certain it's correct. Commented Jul 1, 2015 at 17:23
-
9If you don't know if code is correct than it is not suitable for CR. Commented Jul 1, 2015 at 19:56
Lets be honest: the true way of finding out if a particular piece of code produces problems or not is to apply proper engineering strategies. Unit testing, debugging, logging, profiling.
So if you have done all that and you still cannot figure it out, then yes ask away. Because at this point you have proven that you know what you're doing, you have something to show for your efforts and you have a problem which is apparently deeply rooted and hidden; such a nasty problem will probably attack more people and we'd be a richer community to know how to trap it.
But lets be even more honest: most people ask these kinds of question without making much effort to try and root it out themselves; the question gets shifted to SO or any other site "to save time". And then you'll find your question quickly gets close-voted.
-
6If you've unit tested your code, debugged through it, have good logging, have profiled it, etc., and can't find any problems, would you not simply assume that the code is correct/working, rather than assuming that it's probably incorrect in a way you haven't been able to find, necessitating asking on SO?– ServyCommented Jul 1, 2015 at 14:25
-
I read the question as "there is an error, but I'm just not sure it is in a particular piece of code or not".– GimbyCommented Jul 1, 2015 at 14:33
-
10OP needs to learn how to be precise and diligent before expecting the problem can be solved (or expecting that they can do their job). The fact that this two-line question is itself ambiguous is not a good start. Commented Jul 1, 2015 at 19:31
If you are talking about a logic error then yes you can ask questions about it. Make sure to include the least amount of code to generate the issue. What the inputs should be, what the output is that you are getting and the output is that you should be getting.
-
Yes, the details are key. Sometimes people want to ask "is my code correct?" without even thinking about the details themselves (never mind explaining them in their SO question). That can end up being a waste of time for everyone.– Dan GetzCommented Jul 2, 2015 at 3:04
If it creates an error then it is potentially not correct, so it's OK to ask about it.
It could be exposing a bug in a library or API which makes it a good question even if the error is not in your code.
That asking question about code is legitimate is evident, as in the FAQ this possibility is explicitly contemplated:
"When asking a question about a problem caused by your code, you will get much better answers if you provide code people can use to reproduce the problem. That code should be…
…Minimal – Use as little code as possible that still produces the same problem …Complete – Provide all parts needed to reproduce the problem …Verifiable - Test the code you're about to provide to make sure it reproduces the problem"
Therefore, you have to report a PROBLEM, and that problem must be minimal, well documented, reproducible.
If you are not reporting a problem or did not do research, that question should be considered inappropriate.