12
$\begingroup$

I recently had a student in my Intro to CS class ask me: what is a file? I can't honestly say I had a good answer for him. Those of us who have been around a while know what a file is, but I was at a bit of a loss to explain it to a novice.

Today's students believe (and rightfully so) that a file is an icon-thingy in a folder or on the Desktop. They have some vague idea that there are files for images (JPEG, GIF, PSD, etc.), files for music (MP3, WAV), files for doing office stuff (docx, pptx, etc.), and maybe even HTML files. But they don't know what's in a file. That's where I kind of stumbled around for a few minutes because I didn't have a good answer prepared, nor a really good demonstration.

Looking back, I think I might have shown him what a text file looks like using a hex editor. Maybe also a simple image format such as PBM or BMP. I searched around on YouTube for a good video, but found pretty much nothing.

If you've been asked this question before, what's your answer? What is a file?

$\endgroup$
  • $\begingroup$ Long answer later, if a better one don't show up sooner. To answer the question, next time, just grab a file, or folder, out of your desk and show them a "file." English, German, binary, hex, or Martian, is merely the "encoding." $\endgroup$ – Gypsy Spellweaver Apr 20 at 7:22
  • $\begingroup$ I upvoted the question when you said Hex Editor. Great start! $\endgroup$ – Scott Rowe Apr 20 at 12:51
  • $\begingroup$ Related question? -- cseducators.stackexchange.com/questions/3535/… $\endgroup$ – Scott Rowe Apr 20 at 22:44
5
$\begingroup$

I would approach this pragmatically, beginning with the metaphor that kicked it off. I would tell the students something like this:

Imagine that it's 1925, and you're working at a giant company like General Electric as a secretary. There are files, meaning pieces of paper, for all kinds of things. Personnel files about employees, files of record for payments, files of company policies, board meetings, tax documents, you make it. There are hundreds of rooms holding thousands of file cabinets holding millions of files in hanging folders.

So the metaphor of a file, then, is a document with some information about something. And the metaphor for the folder is as a place to store those files.

We also call these folders "directories", another metaphor. A "directory" is from the same etmological root as direction, and it means "to guide". So, folders can be thought of as places where files sit, or can be thought of as a guide to where files are.

But translating that idea to the very alien mind of a computer involves some tweaks. First there's the idea that folders can contain folders, which can contain more folders still. This is incredibly convenient, and using the same metaphor as "directory", we call the list of folders and subfolders and subfolders that bring us to a particular file as a "path". Get it?

As for the files themselves, there are two perspectives to think about this. Again, the metaphor is there, but it breaks apart a bit in translation:

The first is from the file system, which is concerned with being able to store and retrieve these files. As far as the file system is concerned, a file is a size and a series of locations as to where the various parts of the file are stored. This is because the files don't have to be contiguous inside the computer. It doesn't actually matter if the first half is stored over here in the hard drive and the second half is stored somewhere else, since the file system will retrieve it for us as if it were one document anyway. The file system just has to keep track of everything so that the files can be assembled properly when they are needed.

The second perspective is the perspective of a file itself, which is really just some way to store some data, after all. So far, that's just like a file in our big office. But our files can store so many different kinds of data! We aren't just storing readable text. We can store pictures. We can store sounds. We can store runnable code. All of these require very different internal organizations, so the contents of files are extremely variable.

Many files begin with some sort of metadata. "Hey, I'm a picture, and this is my encoding and my color depth and my size and and and and...". Some files depend on the file system to just remember what kind of files they are. Every file is designed to be read by programs or by the computer itself, and is highly organized to make this possible.

So, a "file" means different things in different contexts, and the only overriding idea is that a file is a way to group data together.

$\endgroup$
  • $\begingroup$ Everything in computing is either a container or something that goes in a container. Because everything in our minds is either a concept, or an instance of a concept. The hardest thing is coming up with so many names for stuff that never did exist in the first place. (And cache invalidation - the failure of a name.) $\endgroup$ – Scott Rowe Apr 22 at 11:26
4
$\begingroup$

"File" is an abstraction. Even worse, we use it for different abstractions.

Well, suppose I copy a file to this site, and you download it. Would you say it is the same file? What do you mean by same?

Actually, we'll have, more or less, parts of our hard disks (or is it a floppy?) containing bytes which we understand (through the magic of operating systems) as a representation of the same informations.

$\endgroup$
  • $\begingroup$ Hard disks are being replaced by solid state 'drives'. (What exactly is driving or driven? Even the words are abstracted away to absurdity.) And much of what we do is "in the cloud" now, so even talking about your computer doesn't apply anymore. $\endgroup$ – Scott Rowe Apr 20 at 17:35
  • $\begingroup$ My not so abstract computer actually has a hard disk, so it does $\endgroup$ – Michel Billaud Apr 21 at 12:38
  • $\begingroup$ Hey, I have a dial telephone sitting on a shelf, but nothing to plug it in to. Give it a few years, then computers will no longer even have screens or keyboards, because most of what we need can be done with voice, as a million years of evolution sans reading has demonstrated. It is being done with voice, and increasingly will be. The question "what is a file?" will no longer have any referent, or anything to prompt it. Files and screens were a temporary phase, like telephone dials and switchboard operators. $\endgroup$ – Scott Rowe Apr 21 at 13:41
4
$\begingroup$

The question is actually quite deep. For instance, I'm sure you've heard the phrase "everything is a file," that is associated with a design of Unix operating system. So, the answer could be puzzling "a file is almost everything in Unix," for example devices can "look like" files to some processes. They use a file as a common interface between many processes. Hence, the file is quite a general notion of a sequence of bytes in Unix.

My simple answer would be that a file is a sequence of bytes with a reference to them, by which you can access these bytes.

