Code is step by step directions, but for computers.
Code is a way to tell your computer what to do under different circumstances
All code eventually gets broken down into ones and zeros
Developers write code in lots of different languages built for different purposes
Most code that people write today is built on packages of other people’s code
Code is probably the most fundamental building block of the difference between life today and life 20 years ago. So read this!
The goal of any piece of software – as large as Gmail or small as a little calculator – is to get something done. The easiest way to understand code is to try and think through how you’d get that thing done, step by step. If we wanted to build Gmail, or any email client, we’d need to make sure it does a few things:
Show me my emails
Let me send and reply to emails
Let me mark emails as junk or flagged
And if we wanted to dive deeper into one of these – let’s choose Let me send and reply to emails – we could break it down into even more specific tasks:
A text editor to write emails
Address fields to put in recipients and cc / bcc
A little “swoosh” sound when we send an email
We can also break these into even more specific tasks – let’s choose Address fields to put in recipients and cc / bcc:
A cc field
A bcc field
Show cc in sent emails, but don’t show bcc
Auto-complete email addresses in these fields
You get the point by now. Every “feature” – or thing you want to build – eventually breaks down into “when your user does X, the program does Y.” Code is how you make that happen in practice.
To make this even more concrete, let’s take a look at a little app I built last year called SNQL – it helps you track the sneakers you own and when you wear, trash, or sell them. I…need help.
Here’s what it looks like (I know, it’s not pretty):
When you add in a new pair, it gets stored in a database. So the code needed to build this program was pretty simple: HTML/CSS to build and style the web page, and Python to add the data you’re inputting into the form into a database on the backend. If you click on the Manufacturer Name dropdown, it shows you the available manufacturers; that’s also the work of a Python script.
Code “runs” on a computer, and gets written in a programming language. When you run a program, the computer executes those instructions. Most applications that you’re using – like Gmail – work by having their code constantly run in the background, displaying things and waiting for user instructions.
To get a better sense of what syntax means, let’s take a look at one of the most common logic patterns in code: a loop. If you have a group of items (like a shopping list) and you want to look at all of the items in the group, you might loop through them:
for item in shopping_list: print(item)
for each (item in shopping_list): console.log(item)
See? Pretty much the same pattern, but with slightly different wording.
Developers sometimes split languages into two broad types: low level and high level. Low level languages like Java and C++ are a bit harder to write, but offer more power and speed if you know what you’re doing. These often require special infrastructure to run, and go through a translator called a compiler.
Running a program can be really simple. If you’ve written a program in Python (
my_program.py), you can run it by typing (
python my_program.py) into the command line (Terminal) on your computer. In practice though, as apps have gotten bigger and more complicated, there are sophisticated ways to deploy and run your code that are a bit more involved than this.
Your app is unique, sure (except the guy who made Yo – wtf man), but most of them are actually pretty similar. Chances are that whatever you’re building, you’ll need to write directions for some of these:
Making requests to a web server
Generating cryptographic hashes
Creating graphs and plots
As people built these, they started to share the code they wrote publicly for everyone else to benefit from (it’s a really nice idea, in theory!). Those are called frameworks or packages or libraries or modules (there are more names but I’ll spare you), and they’re the basis of all modern code. There are tons of libraries out there for each of the 4 tasks we outlined above:
Formatting dates –
Making requests to a web server –
Generating cryptographic hashes –
Creating graphs and plots –
Using these modules means that instead of building the code to make a graph from scratch, you can use the code that someone else wrote to do it. Modern apps are full of these libraries, and that’s most of what you should think about when you hear open source. Open source just means that the library code is public for everyone to see, and generally also implies some community around improving and maintaining that code.
Framework, module, package, library
One of the best ways to understand what code is and how developers work is through data: the 2019 Stack Overflow Developer Survey is a great place to start
Some programming languages have very specific purposes: SQL, for example, is exclusively for querying a database
Learning to code has been in vogue for the past few years, and there are more online resources to get it done than you could possibly ever cover in a lifetime