For asking and answering questions on Stack Overflow with certain frameworks and libraries I have boilerplate lying around for a minimal repro. I would be interested in getting feedback on my WCF basic minimal repro, because I want to make sure it will be up to snuff.

I want to be a good CodeReview.SE citizen, but in the past I've had problems determining what is considered good practice / on-topic here. So I figured this time, because I'm blurry on this one, I'd ask for advice beforehand.

I've read the FAQ, and from that I found (highlights mine) that these are required:

  • Is code included directly in my question?
  • Am I an owner or maintainer of the code?
  • Is it actual code from a project rather than pseudo-code or example code?
  • Do I want the code to be good code? (i.e. not code-golfing, obfuscation, or similar)
  • To the best of my knowledge, does the code work as intended?
  • Do I want feedback about any or all facets of the code?

Most boxes I think I'd tick off, except the highlighted parts, I'm not sure about those.

Would anyone be so kind as to clarify if "code for an exemplary minimal WCF repro" is off-topic as it's "example code", or whether I'm taking the FAQ text too literally?

I'm not sure if it's helpful or frowned upon, but with the best of intentions, here is the code I'd be asking a review for:

using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Threading.Tasks;

namespace WcfMinimalTest
    // WARNING! This minimal repro does no cleanup or error handling whatsoever!!
    // Loosely based on http://stackoverflow.com/a/7833188/419956 by @Anuraj

    public class Program
        static void Main()
            Task.Run(() => Host());
            var client = new FooProxy();
            var result = client.Bar();
            Console.WriteLine($"Received result from service via proxy: {result}");
            Console.WriteLine("Press any key to exit.");

        static void Host()
            Console.WriteLine("Service starting...");
            var host = new ServiceHost(typeof(FooService), new Uri("net.pipe://localhost/"));
            host.AddServiceEndpoint(typeof(IFooService), new NetNamedPipeBinding(), "fooservice");
            Console.WriteLine("Service started.");

    public interface IFooService
        string Bar();

    public class FooService : IFooService
        public string Bar()
            Console.WriteLine($"Service {nameof(Bar)}");
            return "Barrrr, matey!";

    public class FooProxy : ClientBase<IFooService>
        public FooProxy() : base (new ServiceEndpoint(ContractDescription.GetContract(
            new NetNamedPipeBinding(), 
            new EndpointAddress("net.pipe://localhost/fooservice")))
        { }

        public string Bar()
            Console.WriteLine($"Proxy {nameof(Bar)}");
            return Channel.Bar();
  • 2
    \$\begingroup\$ I'm no C# programmer, but your code looks like it is example code etc. Do you really name things; FooProxy, FooService, Bar? Also, you may be interested in this answer. \$\endgroup\$ – Peilonrayz Dec 15 '16 at 22:57
  • \$\begingroup\$ Thx for your response. To further explain, in a sense, yes, I really do name stuff FooProxy, if I'm answering questions on SO. It is intentionally abstract. It is also in a sense "real" code, that I'd use to answer a question. The thing is that others might grab my code, replace "Foo" with their own names, and carry on with the code (which is why it seemed important to have "correct" abstract repros). - (I'll read through the link you gave too, thx.) \$\endgroup\$ – Jeroen Dec 15 '16 at 23:09

The line between real and hypothetical code is sometimes blurry, but I would consider this code sample to be on the wrong side of the line for Code Review. Code that contains Foo or Bar identifiers is generally an indicator that you are withholding something from us. We would have to speculate as to what you really mean, which makes reviewing this code frustrating — hence the reason for the "real code" requirement.

  • 2
    \$\begingroup\$ Shame, but glad I asked. Thanks for taking the time to answer. \$\endgroup\$ – Jeroen Dec 15 '16 at 23:40
  • \$\begingroup\$ What do you think about if OP added their reasoning, in the comment, above to their question? \$\endgroup\$ – Peilonrayz Dec 15 '16 at 23:45
  • 7
    \$\begingroup\$ Thanks for taking the time to ask @Jeroen. \$\endgroup\$ – RubberDuck Dec 16 '16 at 1:38

I've been thinking about this question and I contend that it is indeed on topic.

Now, in general, the second we see a name like FooBar, we hit the close button because it's example code and example code causes frustration for the reviewer & reviewee alike. That is without question. The question here is then, "Is this particular code example code?" That's a potentially gray area for the code in question.

On one hand, it certainly is example code. It's boilerplate explicitly meant to be an example for others to build on top of. Example code -> Off topic.

On the other hand, what if we were distributing this boilerplate as part of a NuGet package? One of my guiding lights when it comes to "Is my code ready to post a CR question?" is "Would I submit this for review at my job?" In this case, I certainly would submit this for review.

Focusing on the relevant "golden questions" from our help center:

  • First and foremost, I want this boiler plate to be Good Code™. Other people will be building on top of this, so I need to set the best example possible.
  • Secondly, this code absolutely must work as intended. When people first install my package, this code must compile & run, performing its minimal amount of work. It's minimal, and perhaps trivial, but the code works and fulfills its intended purpose.

These things combined make me feel that this is real code from a real project. A good answer here could address that the names should be good enough to leave in place, or //TODO: rename comments added. If there were any unimplemented methods (there's not, but let's pretend), we could mention that they should throw NotImplementedException. We could address any bad design choices, and all the other things we would address during any other review.

In short, given the context, this is reviewable code and on topic IMO.

  • 3
    \$\begingroup\$ agreed, but only for this special case. It's very much grey area either way :) \$\endgroup\$ – Vogel612 Dec 16 '16 at 12:27
  • \$\begingroup\$ @Vogel612 and given that it is a special case, perhaps it's better for the community to just hold the line and say "Off topic." \$\endgroup\$ – RubberDuck Dec 16 '16 at 12:45
  • 3
    \$\begingroup\$ @RubberDuck Perhaps this is grounds to reword that section of help: "Is it actual code from a project rather than pseudo-code or example code?" could perhaps be something along the lines of "Is is production (shippable) code rather than pseudo-code or example code?" \$\endgroup\$ – Der Kommissar Dec 19 '16 at 2:17
  • 1
    \$\begingroup\$ @EBrown But then you might confuse people where they've got code that they wouldn't consider shippable, yet, but is something they consider complete. \$\endgroup\$ – Kaz Dec 19 '16 at 14:43

Note that this answer targets questions generally and is not intended to target the specifically mentioned CR question.

To be on the safe side if you fear that you have "example code", I would recommend to instead of posting with classes like Foo, Bar, etc. you can come up with an example project. That is, find a possible use case for what you are doing and implement it as a project.

They key is the context. If you for some reason are unwilling to share your current context, come up with a new one! If you would have problems to come up with another context that can be applicable, then either post your real code (make sure you have permission to do that) or don't post at all.

See also What is the relationship between "example code" and "example project"


You must log in to answer this question.

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