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.
Question/Proposal
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
Duly
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).