- Define a file
- Contrast text files and binary files
- Identify the function of file extensions
Have you tried to memorize a phone number "for a second" as you tried to write it down? Maybe you kept repeating it over and over? Have you ever felt a little overwhelmed when someone was giving you too much information at once and you were trying to keep up--but felt relief when you finally "got it"? As humans, we can only hold a few things in our heads before they start to, well, vanish or get mixed up. Our working memory is not too reliable!
Computers also have limited working memory. Just like us, they keep things in working memory that they're, well, working with.
When computers or people run out of space, they write down information stored in their working memory. Humans sometimes use a napkin, Post-It Notes or the back of their hands. Computers use files. The stuff computers write into their files fits into two main categories:
- Information humans can read ("text files")
- Information only computers can read ("binary files")
Developers create lots of files. This README will help us all get on the same page with how to talk about them.
A file is a thing computers use to store facts ("data") or processes ("programs") for later use.
Computers think in electricity.
Whoa!
Computers' thoughts are usually shown as 1's and 0's. This is called binary code. When computers write things down, they often write them down in files in their language, binary. These files are binary files.
Types of binary files are images, music, and software programs. We can create these files with Adobe Photoshop, the C programming language, or Ableton.
Nobody is exactly sure how humans think. That's a question for science or philosophy. When we write our ideas down, we write them in files in our language, text. These files are text files.
Types of text files are HTML, letters to grandma, a list of student grades for a grade book program, directions to Carnegie Hall, etc. We create these text files with text editors like Visual Studio Code, Atom, Sublime Text, vim, or emacs.
ASIDE: You might hear some developers call text files "plaintext" or "plain text files" They all mean the same thing.
What about files made by word processors Microsoft Word or MacOSX's TextEdit? While you're typing text, those programs store the text as well as information about the text (which font to use, which words are in bold, whether these next five lines are part of a bullet-list, etc.) in the same file. To make the loading and saving fast, these programs save the file in binary.
Since word processing programs store their output in binary files and programs that read HTML (like browsers) or run code (like Ruby, Python, JavaScript, or Java) need text, Word Processors should not be used to create HTML or code. Developers do their work in text editors, not word processors.
Many file names have an "extension" that comes after a .
. It is not a
requirement, but it's a best practice. The extension is a "hint" to the
operating system of which program should be used to work with the file. For
example, LetterToGrandma.docx
has a docx extension which hints to the OS
that it should open the file with the Word word processing program by Microsoft.
The file job_offer.pdf
hints to the OS that it could open the file with
either Acrobat or MacOSX's Preview application. When the OS finds many good
options, it will ask for the user's help in selecting the right program.
Changing an extension does not change the type of file you have. A text file
called groceries.txt
could be renamed groceries.mp3
but it would still be
a text file. A Toyota with a BMW medallion does not suddenly become a BMW. Our
groceries
did not suddenly become music because we changed the extension.
Some operating systems, like MacOSX, hide the file extension by default. They reckon that most users "no longer care about it." Since we're developers, though, we will frequently dig below the "end-user" layer. When in a terminal, we will see full file names - including extensions.
Here's a table to help train your instincts in seeing text-files versus binary-files:
In this lesson, we have taken some time to get to know files. Files are things in which computers store data that needs to last a while or which their users might want to refer to again later. We've noted that files generally come in binary and text formats. And we saw that many files also have an extension that provides hints about which program should be used to work with the file.