# Default for Code Golf: Program, Function or Snippet?

One of the things many (new?) users forget to specify in challenges is whether the answers should provide a full program or a function (or even just a snippet). For most such things, we have defaults in the tag wiki (like scoring by bytes), but not for this.

The conclusion in chat was that such a default would be useful, so let's vote on what it should be.

See here for the follow-up poll on input/output methods.

• I have not added an answer which excludes full programs as the default, because there might be languages where that isn't even possible. – Martin Ender Oct 29 '14 at 20:23
• Supposing functions are allowed, should functions that accept an argument and print the result of a calculation to stdout, or functions that read from argv and return a value be allowed? – feersum Oct 29 '14 at 20:25
• @feersum I think we should worry about I/O defaults after coming to a consensus on this, because the cross product of all possible options doesn't seem manageable. – Martin Ender Oct 29 '14 at 20:28
• I think it would be nice if all the code could be run by people who don't know the language. That is it could be a complete piece of source code. – user9206 Jan 21 '15 at 14:54
• What exactly is the difference between answering with a snippet and "defining a dialect" (a la the 'sed with implied input' at codegolf.meta.stackexchange.com/questions/5476/… ), particularly in cases where the standard interpreter has a built-in mode such as a REPL for running so-called "snippets"? – Random832 Oct 22 '19 at 21:04

# The default should be "programs or functions"

This includes function-like constructs, including J's verbs and GolfScript's and CJam's blocks.

• Would functions be allowed to print rather than return the output? – xnor Oct 29 '14 at 20:25
• @xnor I think we should worry about I/O defaults after coming to a consensus on this, because the cross product of all possible options doesn't seem manageable. – Martin Ender Oct 29 '14 at 20:27
• This excludes some languages, such as J. – Peter Taylor Oct 30 '14 at 8:08
• @PeterTaylor Doesn't J have functions? – Martin Ender Oct 30 '14 at 8:13
• J is weird. It's the reason that I always include "named verb" in my list of acceptable submission styles. (And "named block" for GolfScript, although in GS it's nearly always shorter to write a program). – Peter Taylor Oct 30 '14 at 8:24
• This still leaves one question open: Does the functions/blocks/verbs have to be named? – Dennis Oct 30 '14 at 18:02
• – Martin Ender Oct 30 '14 at 18:04
• Function bodies? Or complete function declarations with function main()-like boilerplate? – user16402 Nov 1 '14 at 20:32
• @professorfish Complete functions. Function bodies would be "snippets" (see this answer). – Martin Ender Nov 1 '14 at 20:34
• This seems to be the correct default, because the general rule is that whatever is left unspecified gets interpreted in the way most advantageous to the answerer. On the other hand, those who intend "program or function" in their questions often absentmindedly write "your program" which then implies that a program is required, when they should write "your code." – Level River St Nov 10 '14 at 13:45
• me downvote, there are programs without functions and the definition of function can be diffent. the startup is part of the language, if you keep that part out, you can skip every part. – 12431234123412341234123 May 5 '17 at 8:29

# Restricting to just programs requires explicitly specifying "full program" rather than just "program"

If the question requests a program, this can still be answered with a function. This allows for the fact that many people state "program" without thinking, not intending to exclude functions.

For questions that wish to exclude functions, this should be stated explicitly, for example: "full program", "complete program" or "program, not function".

• This is an especially good idea for challenges by newer users who aren't familiar with our customs/defaults. – Alex A. Sep 8 '15 at 16:57

# A set of different "defaults"

I think many questions require one of a few different ways, some require...

1. ... a full program that accepts input and prints output throu standard I/O
2. ... files as input/output (e.g. Images)
3. ... only functions (or similar constructs)
4. ... snippets, where input/output is stored in a variable (or similar construct)

This is of course just a rough draft, but you get the idea. My suggestion is making a definition for each of these in order that everyone writing challenges only has to declare which of those apply, instead of writing a whole novel on what is allowed and what is not.

• We have a separate question for which I/O methods should be allowed. – Martin Ender Sep 8 '15 at 10:30
• Having the defaults we already do (separately) means that the question already doesn't need to spend time on defining them. Only those things which are non-standard need be mentioned. – trichoplax Sep 8 '15 at 17:30

# We don't need a default

Every question has to specify this.

• This has my downvote. – Martin Ender Oct 29 '14 at 20:24
• +1 Questions which don't have it should be closed as "Unclear what you're asking". – Peter Taylor Oct 29 '14 at 21:34
• @PeterTaylor plenty of good existing questions would have been under that ruling, I'm afraid. – John Dvorak Nov 3 '14 at 7:03
• @JanDvorak, sorry, I'm using old terminology. I should say "put on hold" and clarified. – Peter Taylor Nov 3 '14 at 9:31

# The default should be "programs only"

• This has my downvote. – Martin Ender Oct 29 '14 at 20:24
• mine too. significant disadvantage for languages that have a large overhead (huge trivial program) – Titus Jul 7 '16 at 7:41

# The default should be "programs, functions or snippets"

By "snippets" I mean just a piece of code which expects the input to be stored in a hardcoded variable and stores the output in another hardcoded variable, or prints it.

• The question is which one of these – Redwolf Programs Apr 19 '18 at 13:56