I've noticed a lot of questions essentially asking this:
"Here's some code, am I doing this the best/right/most efficient way?"
(for example: How to prevent repeating code)
I'm curious if these are on-topic, and if not, what's the proper action?
I've noticed a lot of questions essentially asking this:
"Here's some code, am I doing this the best/right/most efficient way?"
(for example: How to prevent repeating code)
I'm curious if these are on-topic, and if not, what's the proper action?
Of course every question needs to be evaluated on its own merits, and not all questions of the same form will have the same problems, but there are generally two things to look out for when you see a question that is like that.
The most likely is that it's just going to be too broad. This isn't necessarily the case, but usually there are just so many aspects of a code snippet that could each be evaluated independently that one can't expect a realistically scoped answer to completely cover all of them, nor do we want questions that collect a ton of answers each evaluating something different.
Another possibility is unclear, if it isn't clear what should be optimized, or by what metrics "best" is measured. Sometimes it's clear in context, sometimes it's explicitly stated, and sometimes the question is just unclear for not having it.
Note that there is an entire site devoted to questions of this form: Code Review. They do have standards (such as stating what metrics are to be evaluated) but there's a good chance that questions of this form that don't belong on SO can be altered in order to belong there.
Close for primarily opinion based or off-topic
point them toward https://codereview.stackexchange.com/
Could this snippet of code be written more efficiently?