6

Are there useful programs that don't take inputs such as: A user's keyboard input; an interrupt from a clock; data from another server etc.

A program that computed/printed out predefined data could be turned into a file, right?

| improve this question | | | | |
  • 7
    How about a program that computes the digits of pi? How about a program intended to compute the answer for some mathematical problems, where the "input" is hard-coded into the program itself (during programming or compilation phase)? – rwong Mar 11 '17 at 22:06
  • 10
    The answer is yes(1) :-) – Blrfl Mar 11 '17 at 22:07
  • So, is the only example mathematical approximation? – Tobi Mar 11 '17 at 22:15
  • A dead man's switch that doesn't require configuration. Well, I guess that would take a timer as input, though you could approximate a timer by sitting in a loop. Really, any program where you hard-wire the input data. – Robert Harvey Mar 11 '17 at 22:18
  • 1
    This question was unrightfully placed on hold. – Tobi Mar 12 '17 at 17:56
9

One example where such a program can be useful is when the program is much shorter than its output. That means that the program is basically a compressed version of its output.

Some practical use cases:

  • Self-extracting zip files
  • Programs whose output is actually infinite, such as yes(1) which repeatedly outputs "y". (Thanks to blrfl for mentioning this in a comment.)

The theoretical term for this concept (when the output is finite) is Kolmogorov complexity. From Wikipedia:

Consider the following two strings of 32 lowercase letters and digits:

abababababababababababababababab

4c1j5b2p0cv4w1x8rx2y39umgw5q85s7

The first string has a short English-language description, namely "ab 16 times", which consists of 11 characters. The second one has no obvious simple description (using the same character set) other than writing down the string itself, which has 32 characters.

More formally, the complexity of a string is the length of the shortest possible description of the string in some fixed universal description language [...].

(Note: This fixed universal description language is usually some Turing-complete programming language.)

| improve this answer | | | | |
4

Lots of system utilities. The shutdown, reboot, poweroff commands.

There are others I can't think of right now, I'm sure.

| improve this answer | | | | |
3

Yes, unit tests (at least decently written ones).

Edit

To be less glib: There are a lot of different unit test setups but they effectively boil down to the following, the code base under test is treated as a library and your unit tests are essentially one big program that when run prints out something like

Test foo passed
Test bar passed
Test baz failed
     ...Details...
Test quux passed

If your unit tests are deterministic (which they generally should be as debugging nondeterministic tests is the worst), this will just be a constant string.

Now once you get into the real world the border's really fuzzy here, but I think the general point that an inputless program is a good way of learning about some other set of source code.

| improve this answer | | | | |
  • I thought unit tests take code as an input, to test? – Tobi Mar 12 '17 at 3:06
  • @Tobi, hopefully the edit brings the point out. – walpen Mar 12 '17 at 3:51
  • I'm confused; will a unit test not test code you've written, making it an input? – Tobi Mar 12 '17 at 4:14
  • @Tobi well, no ... Unit tests don't read the implementation like an input or environmental resource, they include the implementation during compilation. In order to generate pretty, interactive results, a the test suite usually interacts with the environment (like an IDE or test runner). But, that's optional, really. It could just as easily be a binary that executes on its own and dumps the results to standard out. And in fact, I've cowboyed some test runners of that nature myself... – svidgen Mar 12 '17 at 10:11
1

Depends what you mean by redundant. Here are a few I could think of in a couple minutes:

  • A program that creates music or art

  • A program that dances, or sends instructions to a robot that dances

  • A program that models a virtual society and outputs its likely lifespan under varying conditions

  • A radio beacon

Are any of those things redundant?

| improve this answer | | | | |
  • All of those things will have input, even if it's coming from a random seed. – RubberDuck Mar 12 '17 at 0:23
  • #1: What do mean "creates music or art"? Randomly = Seeded by an input #2: That would be an input into an interpreter that controls the robotic movement. #3: An inputted society or a randomly generated one? The latter would be seeded #4: What do you mean by "radio beacon"?.. – Tobi Mar 12 '17 at 0:32
  • Incorrect; none of the items I listed require input, as in, something traversing from outside the system to inside the system. And I don't know where you got the idea that randomness is a requirement for any of it. – John Wu Mar 12 '17 at 1:25
  • #1 I mean literally composes a piece of music or draws a picture. It doesn't have to be very good music or a very interesting picture. Neither randomness nor originality is a requirement. #2. No, it would be an output to an interpreter that controls the robotic movement. #3. Neither; a society that determines itself, starting with a basic initial condition, then evolving. #4. A continual transmission in the electromagnetic spectrum, modulated by the output of our program, potentially in accordance with a predetermined pattern. – John Wu Mar 12 '17 at 1:47
1

Programs like this occasionally arise and are useful such as to answer a specific question by performing some calculations. But once the program works correctly and produces the result, there is no need to run it anymore.

As an example, I once wrote such a program to produce a set of matrices that convert Euler angles to an orthogonal matrix for all the possible Euler angle systems. The input was essentially generated within the program (a set of permutations). The program symbolically multiplied 3 or 2 matrices together for each possible Euler angle system and produced a TeX file with the resulting matrices. It was less work and less error-prone to write the program than to do the math by hand. There was no input from the environment, though. You just ran the command and it wrote out the file. And once I was satisfied that it was working correctly, I haven't run it again since.

| improve this answer | | | | |
1

A program which computes the sequence of prime numbers.

| improve this answer | | | | |
0

A program that takes absolutely no input from a user or the environment will give a very predictable result. If the result is only data, you could indeed store it in a file instead of running the program again and again. It would be constant propagation to the highest level.

Nevertheless, predictable does not mean identical. A program without any input could yet produce different results at each computation. The typical example is a simulation application using random numbers. This case is nevertheless borderline, because you could argue that the random number generator (or its seed) is a special form of input of the environment.

However a program can have side effects. It could for example switch some leds (or traffic lights) on and off. Or display a count-down in a window. Such "side effects" might not be replaceable by a precomputed result in a file. So no: even without any input a program is not necessarily "redundant" !

| improve this answer | | | | |
  • 3
    Yikes, I'm thinking everyone here failed basic systems theory. You can have deterministic (non-random) output that is not predictable. C.f. chaos theory. – John Wu Mar 12 '17 at 1:34
  • @JohnWu "highly depedent on the initial conditions" means getting some kind of inputs from environment (e.g. State of uninitialised variables). If the program is part of a larger dynamic system, it would have to communicate with other programs to generate chaotic results: IPC are also a form of input. – Christophe Mar 12 '17 at 9:26
  • Here is the textbook example. No external systems needed. var x = 0.002; for (int t=0; t< int.MaxValue; t++) { x = 4 * x * (1 - x); Console.WriteLine($"{t},{x}");} See if you can predict x for a given t. – John Wu Mar 12 '17 at 12:01
  • @JohnWu sorry if this is not clear in my answer:my point is that on the same computer, this sort of computation will produce the same result at each execution. So i can run it one, record the results and use the recorded results afterwards (this is how i interpreted the ambiguous "redundant" in the question). Of course if the intend is to create impatience and enthousiasm for a user looking at the results about whether or not the result will converge, this can't be reproduced, and this is what i meant with "side effects". If the loop never ends, we remain in the side effect part of my answer – Christophe Mar 12 '17 at 12:10
  • So you've never listened to the same song twice? – John Wu Mar 12 '17 at 12:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.