WHAT IS

CODE?|

This is a heavily edited version of an interactive feature by Paul Ford.

You, using a pen and paper, can do anything a computer can; you just can’t do those things billions of times per second. And those billions of tiny operations add up. They can cause a phone to boop, elevate an elevator, or redirect a missile. That raw speed makes it possible to pull off not one but multiple sleights of hand, card tricks on top of card tricks. Take a bunch of pulses of light reflected from an optical disc, apply some math to unsqueeze them, and copy the resulting pile of expanded impulses into some memory cells—then read from those cells to paint light on the screen. Millions of pulses, 60 times a second. That’s how you make the rubes believe they’re watching a movie.

So many things are computers, or will be. That includes watches, cameras, air conditioners, cash registers, toilets, toys, airplanes, and movie projectors. Samsung makes computers that look like TVs, and Tesla makes computers with wheels and engines. Some things that aren’t yet computers—dental floss, flashlights—will fall eventually.

You can make computers do wonderful things, but you need to understand their limits. They’re not all-powerful, not conscious in the least.

The turn-of-last-century British artist William Morris once said you can’t have art without resistance in the materials. The computer and its multifarious peripherals are the materials. The code is the art.

How Does Code Become Software?

We know that someone, somehow, enters a program into the computer and the program is made of code. In the old days, that meant putting holes in punch cards. Then you’d put the cards into a box and give them to an operator who would load them, and the computer would flip through the cards, identify where the holes were, and update parts of its memory.

Computers can be seen as layer of technology of increasing complexity and abstraction, programming can happen at different layers.

layers

Let’s talk about modern typing-into-a-keyboard code. It might look like this:

ispal: {x~|x}

That’s in a language called, simply, K, famous for its brevity. 2 That code will test if something is a palindrome. If you next typed in ispal "able was i ere i saw elba", K will confirm that yes, this is a palindrome.

So how else might your code look? Maybe like so, in Excel (with all the formulas hidden away under the numbers they produce, and a check box that you can check):

Screenshot of Excel spreadsheet

Programming can also look like Scratch, a language for kids:

Screenshot of Scratch programming environment

That’s definitely programming right there—the computer is waiting for a click, for some input, just as it waits for you to type an “a,” and then it’s doing something repetitive, and it involves hilarious animals.

It may look like audio patch, "data flow":

Or maybe:

      PRINT *, "WHY WON'T IT WORK
      END

That’s in Fortran. The reason it’s not working is that you forgot to put a quotation mark at the end of the first line. Try a little harder, thanks.

All of these things are coding of one kind or another, but the last bit is what most programmers would readily identify as code. A sequence of symbols (using typical keyboard characters, saved to a file of some kind) that someone typed in, or copied, or pasted from elsewhere. That doesn’t mean the other kinds of coding aren’t valid or won’t help you achieve your goals. Coding is a broad human activity, like sport, or writing. When software developers think of coding, most of them are thinking about lines of code in files. They’re handed a problem, think about the problem, write code that will solve the problem, and then expect the computer to turn word into deed.

Code is inert. How do you make it ert? You run software that transforms it into machine language. The word “language” is a little ambitious here, given that you can make a computing device with wood and marbles. Your goal is to turn your code into an explicit list of instructions that can be carried out by interconnected logic gates, thus turning your code into something that can be executed—software.

In the '50s Navy Officer Grace Hopper developed the idea of a language for programming similar to English. A language that can be independent from the circuitry of the machine, and automatically translated to lower level instructions by a compiler. It was the beginning of modern coding.

A compiler is software that takes the symbols you typed into a file and transforms them into lower-level instructions. For example if we have a line of code in a text file that says:

PRINT {HELLO NERDS}

Our imaginary compiler program interprets it by doing lexical analysis, going character by character, starting with the “p,” grouping characters into tokens etc... Let’s be the computer.

Character Meaning
P Hmmmm...?
R Someone say something?
I I’m waiting...
N [drums fingers]
T Any time now...
Space Ah, "PRINT"
{ String coming!
H These
E letters
L don’t
L matter
O la
Space la
N just
E saving
R them
D for
S later
} Stringtime is over!
End of file Time to get to work.

What Is an Algorithm?

Algorithms don’t require computers any more than geometry does. An algorithm is a series of instructions that solve a "problem".

