🔥

Thread (@thewizardlucas)


Given that my twitter handle is @thewizardlucas, I couldn't help but love something as magical as streams 💖 Throughout the day today, I'll do a few posts about streams. Here's a quick intro👇

🤔Why I love streams I love streams because I don’t like software. I always try to build less software. Less software means you have to spend less time updating it, less time fixing it, and less time thinking about it. The only thing better than “less software” is no software.

❓How can streams help build less software? Streams help us writing less software because they allow programs to communicate with each other. If programs cannot communicate they must have too many features to satisfy their user’s needs, therefore creating more software.

By enabling inter-process communication, streams encourage software to be smaller and sometimes can even prevent software from being written.

📚What are streams? In the same way that a river has a stream of water, programs have streams of data. Moreover, just like you can use steel pipes to carry water from one place to another, you can use UNIX pipes to carry data from one program to another.

⚙️How do streams work? Streams can be used to pass data into programs and to get data out of them. In UNIX, programs get some streams attached to them by default, both for input and output. We call these standard streams.
notion image

There are three different standard streams: standard input ➡️the stream which feeds your program with data standard output ➡️ the stream to which your program writes its main output standard error ➡️ the stream to which your program writes error messages
notion image

The cat program, for example, uses the stdin to receive input from your keyboard and the stdout to send it out. Data goes in through stdout and stderr and goes out in the other end: your monitor. Similarly, your keyboard input goes through stdin to a program.
notion image

When you know what each stream does, you can connect multiple programs through them.
notion image