I'll try to keep this short... see these (relatively recent) questions for some background: 1 2 3

Disclaimer: I really hate 'untyped anonymous lambdas', and if we must have them, then we need some rules, but I think they don't make sense, and I think this is one formal way we can kill them forever, so I may be slightly biased, but I do think this makes some sense regardless, and that having per-language ruling is necessary if we want comparable answers in the same language.


Would there be support for the creation (by community discussion, consensus, etc.) of sets of allowable 'boilerplates' for some languages (i.e. those that it makes some sense for) which would implicitly indicate submission validity?

Such boilerplates might look like this:

C#, solo anonymous lambda boilerplate

class ArbitaryAndLongClassNameAssumedToBeUnknownAndNotToClash
    static void ArbitaryAndLongMethodNameAssumedToBeUnknownAndNotToClash()
        var result = (/*submission here*/)(/*arguments*/);

Input is supplied as arguments, as indicated. Result is stored in the variable result (upon calling the method) whose type is inferred by the compiler.

C#, class member(s) boilerplate

class ArbitaryAndLongClassNameAssumedToBeUnknownAndNotToClash
    /* submission here */

    static void ArbitaryAndLongMethodNameAssumedToBeUnknownAndNotToClash()
        var result = Q(/*arguments*/);

Input is supplied as arguments, as indicated. Result is stored in the variable result (upon calling the given static method) whose type is inferred by the compiler. You may chose any identifier other than Q such that it is only defined when your code is in inplace (i.e. it can be z, or `husky).

(more 'examples' can be found in my other commentaries.

We can even define boilerplates for "full programs" (this one is easy, no boilerplate) and "functions", and "snippets", terms we already use, but that not necessarily meaningful on a per-language basis.

(if other people who know other languages think they understand what I'm on about, they are welcome to edit in a couple more examples - such examples are examples and we should not consider this proposal a proposal to implement those examples, they are merely illustrative... examples; but keep them sensible)

Checking Validity

When you have a number of such boilerplates, checking validity is easy! You just stuff the code into the appropriate one (require people to specify if it is unclear; but we design them to provide no useable context), and if the code can then be compiled/run, great! Your submission is valid, no questions need to be asked.

This is basically what people do already to demonstrate validity... only it will be formalised.

What I like about the idea

  • While it will be a lot of (initial) effort, it will be less than having the same argument every time someone tries to use a lambda in C#, or Java: because it is opt-in, the effort only need be applied to those languages where everyone is arguing: if there is no argument, there is no need anyway
  • All of the nice stuff that comes with having objective submission criteria:
    • Comparable answers in the same language
    • No extended discussion in comments (as oppose to meta) about submission validity (which have recently resulting in a deluge of discussions on meta
    • Something we can point new users to (instead of discussing in comments)

What is, or may seem, less than ideal about the idea

With some brief responses

  • Does this mean you have code that 'breaks out' of the boiler plate, and looks intrinsically illegal? e.g. finishing a method definition, only to start another, but not quite finish it? Probably, but I can't think of a viable example at this time, let alone one that pays off
  • This 'stuff the code into some boiler-plate' may not apply to all languages; but again, it would be opt-in, and if it doesn't make sense, you have to find another way
  • Won't this make C# answers longer? YES I DON'T CARE
  • What do we do about all the old, now invalid answers? I'm not sure... this is a general concern, and one we can discuss in context this if we think the idea is viable
  • The var keyword in C# means we can more easily let the compiler help us define things... this won't be the case in other languages, and what exactly is defined as the input/output will need some thought
  • As in the second C# example above, method names a bit of a pain, so it won't always be quite so easy as C&Ping the submission, but along with the boilerplate will appear simple rules which can trivially be applied or otherwise qualified in any answers


Do people think this idea has some merit? What would need to be changed/reconsidered if were to employ something like this?

I think that organised per-language submission validity criteria would make (some peoples') lives better, and 'boilerplate' seems like a clean and obvious way to achieve this with some languages.

Naturally, I would be happy to put effort into an example C# write up... but I'm dreadful at writing so someone else will have to tweak it to save embarrassment.

I won't be writing an answer to this (at least not in a hurry)

Follow up stuff....

  • I do not care what the implications of enforcing such rules would be on byte counts, this is entirely about formalising submission validity, and hopefully making illegal what I consider an unjustifiable practice that has become prevalent on PPCG, and to prevent such practices appearing in the future. It has the consequence of making answers in the same language comparable (i.e. they are both C# as defined by PPCG, rather than (for example) one being valid C#, the other being dubious C#)

  • This would not a free licence for answerers to assume any boilerplate they like. It would have to be one of an agreed set of boilerplates. This is essentially exactly the problem I've been trying to solve (people asserting types for "untyped lambdas" in their answers).

  • \$\begingroup\$ Simpler way is to just kindly request answers to include what is required to use it. \$\endgroup\$
    – Stephen
    Jul 7, 2017 at 15:41
  • \$\begingroup\$ @StepHen the issue is then defining what they are allowed to require be required to use it. The classic example is 'untyped anonymous lambdas' in Java and C# (has been discussed to death) where people traditionally provide something to 'assign' them to, but that code can influence their behaviour, and as such I believe makes the submission invalid. Having pre-defined boilerplate removes this concern. Whether we should encourage people to provide very explicit test code is another good question. \$\endgroup\$ Jul 7, 2017 at 15:44

1 Answer 1


I don't really think that this is needed.

This site is moving away from the "shortest code wins" rules, and most people only include it in challenges as to not be closed for a lack of a winning criteria. In short, this site is now about finding the shortest code in each language, rather than in all languages.

Therefore, this method of bypassing boilerplate is redundant. Who cares if C# and Java are longer than Jelly or 05AB1E? No matter the program, production languages are going to be longer than golfing languages. But what does matter is how the code is written. Just because a golfing language has a builtin for the problem doesn't mean that you shouldn't write a perfectly valid, C# program that does the same thing, albeit in 100 bytes.

As a more definitive answer, however, I don't think that it would be well received. Just reading through your post, I identified 3 key problems:

  • What if different programs, in the same language, require different boilerplate? Would you have to identify every different possible boilerplate template available?
  • These aren't full programs. They are snippets. and snippets aren't allowed here.
  • What is so bad about untyped anonymous lambdas? If you can solve the problem in a lambda, and really care about the byte count, use a lambda
  • \$\begingroup\$ I agree that we shouldn't compare between language byte counts, this is part of why I dislike the insistence on using "untyped anonymous lambdas" (I have stated why I dislike these may times elsewhere: it is because they are not self contained). What I want is a set of rules for a language, so that bytes counts can be compared for the same language. That is, everyone knows what a valid C# answer is, so you can't 'golf' a byte off but in doing so make your answer invalid (e.g. removing the types in your lambda). (I agree with everything you say in the first two paragraphs, I see no conflict) \$\endgroup\$ Jul 7, 2017 at 16:51
  • \$\begingroup\$ There would be multiple boiler plates, but we keep the number of them small. I can only think of 4 sensible (as far as I'm concerned) ones for C# off hand (no doubt similar for Java, F#, C, etc.), and they are pretty much what people do anyway, excepting "untyped anonymous lambdas". I don't imagine this would present any significant issues, though would certainly be language specific. Most questions only ask for a function. As I tried to express above, we can have 'function' boilerplate, 'full program' boilerplate, and 'snippet' boilerplate (or not, if they are frowned upon). \$\endgroup\$ Jul 7, 2017 at 16:53
  • \$\begingroup\$ @VisualMelon my point is that this would open the door for loads of languages claiming "boilerplate handicap" scores. I could say that a Python answer to hello world could be 1 byte and that I have to declare boilerplate to make it work. It just opens yet another loophole and isn't needed \$\endgroup\$ Jul 7, 2017 at 16:55
  • \$\begingroup\$ The whole point is we define boilerplates so that you can choose from a set of (simple) contexts, not define your own. Given the other commenter made a similar comment, I figure I've not made this clear in the question... The problem (I have) with "untyped anonymous lambdas" is that they assume context which people shouldn't be allowed to require in their answers. (See the many other linked meta questions for much discussion on this matter). (The reason I go on about them so much is because they are everywhere and I believe they make no sense) \$\endgroup\$ Jul 7, 2017 at 16:56

You must log in to answer this question.

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