Ada Lovelace, despite living in the mid-19th century, a hundred years before computing as we know it, is considered the first programmer. She made an algorithm for the first analog computer (which was never actually created) and she had the intuition that the application of computers could go beyond crunching numbers.

Many algorithms have their own pages on Wikipedia. You can spend days poking around them in wonder. Euclid’s algorithm, for example, is the go-to specimen that shows up whenever anyone wants to wax on about algorithms, so why buck the trend? It’s a simple way of determining the greatest common divisor for two numbers. Take two numbers, like 16 and 12. Divide the first by the second. If there’s a remainder (in this case there is, 4), divide the smaller number, 12, by that remainder, 4, which gives you 3 and no remainder, so we’re done—and 4 is the greatest common divisor.Δ (Now translate that into machine code, and we can get out of here.)

There’s a site called Rosetta Code that shows you different algorithms in different languages. The Euclid’s algorithm page is great.

And that’s Euclid’s algorithm in PostScript. I admit, this might be fun only for me. Here it is in Python (all credit to Rosetta Code):

def gcd(u, v):
    return gcd(v, u % v) if v else abs(u)

A programming language is a system for encoding, naming, and organizing algorithms for reuse and application. It’s an algorithm management system.

P.S. What happened to women in Computer Science?

article
1

Not bad for six or seven decades—but keep it in perspective. Software may be eating the world, but the world was previously eaten by other things, too: the rise of the telephone system, the spread of electricity, and the absolute domination of the automobile. It’s miraculous that we have mobile phones, but it’s equally miraculous that we can charge them.

2

The world of code is filled with acronyms. K is modeled on another language called APL, which stands for A Programming Language. Programmers are funny, like your uncle. They hold the self-referential and recursive in the highest regard. Another classic: GNU, which means GNU’s Not Unix. Programmer jokes make you laugh and sigh at once. Or just sigh.

3

Compilation is one of the denser subjects in computer science, because the lower down you go, the more opportunities there are to do deep, weird things that can speed up code significantly—and faster is cheaper and better. You can write elegant, high-level code like F. Scott Fitzgerald, and the computer will compile you into Ernest Hemingway. But compilers often do several passes, turning code into simpler code, then simpler code still, from Fitzgerald, to Hemingway, to Stephen King, to Stephenie Meyer, all the way down to Dan Brown, each phase getting less readable and more repetitive as you go.

4

I find code on the printed page to be hard to read. I don’t blame you if your eyes blur. I try to read lots of code, but it makes more sense on the computer, where you could conceivably change parts of it and mess around. Every now and then I’ll find some gem; the utility programs in the Unix source code are often amazingly brief and simple and obvious, everything you’d hope from a system that prides itself on being made up of simple, composable elements.

5

Adobe created PostScript in the early 1980s and licensed it to Apple, its first success. Three-plus decades later, Adobe is valued at $38 billion. PDF is a direct descendant of PostScript, and there are PDFs everywhere. In code as in life, ideas grow up inside of languages and spread with them.

6

Two plus two usually equals four, but in a language like JavaScript if you add 0.4 + 0.2, the answer is 0.6000000000000001. That’s because those numbers are interpreted as “floating point” (the point is the period), and the JavaScript language uses a particular way of representing those numbers in memory so that sometimes there are (entirely predictable) rounding errors. This is just one of those things that you have to know if you are a committed Web programmer.

7

Well, he might have said it. It’s attributed to him, but it might be folklore. Nonetheless, great quote!

8

Meaning those companies are so huge that they can’t use as much off-the-shelf, prepackaged code as the rest of us but rather need to rebuild things to their own very tight specifications.

9

By the way, that earlier assertion about how $100,000 in singles can fit in a barrel? It comes from a calculation made in Wolfram Alpha, a search engine that works well with quantities. The search was, “1 US dry barrel/volume of 1 US dollar banknote,” and the result is 101,633.

10

User stories are often written on paper cards and arranged on a wall; they can also be two-dimensional computerized cards that are then moved around with a mouse and “assigned” to programmers.

11

Programmers spend much of their time dealing with different types of data. Let’s say I have a number x, like 7, and a word y, like “cat.” When I multiply x and y, what’s the result? A runtime error in many languages—because you can’t multiply a number by a word. The language Perl returns a zero, which is expedient but baffling, and JavaScript returns “NaN,” for “not a number.”

