# Default for Code Golf: Input/Output methods

It looks like we have a consensus that we want certain defaults for the format which answers are expected in for . On that poll, the question arose twice, which input/output formats should be allowed for programs and functions.

So here is another poll. This one works different though. All the input/output methods are independent of each other, so there will be one answer per method. Upvote all you think are reasonable for the default. Downvote those which you think shouldn't be allowed unless the OP explicitly permits them.

To keep this remotely manageable, I have not posted individual answers for all possible inputs for functions. So there are only four: functions can take input/output via their arguments and return values. Or functions can use any method full programs can. I don't think there is any point in (say) allowing programs to take input from STDIN (only) and to allow functions to take input from ARGV (only) or something like that. If you disagree, please leave a comment.

Note: Some votes have been reverted because they were detected as serial voting. If you vote on multiple answers, please leave some time between votes.

A method is allowed if it has 5 net votes and at least twice as many upvotes as downvotes.

### Update

The current results of the polls are now part of the tag wiki. Please notify me, if results change significantly and the wiki should be amended.

• Related (Can numeric input/output be in the form of byte values) – mbomb007 Dec 13 '16 at 16:10
• "The current results of the polls are now part of the tag wiki" which tag wiki? meta wiki has nothing for code-golf tag. ppcg wiki has codegolf.stackexchange.com/tags/code-golf/info but it's missing a lot of answers here. – Sparr Jul 18 '18 at 18:17

# Programs running under Unix may produce output by overwriting their command-line arguments, which changes what ps reports.

I'm posting this because it was brought up as a loophole in my answer to this question. I personally think it should not be allowed, because it's obscure, not available in all languages, and ephemeral (someone has to run ps while the program is still executing).

• this seems to be a special case of "functions may use out parameters" – Jasen Dec 22 '16 at 10:55
• but ps doesn't report it after the program ends :( – Jasen Dec 22 '16 at 11:01

# Dynamic creation of a "fake" STDIN, when one isn't present (creating also a separation between the code and the input).

For example, Javascript doesn't have STDIN(for obvious reasons).

One could make something like function(a){[code here]} and only count the content inside it + 1.

On php, one can read from STDIN using \$f=fread(STDIN,1024); and this would count only as 2 chars.

On other languages, this would vary a bit.

• Isn't the PHP example actually reading from STDIN? In which case, why shouldn't all of those bytes count? – Martin Ender Nov 3 '14 at 0:09
• Depending on the way you handle it, if you read everything on STDIN at once, you can consider it a single input. I don't know if I'm making myself clear. But if your code is restricted to only 1 read to the STDIN, you can only consider the size in bytes of the name of the var. If multiple accesses are made (loops, conditions, partial reads...), everything is counted on the code. – Ismael Miguel Nov 3 '14 at 0:14
• @MartinBüttner He's referring to the fact that different languages have different character counts for an STDIN read. Also, shouldn't this be CW? – TheDoctor Nov 4 '14 at 23:42
• @TheDoctor Doesn't matter anyway - no rep gain/loss for meta. – user10766 Nov 6 '14 at 21:44

# Output is saved in a certain variable at the time the program has finished execution

This eliminates the disadvantages languages like Java have when printing System.out.println("asdf")

For languages without variables this could be top of the stack etc...

• This essentially makes the submission a snippet instead of a full program, which the other meta question decided should not be a valid default. – Martin Ender Sep 11 '15 at 18:25
• @MartinBüttner Unless the programming language is, of course, a turing machine. (I do vote for placing the tape head at the return value) – yyny Jan 31 '16 at 0:41
• In C#, a lambda is more a variable than a function. Lambdas are build on top of Delegates. Are they still valid? (By this, i think so) – aloisdg Jul 6 '16 at 20:32
• In what way is this fundamentally different from the same rule about functions? Why is it allowed for functions and not for full programs? – Kaddath May 5 at 15:04

# Programs may take input by assuming it is stored in predefined variables.

• -1 (Can't vote) – Nathan Merrill Mar 17 '16 at 21:43
• This just skips the "reading" step of a program. I don't think programs should be allowed to assume the output of an arbitrary computation, e.g. the one asked for in the question, is stored in a predefined variable either. – djechlin Jun 6 '16 at 18:11
• @djechlin we are intentionally separating input/output methods. Outputting on variables is listed here: meta.codegolf.stackexchange.com/a/6965/20198 – Nathan Merrill Jun 6 '16 at 18:14
• Okay, I still don't think you can skip the "reading" step of a program any more than you can skip the "writing" step of a program. That's all I'm trying to say. – djechlin Jun 6 '16 at 18:15
• I'm confused what you are talking about. Programs have input and output. We define valid input methods (such as reading from a file, or parameters to a function), and valid output methods (writing to a file, or return values). This post is directly targeted at input methods. There is another answer on this question targeted at output methods. We split them so people can vote separately. – Nathan Merrill Jun 6 '16 at 18:18
• This is most relevant to the Sinclair ZX80 and ZX81 BASIC. – Shaun Bebbers Apr 4 '17 at 9:04