$\endgroup$
2
$\begingroup$

Nothing wrong with citing all the "dictionary" definitions found on the Internet.

I'd add that a file tends to be the lowest level of abstraction of a container or boundary around data that the Operating System manages. That is the file's name is accessed through the OS and if you want to know the bits and bytes of data "in" the file you need an Application or program to read/write the file. The OS "promises" to return the data to any Application in the same order in which the creating Application specified but physically the OS may scatter the data to the wind - as long as the OS can return the data properly to some Application.

$\endgroup$
  • $\begingroup$ Right, the OS exists basically to manage files and launch programs. $\endgroup$ – Scott Rowe Apr 20 at 22:45
2
$\begingroup$

I think in this case a short answer is better than a long one, which is harder, but I might give it a shot:

A file is a list of bytes and an identifier [location].

Make sure to explain that there are no physical files and the term is just an abstraction. With my definition you can explain the following:

  • If you create a new file with a different identifier but the same bytes, it is a copy of the file.
  • If you just change the identifier [location] you say it moves
  • If you keep the identifier but change the file is said to change.

The identifier can be different, e,g. a filename ("C:\Desktop\MyFile.txt") or a URL ("https://www.mydomain.edu/MyFile.txt"), but the content is basically always a list of 0 to many bytes.

You could go into details how files are stored and how http works, but in the end you only need to explain the abstraction to understand what "file" means.

$\endgroup$
1
$\begingroup$

Was in a conference the other day and someone was showing intercept security... A .exe file started with MZ. Why? Those are the initials of the man who created the first DOS executable file format. Many kinds of files have 'signatures' in the first few bytes.

I used to use a tool called 'strings' that would show any displayable sequences of characters in an otherwise 'binary' file. Helpful sometimes. We have gotten far away from this level of reality in our everyday use of computers, so it is good to show that there is really no mystery, it is all just a heap of ideas people have had over time, piled up in layers. Start at the bottom with characters and follow the clues.

Attack it in many ways, showing the aspects of 'files' that are meaningful to you. Give some of the history. I am sure you can come up with analogies. One issue is that although 'file' makes some sense, 'folder' does not, because we don't ever nest manila folders! Nnnnt! The other term, 'directory', has fallen in to disuse, and really is not any better.

What is a synonym for what we call folder...? There isn't one! It is a brand new concept, like variables. Nothing else in our world is like that. This is why we have to show that analogies are limited and misleading. You have to actually know some things.

$\endgroup$
  • $\begingroup$ And how many of the students have seen a manila folder? A floppy? A dial phone? They have no experience with the things we analogize from! Lost beyond lost in a hall of mirrors. $\endgroup$ – Scott Rowe Apr 20 at 13:06
  • $\begingroup$ Could you explain what you mean by "lost beyond lost in a hall of mirrors."? $\endgroup$ – LogicalBranch Apr 22 at 11:00
  • 1
    $\begingroup$ @LogicalBranch Sure. Humans usually make meaning by relating to things in their environment. The floppy disk is the icon for 'store' because they used to be commonplace. But to someone who has never seen one, it doesn't have any inherent meaning. If a student is asking what a file is, it probably means they have no referent, no commonplace objects, situations and processes that they can intuitively substitute. If all of computing is strewn with metaphors and references to never-before-known things, it is basically like going to a foreign planet and trying to start from nothing. $\endgroup$ – Scott Rowe Apr 22 at 11:12
  • 3
    $\begingroup$ Beyond, that, the references seem pointless and strained. Floppies only make sense without an internet. And if your entire life experience is that the internet has always just "been there", how can any other scenario make any sense? If I put you down in the Amazon rainforest and said, "There is lots of food here. Just watch out for the dangerous things." would you be likely to survive even for 2 days, or know what killed you in your sleep? No. This is the world we put our children in to with no preparation, because we cannot see it from their point of view. $\endgroup$ – Scott Rowe Apr 22 at 11:17
  • 1
    $\begingroup$ Sure. This is why I keep crying like the little voice in the wilderness: "We have to start with the the basic level of how things actually work!" And everyone here says I am wrong. We shall see. Wait... We are seeing now. $\endgroup$ – Scott Rowe Apr 22 at 11:20
0
$\begingroup$

A slightly different but insightful take on this :-

On UNIX systems everything is a file. A file of data is a datafile but a directory (folder) is also a file. A device is a file (found in the /dev directory). Programs are executable files and even running program and system states have associated files (found in /run). Network connections are files that can be read and written.

I suppose that explains why its difficult to define what a file is. In a physical sense it is just a list of connected disk or tape or memory sectors containing codes for data values.

$\endgroup$
0
$\begingroup$

I'd actually answer this question from an Intro student from more of the HCI perspective, because they likely have more experience using a computer than understanding how the computer works. @MichelBillaud had a similar notion in suggesting it as an abstraction (although most intro students won't fully appreciate what abstraction means the point of asking what a file is). Relating the abstraction to what they already understand in the physical world helps establish a good foundation.

I'd start by explaining that the first personal computers with graphical interfaces (Xerox Star if they want a historical context) faced the challenge of making it easy for someone who works in an office learn how to work with a computer, which stores information digitally instead of on paper.

In an office, they might have records of a client's information that they'd traditionally write on a piece of paper and store it away in a file cabinet. That file is a record of related information that you can look up by a name. That metaphor works for computers. They store information electronically instead of on paper, but that digital record is organized in one place and can be looked up by the file name.

From there, you can build upon that fundamental to explain different file formats (e.g. plain text vs binary) or how the metaphor extends to other abstractions of digital data represented in ways people can relate to in the physical world (e.g. folders, storage, copying/moving and recycle/trash, to other WIMP metaphors.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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