I know, I know.

How often are you going to be multiplying sevens and cats? Soooo much. The real world of data is messy, so you’re constantly converting one type of thing into another type—and the shading is subtle. Sometimes an e-mail address is just a bunch of letters and symbols; sometimes it’s a field just plucked from a database; sometimes it’s specially prepared to be sent into the Internet. Programmers write a lot of code that converts data from one type to another.

Some languages are incredibly vigilant about types, and what can be done with data of any given type. They push hard for programmers to nail down data types, and the payoff is that these languages can then identify problems before they happen—at “compile time” instead of later, when the program is running. A statically typed language like Java catches you before you multiply a poem or try to find the geographic distance between Chicago and a Social Security number. Other languages are far more caveat programmer.

12

A kernel is the lowest level of an operating system. The Linux kernel is like the engine in a car; the dashboard, windshield, tires, and seats come from a variety of sources. The Free Software Foundation asks you to call it GNU/Linux, to honor its roots, and some people follow this suggestion. Most people call it Linux, though, or refer to one of the Linux distributions, i.e., “Red Hat Enterprise Linux,” “Ubuntu Server,” or “Debian.” It’s worth noting that Linux is hardly the only Unix; there’s OpenBSD, FreeBSD, Solaris, AIX, and—well, you get the drift. The charts showing all the Unices are large charts.

13

If you’re old enough to remember DOS, you know what a command line is.

14

Disclosure: I’ve written about 500 lines of C code in my life, though I’ve read a lot about the language and worked through many tutorials. As a Web person, I just don’t do the kind of systems work at which it excels. If you work for a large software or hardware company, it’s far more likely you’ll find it in use.

15

“Object-oriented,” “imperative,” and “functional” are paradigms; a language like Python is referred to as “multiparadigm.”

16

Writing this article was a nightmare because I know that no matter how many people review it, I’ll have missed something, some thread that a reader can pull and say, “He missed the essence of the subject.” I know you’re out there, ashamed to have me as an advocate. I accept that. I know that what I describe as “compilation” is but a tiny strand of that subject; I know that the ways I characterize programming languages are reductive. This was supposed to be a brief article, and it became a brief book. So my apologies for anything that absolutely should have been here, but isn’t. They gave me only one magazine. If you want to rant, I’m ford@ftrain.com.

17

It’s a balance. You also don’t want to create a situation where engineers can’t play around, because then they’ll set up systems behind your back “just for testing.” That’s how Linux spread.

18

Technical debt is the idea that software often launches without everything buttoned up, to meet deadlines or because some features were prioritized over others, and over time, as systems change and evolve, a kind of code-debt builds up. It’s no different from infrastructure debt. Bridges, tunnels, or tech—to do new things in a compatible way can require painful, wasted effort. Sometimes, to move a system forward, you need to address that debt: Upgrade the balky server, deal with the fact that your user account manager tends to log people out without warning, or occasionally throw away a component and start again.

19

You know what, though? Cobol has a great data-description language. If you spend a lot of time formatting dates and currency, and so forth, it’s got you. (If you’re curious, search for “Cobol Picture clause.”)

20

Different computing eras smelled differently. The old, huge machines had a slight burning-metal smell. Early PCs gave off different odors of plastic, metal, and enamel. And who could forget the wafting scent of a monitor with smoke pouring out the back? The goat-like aroma of dozens of people in a computer center, up against a deadline? The odd smell of laser toner or massive piles of pulpy striped paper? Occasionally I’ll see a picture of a pile of old machines from the 1980s, and the olfactory memory will jump me.

21

Lisp is a language that programmers venerate because of its rich history and its simplicity—and the fact that such simplicity makes it possible for Lisp to program itself; it’s described as a “programmable programming language.” If you ever have bright programmers who need a challenge, send them off to learn Lisp. Some may return as insufferable evangelists, but more likely they will come back smarter and more flexible.

22

Enjoying Lisp programming is like enjoying prog rock or expressionist art; if you’re into it, you probably love it, and too bad about the squares who hate parentheses. Remember how the computer’s memory is kind of like a straight line, but programmers think in trees? That’s Lisp in a nutshell; it gives you an incredibly consistent way to think in trees. It’s as close to Zen as computing gets. Of all the languages in this essay, Lisp is the one I’d take to a desert island. It has the most to teach me about the hidden order of the universe.

