What is IO?
IO stands for Input & Output. Properly, its defined as taking data into your program and taking data out of your program.
IO is Everywhere!!!
Consider the human body:
From Wikipedia: By Own work, CC BY 3.0, Link
The nervous system isn’t just the brain! And even massive portions of the brain are dedicated to simply sending and receiving data. Or processing data on the way.
The nervous system is made up of many small processors, all connected beautifully.
I would thus argue that a massive portion of the nervous system is just IO! Just networks of data traveling this way and that way.
And would also argue that a massive portion of programs also are just IO.
Types of IO
There are multiple kinds of IO in a computer program:
- Writing to and reading from files (saving and loading files)
- Sending and receiving data via a network socket (less technically referred to as download and upload)
- Printing to and reading from the console
- Sending and receiving data from a physical device, such as a USB keyboard.
Use Cases of IO
In addition, this makes each form of IO a form of communication between two programs, or a program saving data in the past to be loaded later.
Thus programs can have responsibilities, and then communicate with other programs with differing responsibilities. Or even redundant programs for allocating traffic. These programs can run on the same machine, or even different machines, with both having differing pros and cons.
How to Perform IO?
In Unix-Like systems such as MacOS, Linux and FreeBSD (and closely equivalent in Windows), there are common functions for dealing with IO. While there are a handful, there are four main functions with dealing with IO:
- Open - Prepare to send data to something (Open a file, open a network socket, etc.)
- Close - Close a data stream to something (Close a file, close a network socket, etc.)
- Write - Send data to something
- Read - Receive data from something
If you understand these four functions, you can connect your programs to almost anything!
UNIX systems highly abstract the concept of read and write, where one can interchangably use these functions with files, consoles, networking, devices, etc.
Though Open and Close may be different. Open often requires unique code depending on whether it’s a file, console, network socket, etc.
IO as a General Concept
More generally, the input from a human via a keyboard or mouse, or touch screen, or speech, or thought, or virtual reality, or whatever else we can invent, can perhaps be a form of IO. Similarly, pixels on a screen or sounds emitted from a speaker to a human could be the output of a computer to a human, thus a conceptual form of IO.
21 July 2024