11
\$\begingroup\$

In the Help Center, under What topics can I ask about here?, one of the rules currently states:

However, if your question is not about a particular piece of code and instead is a generally applicable question about …

  • Best practices in general (that is, it's okay to ask "Does this code follow common best practices?", but not "What is the best practice regarding X?")

then your question is off-topic for this site.

The analysis by @rolfl reminded me of a question that I had previously voted to close: Using a for-loop instead of sleeping? I nominated that question for closing not because I think though it was too short or that it was a poor question to ask, but rather because I considered it to violate the rule above. Considering that we have been closing similar questions before based on that rule, I thought it would be fairest to apply the rule consistently.

I still believe that if a rule exists, then there should be some consistency in enforcing it. However, after further analysis, I came to the conclusion that it was not a bad question, but rather a bad rule (or at least well intentioned but poorly phrased).

I'd like to clarify the rule to read:

However, if your question is not about a particular piece of code and instead is a generally applicable question about …

  • Best practices in general (that is, it's okay to ask "Does this code follow common best practices?" or "Does this code follow the best practice regarding X?", but not "What is the best practice regarding X?")

then your question is off-topic for this site.

The key point of the rule is to express the mission of Code Review: we review code, and the question must be about your code.

In that light, perhaps the best-practices rule is redundant with the "Does my question contain code?" and "Is it actual code from a project rather than pseudo-code or example code?" tests, and should be deleted altogether. Eliminating the rule might also remove an unnecessary source of confusion and controversy.

What do you think? Should we revise or delete the best-practices rule? Can you think of any good examples of questions that support either position?


Background: This rule has been discussed and revised before.

\$\endgroup\$
  • \$\begingroup\$ We never updated the help center, is this a dead question ? \$\endgroup\$ – Marc-Andre Jun 27 '14 at 13:22
6
\$\begingroup\$

I think that one of the things that this rule was meant to avoid is questions that are primarily opinion-based. Many of these primarily opinion-based are asking something like "What is the best (practice) and why?". Considering that there is a separate close reason for "primarily opinion-based", the on-topic rule about "best practice" doesn't apply much here either.

My vote is: Remove the rule for now. If question quality drastically decreases, then consider re-adding a clarified version of the rule.

\$\endgroup\$
7
\$\begingroup\$

I agree that this is a bad rule.

First, I reference the wiki for (emphasis of mine).

Best-practice questions generally involve a short excerpt of code with a question of general interest, usually focused more on maintainability concerns than the algorithm to solve the task at hand. Note that questions must include a real code excerpt and sufficient context for reviewers to make specific recommendations relevant to your situation; hypothetical questions are off-topic for Code Review.


Now we can look at a couple of questions with regard to . All of these are currently closed as of this question's posting.

  • Using a for-loop instead of sleeping?

    For this question, we can see a that it abides by all of the the requirements in the tag wiki. It contains a short snippet of code (there were arguments that one line was too short, we didn't define what short is in the tag wiki); it questions the general interest of delaying code execution for a specific interval; and it does contain a real excerpt of code from one of the OP's programs, with plenty of context what the line of code is being used for.

  • 'do { statement; } while(0)' against 'statement' when writing C macro?

    Here the question provides two different cases that are being used simultaneously in a project, and asks for the better of the two options. They provide the context of usage, the short snippet of code to be reviewed, and it is a common enough issue that it is a general interest to readers.

There are others I could go more in-depth with, but I think you get the point.


Why I think this rule exists in the Help Center:

Here is what I imagine as being a more "full" example of what the Help Center defines as off-topic:

What is the best practice regarding X?

I am trying to implement X into my code, and I am wondering what the best practices for this are? Any suggestions?

In my fuller example, no code is actually being reviewed, because none is being supplied. It doesn't include the OP's implementation, may or may not be of general interest, and doesn't provide any context to the reviewers. This is a question that I would consider as off-topic.


Conclusion:

Best-practices questions that include code have been historically successful and popular, and will be beneficial to have in the future for this site. Either edit the tag to avoid confusion regarding things that are on or off-topic with this site, or clarify the phrasing in the Help Center.

\$\endgroup\$
6
\$\begingroup\$

This is not an answer, but a talking point about whether this is on, or off topic


Version 1: (off-topic - asking for code to be written)

What is the best practice regarding synchronization?

I have this class that works really well, but I need to make my application multi-threaded. I have read that synchronization can help. What are the best practices for making my code thread-safe?

public class Foo {

    private String foo = "Foo";

    public void setFoo(String newfoo) {
        this.foo = newfoo;
    }

    public String getFoo() {
        return foo;
    }
}


Version 2: (on the fence, but probably on-topic)

What is the best practice regarding synchronization?

I have this class that works really well, but I need to make my application multi-threaded. I have read that synchronization can help, so I have synchronized the setters.

What are the best practices for making my code thread-safe?

public class Foo {

    private String foo = "Foo";

    public synchronized void setFoo(String newfoo) {
        this.foo = newfoo;
    }

    public String getFoo() {
        return foo;
    }
}


Version 3: (on-topic)

What is the best practice regarding synchronization?

I have this class that works really well, but I need to make my application multi-threaded. I have read that synchronization can help, so I have synchronized the setters.

Have I successfully implemented the best practices for making my code thread-safe?

public class Foo {

    private String foo = "Foo";

    public synchronized void setFoo(String newfoo) {
        this.foo = newfoo;
    }

    public String getFoo() {
        return foo;
    }
}

\$\endgroup\$
  • \$\begingroup\$ It is my opinion that the above is off topic because it is asking for code to be written. \$\endgroup\$ – rolfl Mar 4 '14 at 0:12
  • \$\begingroup\$ I'd say that it violates the "asking for code to be written" rule. \$\endgroup\$ – 200_success Mar 4 '14 at 0:12
  • \$\begingroup\$ Obviously, we agree! \$\endgroup\$ – 200_success Mar 4 '14 at 0:12
  • \$\begingroup\$ @200_success What about version 2? \$\endgroup\$ – rolfl Mar 4 '14 at 0:17
  • \$\begingroup\$ In Version 2, the author tried to write code, and probably believes in good faith that it is working code, even though it is actually buggy. I would consider it to be on-topic. Also, if you rephrased the question as "I think my code is thread-safe — can you confirm?" then it is more obviously on-topic. \$\endgroup\$ – 200_success Mar 4 '14 at 0:22
  • \$\begingroup\$ @200_success I am inclined to agree, again... so, there is some line between version 1, and version 2, but a version three should make the point solidly.... \$\endgroup\$ – rolfl Mar 4 '14 at 0:24
2
\$\begingroup\$

Help Center > Asking

It is hard for me to visualize the proposed changes. Here is the current Asking help page:

Code Review Stack Exchange is for sharing code from projects you are working on for peer review. If you are looking for feedback on a specific working piece of code from your project in the following areas…

  • Best practices and design pattern usage
  • Security issues
  • Performance
  • Correctness in unanticipated cases

then you are in the right place!

I look at that, and suggest the following may be more useful:

Code Review Stack Exchange is for sharing code from projects you are working on for peer review. If you are looking for feedback on a specific working piece of code from your project in the following areas…

then you are in the right place!

The above not only helps clarify what is on topic, but also directs the asker to specific tags.

Also:

  • I don't like specifically identifying 'security' as an on-topic item. I don't mind the tag (it has it's place), but security questions are likely better on security.se
  • I don't like the idea that hunting for 'edge-cases' is on topic.
\$\endgroup\$

You must log in to answer this question.

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