23

HyperText Markup Language, the encoding format for Web pages since the Web began. Programmers argue over whether HTML is “programming” or not because they are paranoid about status and don’t want to allow mere tag-wranglers to claim blessed programmer status. So the text that appears here doesn’t count as “code” but as “markup.” The difference between an expert markup person and an expert coder is, from experience, somewhere between $20K and $70K in favor of the programmer.

24

When people talk about databases, they often use the acronym CRUD, for create, read, update, and delete. You might create books or customers or purchases; read the data when a user logs in and load up their name and information; update someone’s e-mail address; or delete a user upon request. A huge amount of code is all about managing CRUD operations.

25

Other languages, such as Perl or PHP, let you do the exact same things Java does, and they run on the same platforms—but they were originally designed for scripting, for quick evaluation of programs. They don’t have quite the same muscle.

It’s a matter of degree—to say one thing is more powerful than another is to invite a fight; someone will show up in the digital doorway and say, “Actually …” and your night’s ruined. But if I came to you and said, “I need to build a stock-trading platform in 36 months,” no one’s going to fire you for choosing Java. If I said, “I need a prototype of a new stock-trading platform in the next two months for a client who may or may not decide to build one, and it has to look beautiful in my Web browser,” I might use something a little smaller, not quite so enterprisey. Python would be a good bet. Ruby would also be fine.

26

I really, really like Clojure. It taught me a ton. But what applies to Clojure applies to other languages, too.

27

Oracle was none too pleased about this and—long story—sued Google.

28

The runtime for something like JavaScript is a little like the kernel in an operating system. It’s the set of services that runs when JavaScript runs, that are available to all JavaScript code. You start the runtime, and then the rest of your code runs within it, in the context it provides. In this case, that context was “the Web browser.”

29

Ajax is short for “Asynchronous JavaScript and XML.” It refers to a set of technologies that, when combined, turned Web pages into software. After Ajax became well-understood, much of the Web transformed from a publishing platform into an application-delivery platform, and, as a result, the Internet industry transformed into its current form.

30

People do complain.

31

Application Programming Interface—kind of a big, hairy set of classes and objects. There are also Web APIs, which are big, hairy sets of classes and objects that you retrieve using the Web.

32

A language is a way of perceiving the world. A standard library is a way of organizing the world. And an IDE is a way of bringing those things together in a lively and dynamic way.

33

In the same way Microsoft makes a tool available called Visual Studio, which it uses to write its own software.

34

You know who else is good at this sort of thing? Microsoft: developers, developers, developers, developers.

35

For, lo, in New York there was AT&T, which in New Jersey begat Bell Labs, which begat Unix. And it was very good. And in Rochester, N.Y., and later Stamford, Conn., there was Xerox, and it begat PARC, in Palo Alto, which begat Smalltalk. And it was very good. And in Cupertino, Calif., there was Steve Jobs, who begat, with many other men and women, the Macintosh, and it was well-marketed. But Jobs was cast out into the Valley and created NeXT, which married Unix, Smalltalk, and the Macintosh, and named its issue NeXTStep, which is what the “NS” stands for in NSThickSquareBezelStyle, for the influence of a platform is with us always.

36

I really like Django. It was written by kind people to help people in publishing. Ruby on Rails is probably the most famous Web framework, of course. It’s great, too!

37

“Comparison of Web application frameworks,” which is a solid Wikipedia page. In fact, Wikipedia is an essential programming tool. The summaries of languages and approaches are typically well-vetted and full of code samples.

38

What’s with the name, which basically means “jerk” in the U.K.? Torvalds told PCWorld: “I’m an egotistical bastard, so I name all my projects after myself. First Linux, now git.”

39

Actually, programmers don’t always talk as much as chat online, often using Slack. Slack is an Internet startup that provides a chat service organized around the needs of geographically diverse groups. A large part of its appeal is its simplicity and the ease with which it integrates with other products. Chat channels can quickly come to represent all the work that’s going on inside a company, as a set of streams of text, which can then be searched. Slack provides a short-term institutional memory, which has made a lot of nerds happy. It’s growing quickly. Slack’s investors recently valued it at $2.6 billion; by the time this issue is published, it will probably be worth more than planet earth.