3. Working with Data

3.1. Input, Output and Everything In-between

As soon as we start to write code, we deal with input and output. We deal with data and I know these words, input, output and data are so generic, so well known. It's easy for them to sound former and lifeless. This gives me visions of 1960s computer rooms.

But the reality of these ideas is much more interesting because at its most basic sense when we talk about input, output and data, we mean anything and everything we're going to put into our program, anything and everything we're going to get out of it and whatever we need to figure out along the way.

So first, think of all the things we can physically do with the computer while a program is running. We touch the keys on the keyboard, move the mouse, plug in a joystick, talk into a microphone, phone, use a webcam, plug in a music keyboard or alternative controllers. If you have a phone or a tablet, you can swipe on the screen or tilt it and shake it. Any of these things can be input for our program if we decide that we care about that kind of input.

Then there's also files on a hard drive, documents, images, music or video. Those could also be input and often we will have multiple types of input. Think of something like iTunes or windows media player. We can use them to read music files in from the hard drive (one kind of input) or we can stream music from the internet (a different kind of input). At the same time there's also input coming from the user: press play, press pause, adjust volume.

For output, we've already seen a simple example. We can output a message to the screen. But being able to take that concept a step further is what lets us show lines, boxes and user interfaces or even further take over the entire screen with with 3D worlds. But there are other ways to output.

Image

Fig 3.1.1: Some outputs of a computer program

We could have our program create a document and then save it out to the hard drive. We could generate an email and send it out to the internet. We could send sound to computer speakers. We can send output to a connected device like a printer or a robotic arm. There is incredible variety to what is meant by input and output and that's something to stay conscious of as a programer.

Here's the great thing. We don't have to think about language syntax to just ask the questions, how do I need my new program to communicate with the outside world? How do I want it to interact with something outside of itself, whether that's a human being or another computer or a device like a printer? This gets us one step closer to what needs to happen in the code. If this is the input I want to provide and this is the output that I want to have, how do I turn this into that?

If someone taps the left arrow on the keyboard, how do I then the position of a character on the screen and by how much? If someone clicks a specific button, how do I send a document out to the printer and all of this, whatever's coming in, whatever's going out. Importantly, whatever we need to figure out in between, we are going to have to hold at least temporarily inside our program so we can look at all this data, ask questions about it, and change it.

Data is one of these words that you used a lot in computing and often as part of another term like database, big data, and data modelling. So, to be clear, right now I'm using the word data in its most generic sense: stuff.

Data is any stuff or information that we care about, whether that's input or output or anything in between.

But we need to say in our source code exactly what data or information is important to us right now in this program and this moment. In the next few sections you'll see exactly how to do the that.