7 ms·
> What is a Program? A program is a set of rules for converting input into output. A program doesn’t need input or output though right?… it’s just a series of
by gitgud 3y ago
> What is a Program?
A program is a set of rules for converting input into output.
A program doesn’t need input or output though right?… it’s just a series of logical instructions that are executed
- kubb 3y agoYou’re right. What the author is doing here is philosophizing. Trying to make connections, view things from an angle, come up with your own definition. Maybe forgetting that others have already explored the space. It’s OK to do that even if you don’t impress many people.
- kaoD 3y agoIf a program has no IO it can be reduced to not running a program at all (not counting side effects like the CPU getting warmer... but I don't think we'd count that as a property of the program itself).
- Etheryte 3y agoIO is a side effect, at least from the functional programming perspective.
- pjerem 3y agoYes but also in FP perspective, a program without IO will not be ran at all. Except if you count static parameter to not be an input, then you have a static output which is basically a constant. Compiler may in fact try to transform it into a constant and if you don’t do anything with it, well, it’ll probably be marked as unused and not even embedded in your binary.
- blowski 3y agoIf you have a program that sends an email with fixed content to a fixed email address, whenever you run that program that email address will receive an email. Is the email an output, or a side-effect?
- rzzzt 3y agourn:xkcd:1172
- infradig 3y agoNon-termination is a valid computation. No I/O involved.
- ReactiveJelly 3y agoIf the program doesn't take any input and your only output is termination time, you are writing an egg timer.
- Supermancho 3y ago> If a program has no IO it can be reduced Thats a difference between the theory and practice. In practice you always have to consider physics. There are always inputs and outputs.
- RugnirViking 3y agoI disagree, if I make a program to calculate something complicated, it can start with everything hardcoded and still be a program no? Maybe there is some academic definition im not aware of though.
- glimshe 3y agoThe result of your calculation is technically the output. But if the program is just an infinite loop doing nothing... The output is heat :).
- nonameiguess 3y agoThere seems to be a mixing of definitions going on here that is confusing people. You've got an algorithm, a finite sequence of unambiguous instructions that, given some initial conditions, will produce some end state that is interpreted as either correct or incorrect. You've got a function, which is some mapping of elements from a domain to elements of a codomain such that the mapping is unique for each element of the domain. Then you've got a "program." This one doesn't come from mathematics, so I guess that means it doesn't get a rigorous, clear, agree-upon definition. So what does the writer himself mean? He wrote an earlier post linked to from this post that provides his definition: https://blog.charliemeyer.co/code-doesnt-happen-to-you/ https://blog.charliemeyer.co/code-doesnt-happen-to-you/. My definition is a sequence of instructions provided to a machine allowing the machine to do work partially or fully autonomously once it has been started. If we limit ourselves to the kind of machine the people of 2023 commonly called programmers typically program, we've got electronic boolean state machines that receive fixed-length sequences of bits either as operands to a boolean circuit or instructions telling the state machine which boolean circuit to execute in this cycle. The instructions and operands are either persistently stored as firmware, fetched from NVRAM in the case of a bootloader, or fetched from volatile memory in the case of most other programs. These were in turned put there by some higher-level management program that read them from sources such as durable storage or buffers that may be written to by hardware that receives messages from external sources such as network interfaces, capacitative touch devices, or keyboards. Not all instructions accept operands and thus not all programs require operands. Trivially, the null program executes a sequence of NOPs. So does every program need inputs? Well, every program is a state machine. A state machine has an initial state and an end state and these usually get referred to as inputs and outputs when discussing state machines. Even the null program is a state machine. It remains in the same state at each cycle no matter the current state, such that the final state is always the same as the initial state. The null program is also a function. It even has a special name: the identity function. Like all functions, the identity function has an input and an output and these are always the same. Another trivial program is the constant function, which produces the same output no matter the input. Consider a program to factory reset or wipe a device. The initial state of the device is still an input, but the final state at program completion will not depend upon this input. What every program does not need is inputs provided at startup in the argv and envp arrays or provided interactively at runtime by other programs or human users. The mixup here seems to be readers limiting themselves to considering input only in the sense of hardware devices that get labeled as IO devices when discussing the basic taxonomy of computer organization and design, but these are one of those "the categories are made for man" things. The execution unit on a processor just receives bits from the buses connecting the processor to a memory module. It doesn't know or care where they came from and whether they were already there or not before a particular program started.