Tell your students the math they’re learning is Hindu & Muslim technology

If a student was to ask you what was the most important piece of technology ever invented, what would you say? Hopefully you’d use it as a conversation starter, and see what they knew. Things that would likely come up would be fire, the wheel, agriculture, and plumbing. All of these could vie for the top spot. But one of the most powerful technologies ever invented isn’t even taught as a technology, or even an invention. Is it because we take it for granted, or because it’s invented by non-European cultures?

Before Europe had the numbers we have today, they had Roman numerals. The Romans were great at lots of things, but their arithmetic, bluntly, sucked. Quick, what’s XIX times LVIII? Clearly they didn’t do math using these clunky numbers; doubtless merchants had abaci that allowed faster calculations, but there was no way to record the calculations. The Greeks, so famous for their math, didn’t have a better numeral system. In any case, Greek mathematicians focused on geometric proofs, and considered arithmetic a trivial matter for members of the lowly merchant class.

At least as far back as 700 BCE Hindu mathematicians had to record what would have been stupendously large numbers for their cosmology; for example their estimate of the life of the universe is 4.3 billion years, which given what we know today is a pretty good guess. They needed a way to represent these numbers. Originally they gave different numbers names, like “veda” (4) and “tooth” (32). But they found a more efficient way using calculations on clay tablets covered with sand, where they traced different numbers and calculations. Words were dispensed with and replaced with symbols. We wouldn’t recognize the symbols now, but they were the ancestors of the numbers we use now, and they used a place value system based on powers of 10. For an empty place they used a dot. A case has been made that they copied this system from a similar system used in China in the first millenium BCE.

The Hindus certainly weren’t the only people that used a place value system. The Maya had a place value system maybe as early as the first century CE. And the Sumerian cultures had nearly every part of a place value system as far back as the second millenium BCE.

Hindu and Arabic Numbers

It’s interesting to think about why we don’t use these systems now. I am a huge fan of the Mayans and love to talk about their math. But their numeral systems had a couple of weaknesses. They used powers of 20 instead of 10, which would have made it difficult to create things like multiplication tables. Worse, instead of making their third-lowest place 400 (20×20) they made it 360 (20×18) because that was close to the length of a year and they were mostly interested in keeping track of dates. Their numeral system could easily have overcome these weaknesses but the Classic Mayan culture crashed in the late first millenium CE and descending civilizations were decimated by European invaders.

The Sumerians had a better chance to make a numeral system that lasted, but their system lacked some important parts. Unlike both the Mayans and Indians they didn’t have a symbol for an empty place, so they just left it blank. If we did things like the Sumerians then 102 would be written as “1 2”. They also didn’t have a way to mark a unit place, even though they could do fractional places. The order of magnitude had to be figured out by context. If we did things this way then “432” could mean 0.432, 43.2, or 432,000. (In fact we do this verbally today: if I say a house costs “two-fifty” you assume one thing, if I say a slice of pizza costs “two-fifty” you assume something else.) Worse, they used base 60, meaning that a multiplication table would be impossible to memorize by anyone but a genius. Still, the Sumerian base-60 place value system continues to be used today in the way we count time, angles and latitude and longitude.

Muhammad ibn Musa al-Khwarizmi
Muhammad ibn Musa al-Khwarizmi

Still, the Hindu numeral system might not be the default today if not for the Persian genius Muhammad ibn Musa al-Khwarizmi. You might have heard of him as the inventor of algebra, and that is more or less true (really he got a lot of it from the Hindus). But that completely understates his impact. After his famous book al-Kitāb al-mukhtaṣar fī ḥisāb al-jabr wal-muqābala (The Compendious Book on Calculation by Completion and Balancing from which the term “algebra” comes), he wrote a few less famous but maybe even more influential couple of volumes whose original titles are unknown but were translated as “So Said Al-Khwarizmi” and “Al Khwarizmi on the Hindu Art of Reckoning.” These translations were the Europeans’ introduction to the algorithms of arithmetic we still use derivations of today: long addition, long multiplication, long division and so on. 

So to rather than just saying al-Khwarizmi gave us algebra, it’s better to say that aK gave us nearly the entirety of what a layperson calls “math.” Is this a technology? Absolutely. There is nothing in the counting numbers that requires they be divided into powers of 10, as the Mayans and Babylonians could tell you. Arguably other place value systems might work even better: base 6 would have an easier times tables, base 12 would give us better fractional places and base 16 has the advantage of working with binary numbers central to computing.

But it’s because of this piece of technology that an average contemporary sixth grader can solve problems that would have only been accessible to the most advanced calculator in Roman times. It is because of this technology, of course, along with aK’s invention of algebra, that we have made so many other tools in math like the coordinate plane and calculus, and all of the practical inventions that have required complex calculations.

Alan Turing
Alan Turing

But the contribution doesn’t end there! In the early 20th century logician Kurt Gödel ruined the dreams of a generation of mathematicians by showing that in every logical mathematical system some true theorems couldn’t be proved. The British mathematician Alan Turing wondered if he could at least make a method to predict what those unprovable theorems could be. If this were possible perhaps we could place some logical land mine warnings around them. (Spoiler: you can’t do that either.)

This led Turing to ask what sort of things could be proven using a “mechanical process,” ie and algorithm. To think about this, he began by considering someone carrying out an algorithm in the style invented by al-Khwarizmi, like

23
x 15

He decided there was no reason this had to happen in two dimensions, so imagined instead a tape containing

23 x 15 =

from which a machine could carry out the algorithm by moving up and down the tape. This machine, known today as a “Turing machine,” is not a physical thing but rather a theoretical instrument that has the ability to calculate anything that’s capable of being computed mechanically.

“Computed mechanically” today of course means “can be done by a computer.” Turing didn’t invent the computer, rather he invented computation as we now understand it. But his method of computing began with the methods written by a Persian mathematician who’d studied the Hindus who maybe studied the Chinese.

We can’t say al-Kwarizmi invented our modern numbers and mathematical algorithms; rather he is similar to Euclid, who compiled different geometrical proofs (no doubt filling in blank spaces with his own genius) from Greek mathematicians into a compendious volume that shaped math for millennia to come. Certainly Euclid’s Elements and al-Kwarizmi’s “Compendious Book” are the most influential math textbooks of all time.

It’s surprising, if you think about it, that outside of specialized areas there is only a single numeral system that’s used in general today worldwide, regardless of culture or language spoken. Different countries might use different symbols for “2” and “4” but their calculations are all identical if you just change the symbols. This certainly suggests the power of this technology. And all of our science and invention, from molecular biology to Mars explorers, could not have been made if we couldn’t do the kind of calculations we can do.

But when students learn arithmetic, they are given this technology as if it has just been written into the universe with no invention necessary at all. I remember listening in shock when a commenter on a news channel said something like “give me an important invention that didn’t come from a European.” He’d never been taught that an invention we use today was created by Persians, Hindus and Chinese, because he’d never been taught it was an invention at all. We can do better than that.

Proposed computer programming standards

So this is my first try at creating computer programming standards. Note that these are not general “tech” standards, as tech can mean a lot of things (for example in Montessori it can have little to do with computers). Instead of talking about computers I say “computing machines” to mean any device that is controlled by a processor, which today can mean everything from your car to a fighter jet to your coffee maker. I’ve tried to minimize just learning a particular programming language, which is what most programming classes today do; mostly that is in the “Process and Application” section. I’ve created 8 categories that I think envelop the experience of working with computing machines, but I’ve probably missed something.

The categories I’ve chosen are:

  • Algorithms, meaning developing procedures to solve problems
  • Process & Application, meaning the general rules of procedural programs (loops, conditionals, etc.) and turning algorithms into actual code
  • Data & Classification, meaning the different ways that computing machines store data, such as data types (string, integer, etc.) and more complex data structures (objects) and databases
  • Logic, meaning the rules that apply to booleans and conditionals
  • Environment and Interface, meaning both the input and output devices of computing machines and also the user interfaces of software
  • Network and communication, meaning all the different ways computing machines talk to each other
  • Physical computing and sensing, meaning devices controlled by computers that do work in the world and analyze it
  • Debugging, meaning understanding the kinds of unexpected behavior we get from computing machines and how we can analyze and come up with solutions for them

There are other categories that I’ve debated including. Two specifically are: Hardware and History of Computation. The first is how computers physically work; this should be in here and the whole thing could be expanded to Computer Science standards, but I don’t know exactly what they are yet. The second is how the idea of computation has developed, going from Al-Kwarizmy developing algorithmic processes through Charles Babbage and Ada Lovelace developing the ideas behind doing it with machines, Alan Turing developing the theoretical underpinning of modern computation and John von Nuemann inventing the architecture of the computer, programmers like Margaret Hamilton writing the code for Apollo, and so on. This content is essential to include because it will engage more humanities-inclined students, but I don’t know if it belongs in standards.

The standards have levels ranking from what I might expect a young grade schooler to be able to learn up to what I think a small percentage of advanced high schoolers might potentially learn. The goal is to create an “all-some-few” approach to lesson design in which every level of learner is challenged and engaged.

Here are the complete standards:

  1. Algorithms
    1. Overview: many problems can be solved by a planned procedure of steps that can be carried out in a mechanical predictable way by a person or a machine
    2. Levels:
      1. Students can follow simple sets of instructions with only one outcome
      2. Students can distinguish between a mechanical and non-mechanical process
      3. Students can follow a set of instructions with conditional outcomes
      4. Students can describe algorithms verbally and visually
      5. Students can identify commands in a computer language that apply to steps in an algorithm
      6. Students can write a computer program implementing an existing algorithm
      7. Students can modify existing algorithms to get different results
      8. Students can make original naive algorithms to solve a problem
      9. Students can evaluate an algorithm for correctness and efficiency
        1. “Safe move”
        2. Asymptotic notation
      10. Students can understand proofs about the efficiency and accuracy of an algorithm
      11. Students can create an efficient algorithm
  2. Process & Application
    1. Overview: Machines can be programmed to execute algorithms using various coding interfaces that can be interpreted by the machine.
    2. Levels:
      1. Students can apply existing methods with or without parameters to get an output
      2. Students can match basic method keywords with desired outputs and order them in short functional segments
      3. Students can create simple conditional blocks that respond to hardcoded variable states
      4. Students can create conditional loops responding to hard-coded conditions and match them with loops in an algorithm
      5. Students can use main loops that run during the length of the program
      6. Students can create conditionals of moderate complexity that respond to data input by a user, and match them with branches on an algorithm
      7. Students can create iteration loops to move through collections of data based on loops in an algorithm
      8. Students can combine multiple conditionals and loops to create a single-function program
      9. Students can create simple functions matching a subprocess in an algorithm
      10. Students can create multi-function programs based on algorithms they have created
  3. Data & Classification
    1. Machines that do computations and apply algorithms store data of various types in different ways in order to perform operations on it.
    2. Levels:
      1. Students can identify different kinds of information, such as numbers, dates and text
      2. Students see how primitive kinds of data describe different kinds of real-world objects and situations
      3. Students understand that different kinds of operations and methods apply to different types of data
      4. Students can recognize complex data types that contain a number of primitive types and methods
      5. Students can identify how complex data types apply to real-world objects and problems
      6. Students can describe data types as superclasses and subclasses
      7. Students recognize complex data types that contain other complex types have methods or functions with different types as arguments
      8. Students can make original data classes to model real-world objects
      9. Students can identify and share data classes using a markup language such as JSON or XML
  4. Logic
    1. Computers at their core operate by evaluation of logical statements that follow certain logical rules.
      1. Students can classify statements as true and false
      2. Students can evaluate simple conditional statements based on truth or falsity and use them to make choices
        1. (“stand up if you’re wearing blue.”)
      3. Students can evaluate simple conditionals using conjunctions (AND) and disjunctions (OR)
      4. Students can evaluate multi-level conditional statements with basic operators
      5. Students can create basic conditional statements that can be used to solve real-world problems
      6. Students can apply more advanced operators such as XOR and NAND
      7. Students can apply Boolean operators to binary numbers
      8. Students can create complex Boolean operations to solve problems
  5. Environment & Interface
    1. When a human interacts with a machine there must be an interface through which the user provides data and instructions to the machine and the machine can provide information to the user
    2. Levels:
      1. Students understand the difference between input and output and can give some examples of each (not necessarily in a machine)
      2. Students can identify common input devices such as touchscreen, keyboard, mouse and camera, and can identify common output devices such as screen, speakers and printers
      3. Students can type short inputs and place things using a drag-and-drop interface with a plan for expected output
      4. Students can respond to basic computer requests for information, including username and password forms
      5. Students can interact with a computer in a text-based interface and use advanced GUIs
      6. Students can create text-based interactive environments for other users
      7. Students can used advanced GUI and text-based development environments with an expected outcome
      8. Students can create interactive environments for other users
      9. Students can understand and control how a device interacts with a computer at a machine level
  6. Networks & Communication
    1. Many machines communicate with other machines over different types of electronic connections.
    2. Levels:
      1. Students understand that devices they are using are connecting with other devices locally and over the internet
      2. Students can navigate a simple hyperlink environment
      3. Students can enter network addresses (such as URLs) with an expectation of reaching another device
      4. Students can understand and respond to events that occur through interfaces and distinguish them from events internal to the machine
      5. Students understand basic principles of how computers request, serve and interpret served data (what happens when you “go to” a Web page?)
      6. Students can create client-side interfaces that can be served over a network (such as an HTML page)
      7. Students can create interfaces that send and respond to data from the server during use (client-side programming)
      8. Students can create and interpret network requests at a text level
  7. Physical computing and sensing
    1. Processing machines can control other machines that collect information from the world perform physical work in the world according to a program.
    2. Levels:
      1. Students can identify devices that can connect to a machine and do physical work
      2. Students can identify what kind of physical work a device will be able to do
      3. Students can make a physical device do a simple motion or response, (such as spinning  a motor or turning on an LED)
      4. Students can plan simple motions for a connected physical device and explain it algorithmic fashion
      5. Students can convert an algorithm to control a machine into a simple program
      6. Students can plan a series of actions for a physical machine to solve a problem
      7. Students can plan and write a program that will make a physical machine solve a problem
      8. Students can modify physical machines to make them do different things than they were built for
      9. Students can make a physical machine to solve a problem and program it
  8. Debugging
    1. Often machines don’t do what we expected them to do or want them to do, which can result in an error message or in unexpected output. There are different types of errors that can happen in computing and many different reasons they can happen. Debugging is identifying the type and cause of an error and changing our input or the state of a program or machine so we get the output we expected.
    2. Levels:
      1. Students understand that an error message occurs because a program can’t interpret an input or because it’s in an incorrect state
      2. Students understand that an error can be understood by analyzing and changing input or the state of the computer or program
      3. Students can experiment with different types of input to analyze what is causing an error
      4. Students understand the three main kind of errors that occur when programming:
        1. Syntax or compile-time errors: the compiler won’t even try to run a command because it doesn’t understand it
        2. Runtime errors or exceptions: the compiler understands a command and attempts to run it, but the data it is using lead to an operation the computer can’t perform, causing the program to stop with an error (y=5/x, where x = 0)
        3. Unexpected output: the compiler understands a command and it runs without error, but doesn’t give you the output you were planning for
      5. Students can identify some causes of an error, such as unanticipated input, endless loops, memory overflows and incorrect data types
      6. Students can identify the type of error that’s occurring in a program and consider what kinds of actions might change the outcome
      7. Students can analyze error messages and use this information to find the location and cause of an error
      8. Students can anticipate the kinds of errors that might happen in a program and modify the program to avoid them
      9. Students can write methods that deal with exceptions in a way that records or logs useful information, allows the program to continue and gives a user-friendly output

 

Can We Escape the Forever Loop?

If you’ve used Scratch or a similar program to teach coding, it’s likely you’ve helped a student who asked why code like this isn’t working:

When green flag clicked - if(space key pressed) - Move(10)

The student is pressing the space key, but their sprite isn’t moving. They don’t understand why.

“Well,” you say, “that’s easy. What’s happening is the code’s only running once, and it happens instantaneously, so if you’re not already holding down space when the program starts, it sees that the key isn’t down, moves on, and ends the program. All you need to do is wrap it in a forev-”

And I’m going to stop you right there, before you doom the kid to a loop he probably won’t escape for years. Let’s go back in time. It’s likely you at some point learned to code using some kind of a console app, maybe Python or if you are as old as me maybe BASIC. In any case, you probably have written a HelloWorld2 program that went something like this:

name = input("Hi, what's your name?")
print("Hello " + name + "!")

Now let me ask you this. Why do you not need to do something like this?

while(name == "")
    name = input("Hi, what's your name?")
print("Hello nice to meet you " + name + "!")

In other words, how does the compiler know to just sit there and wait for you to enter your name before just moving on and running the program and printing “Hello  !”

If your answer is, “Well, that’s just how console apps work!” then I am a bit disappointed but I’ll give you another chance. Why do console apps work that way? In pretty much any console app, when you use an input command, it knows to sit there and wait until the user has entered some data ending with a linebreak (‘enter’) character.

Formally in programming this is known as an ‘event’. This is any change in state of the compiler’s environment; an event is often user input but doesn’t need to be. It can be a mouse click but it can also be the return of data from a network call or two objects colliding in a video game.

In a simple procedural program the only way to check for an event is to create an endless loop and check repeatedly 30-60 times a second. It’s not just Scratch that does it this way. Processing (and Processing JS in Khan Academy by extension) has the draw() function, which is just a forever loop. Greenfoot has the act() function, same thing. Even Arduino C is centered around the loop() function.

Except for the Arduino, all these are primarily game-creation engines. But real programmers rarely use a continuous loop like that. Most programs with user interaction are instead event-based. This means you create a handler that responds to an event like a mouse-click or key press. In JavaScript, for example, it’s something like this:

document.getElementById("myBtn").addEventListener("click", displayDate);

But that’s advanced programming! You can’t expect a simple program like Scratch to have event handlers. Oh yeah? How about this:

When (space) key pressed - Move 10 steps
An event handler in Scratch!

If you put in the above, it works out of the box. No Green Flag Clicked necessary. Oddly, I always thought of this as the more “basic” approach, probably because there is nothing to “start” the program. But really it could be seen as the more sophisticated approach. They have the start of full event-driven programming. Imagine if they had a block like this:

On event ( ) do:
The event handler Scratch should have

With something like this you would probably still have a few things stuff in the forever loop, but almost everything else – key presses, mouse clicks, collisions, changes in variable values, appearance and disappearance of sprites, etc. etc. – could depend on event handlers. Ideally there would be something to “turn on” the event handlers too, whether a green flag clicked or whatever. There is no reason that couldn’t be in there.

But what difference does it make? Why is the forever loop so bad?

Well, for one thing, if you ever want to teach any other kind of loop it is really difficult to come up with a way to work it in, because it’s already looping. If you try to loop something inside that, it will stop all the rest of the action of the sprite. If you want to iterate, or have a conditional loop, you have to kludge it by creating a counting variable or condition and checking it repeatedly in the forever.

But in an event-driven program with multiple different event “threads” (weird, Scratch has threading too!), other handlers could respond to different events while a previous thread is still executing. This gives you an opportunity to put different kinds of loops in.

More importantly, though, it would give students a better idea of how most programs actually work. They could create an interactive environment like a modern web page.

Also, you will help them understand that a loop that repeats forever without a built-in interrupt condition is normally a really bad idea. Really there usually is some kind of interrupt, whether the stop sign or the pause button in Greenfoot and so on. But that’s outside the program the students are writing.

More importantly, we could get away from the idea that the only reason for programming is to make video games. We’re never going to get anywhere with coding education until kids start making programs that do real things, not just play.

On Teaching Magic

I’ve been thinking about Elodin from Patrick Rothfuss’ Name of the Wind series lately. Elodin is a teacher at a magic university attended by Kvothe, the main character; he teaches Naming, the most difficult of arts. In the first class Kvothe attends Elodin arrives thirty minutes late. He tells them he’s going to throw a rock and gives them ten minutes to calculate exactly where it will land. After they’ve struggled with the math and admit they can’t he calls an eight-year old servant boy into the class and tells the boy to catch the rock, which he does. Then Elodin writes the names of twenty books on the board and tells the students to read one. Which ones are most important? a student asks, and Elodin says he doesn’t know because he hasn’t read any of them. He puts stars by three, underlines two, and draws a sad face by one, then walks out of the room. Elodin is known to have been a genius who outshone even the brightest scholars of the university; he’s also considered to be insane, and is kept on as a kindness, and allowed to teaching Naming since no one understands it anyway. He is constantly giving Kvothe pointless tasks, and at one point he pushes Kvothe out a window and nearly kills him. He is always trying to keep his students intellectually off-balance because he says Naming’s not an art you can learn in a sequential way; it’s more a kind of inspiration.

Like anything in a fantasy novel Elodin is over the top, but it made me think of the different kinds of teachers we have. Mostly, good teachers are the kind whose units are planned out through the year and who progress through a subject, carefully building understanding like an architect. And then occasionally you get the teacher who’s kind of a flake, but who shows you things that no one else shows you, either because other teachers consider it beyond your level or just not worth teaching because it doesn’t connect anything else on the curriculum. Sometimes what they teach really is beyond your level and you’re just left confused but intrigued. These teachers’ classes are either engrossing or interminable, depending on the day and their mood and yours. They may not be good at what’s known as “classroom management,” and maybe their classes are a bit of a circus. Maybe sometimes they lose their temper where a more measured teacher would be patient and mature. They may try to teach you things they barely just learned themselves, just because they’re excited about it.

I’m oversimplifying; a teacher can be both organized and imagination-stretching or one or the other depending on the circumstances. But I know that it’s the Elodin-like teachers who gave me moments in a classroom that still stick in my head now. I’m not saying I’m an Elodin or that I’m trying to be, but I’d like to be the kind of teacher who at least sometimes pushes kids to do things that is maybe beyond them but maybe isn’t. I promise not to push any kids out the window.

Why Front-End Is So Hard Nowadays

I’ve been thinking about teaching HTML/JavaScript lately and why I don’t do it. One of the main reasons is that front-end as it’s done today is much harder than learning a language like Python or Java or C. This will surprise you if you’re a developer who fell into a Rip Van Winkle type sleep in about 2002.

It used to be that making the “front end” of a web page (basically HTML + stylesheets + JavaScript) was a great way to get started learning to code. After all, you could start with something like this:

<html>
<body>
Hello world!
</body>
</html>

And hey, open that code up in a browser and it will still work! The difference is that in those days, every single element or file you added, no matter how complicated it was, was written by your own hand. You never looked at your file structure and said “what the hell is all this stuff for?” (At least, not if you recently wrote it.) And you could use code that you entirely wrote by hand for professional -level production! Sure, you could by using FrontPage or DreamWeaver, but even then if you spent a little time you’d understand what the code they put in was for.

And if you wanted to see how it was done, you could just go on the web and hit “show source.” You could read everything that made a web page do what it does, and if you spent enough time you could understand it.

Nowadays, however, professional-level front-end almost always involves some kind of “framework.”  The definition of a framework is kind of hazy, but I’m going to use a broad definition that includes everything from Angular to Ruby on Rails to .Net to React, knowing very well that those don’t really go in the same category. What many of them have in common is that there is a moment of instantiation where some huge file structure is automagically constructed for you. It will usually create something like this:

Angular File Tree

And that’s just the top tenth or so of it. Note that depending on the “framework” (again using that term very loosely) your file structure there could include a lot of backend stuff too, for example in Ruby or .Net.

So someone set all this stuff up to make it easier for you, right? No way you were going to make all those files. But here’s the problem: now you have a digital house of cards where if you screw up just the wrong thing the whole thing comes crashing down and stops working.

But, I mean, you can’t just leave it alone either unless you want to publish a page that says “Welcome to [framework]! Click here for a tutorial to make your page.” Presumably you started this whole process because you want to make a website with some content.

So a lot of the time you spend is learning what small tiny fraction of these files it’s (sort of) safe to screw with. And you may work with this framework for a very long time before you know what most of those files ever do. I’ve been doing .Net long enough to at least know what most of the files in an MVC file structure do. But sooner or later they’re going to change the whole framework and everything will be confusing again. If you don’t believe me as anyone who learned Angular 1.

And things get worse when you need to use more than one of these frameworks at the same time, as often you do. If you think that a .Net or an Angular framework alone are confusing, try to figure out how to shuffle these two houses of cards into a single house that still stands.

And forget seeing how someone else does something. Most professional javascript today goes through a minifier, Now if you try to read someone’s script you’ll see something like this:

minified javascript

 

 

 

 

 

 

 

Good luck trying to figure out how that works!

Of course you could still teach people to make a website the old-fashioned way. But the question is, is it worth it? Might it be that the baroque intricacies of cascading stylesheets will become as distant to users in the future as pointer-level memory management is to most people that use languages like Java or Python?

Not sure what to do about this. What people want from a web app nowadays requires these frameworks. But it’s sad to think of how it’s changed.

Quantum Computers Will Kill the Web as We Know It

cryptographyRecently I’ve been having students play around with some “toy” encryption programs, mostly simple double-Caesar encryptions, which is a good way to learn about text in Java. As with everything I started thinking and reading about encryption, and came to a terrifying realization: encryption for regular people is doomed.

About 25 years ago a coder named Phil Zimmerman invented an algorithm that has become central to the net. It was modestly named Pretty Good Privacy, but it was a method of encryption that was free, usable by pretty much anyone, and almost completely uncrackable by pretty phil_zimmermanmuch anyone, even the US government. It was based on a relatively simple mathematical principle: if you have a factor of two very big prime numbers (where ‘very big’ is at least 40 decimal digits, though for modern implementations more likely 150 or 300 digits) it’s almost impossible find those factors. Specifically, for a regular fast processor it would take millions of years of trials; a huge multi-core supercomputer might get it done in your lifetime but it would take years and the computer couldn’t be doing anything else.

As with so much about info tech it’s easy to forget how revolutionary this was. Before that, really good encryption was only really available to big governments and maybe corporations. I’m not really sure what encryption methods they had; probably they already had a prime-based method similar to PGP, but I don’t know
. Now it was available to everyone in the country, and pretty soon the world as method predictably spread beyond our borders (as Zimmerman, an anti-nuclear activist, certainly intended it to). The US government freaked out almost immediately, and by 1993 Zimmerman was being prosecuted. Zimmerman cpgp-logoleverly published the code as a hardback book, which was indisputably protected by the First Amendment. Later court cases over similar encryption methods established the principle that code is protected by the First as well.

Even if the government had succeeded in prosecuting Zimmerman it would have done nothing to put the genie back into the bottle. The basic algorithm was easy to program and implement by any 220px-edward_snowden-2talented coder, and soon was. Many other encryption algorithms have since been invented using some variation of Zimmerman’s prime number hack. PGP is still around as well; most recently Ed Snowden used a more advanced version of PGP to share his whistleblowing documents with Glenn Greenwald and Laura Poitras as documented in Poitras’ intense documentary Citizen4.

In 1980 physicist Richard Feynman proposed the concept of storing computer data not as ones as zeroes as people had done so far (and still almost entirely do) but as “qubits,” or quantum states of two-state quantum systems. In 1985 David Deutsch speculated in a theoretical paper about using these to make a computer that would solve at least some problems at a speed many many orders of magnitude faster than even the fastest digital machines.

In 1994 Peter Schor proposed a method for factoring large integers using this method in what algorithmic specialists would call “polynomial time,” as opposed to the “exponential time” it currently required. This is an extreme simplification, but to explain the difference between polynomial and exponential time consider a program that has to solve a problem with a “length” of 100 parts. In exponential time the program would have to solve a number of operations equal to 100 to some power, so say 100 to the 5th power, or about 10 billion operations. That’s a big number to us, but an Intel i7 processor that does about 300,000 operations per second could do it in a few hours. Exponential time, by comparison, would mean something like 2 to the power of 100, which is a number with about 30 digits, which the same processor couldn’t finish in the lifetime of our solar system, and possibly the universe. These are completely made-up numbers but hopefully give some sense of the difference.

qubitsLots of progress has been made in quantum computers, but as far as I know, no one has made a quantum computer that can execute Schor’s algorithm in that way. But you can be certain that the NSA and many other intelligence agencies are pouring an enormous amount of resources into solving this problem. In fact, if you were paying attention to the dates you might have noticed that Schor invented his algorithm within about a year of when charges were filed against Zimmerman for publishing PGP, so Schor certainly picked factoring large numbers as a challenging problem for a good reason.

There’s no way to predict technological progress, so no way to know when or even if Schor’s Algorithm will be implementable on a practical level. But likely it will happen. Not everyone will be able to do it. Only people who can afford top-level quantum computers will be able to, which for a long time will only be available to large organizations like governments and big companies. In addition to offering a way to break current cryptography, quantum computers also offer a method of encrypting that can’t be broken by a quantum computer.

In other words, when Shor’s Algorithm can be implemented, we’ll be back where we were before PGP: good crypto will no longer be available for the average user. If the NSA had had this ability when Snowden was communicating with Greenwald and Poitras, they could potentially have decrypted their messages, learned who Snowden was, and arrested him before he escaped the country.

Okay, then, so no more Edward Snowdens; that sounds pretty bad. But it’s not even the start of the problem. In the 25 years since Zimmerman invented his algorithm, the web has become central not only to most people’s lives but also our economy. A huge amount of business is done online, and all of this must be encrypted. You might have noticed that addresses at the beginning of your url bar often begin with ‘https’ instead of ‘http’. This means that your communication with the server is encrypted using the RSA encryption scheme, which depends on uncrackable primes in the same way PGP does. http_insecureIn the early 90s, encryption was for spies and hackers; now it’s essential to every person who uses the net. In fact, Google Chrome will soon warn users that sites using plain http are insecure.

I don’t suppose the NSA has any interest in hacking Amazon to steal my credit card number. But foreign governments might want to, or a criminal organization that has enough money to buy their own quantum computers. No doubt the government will try to criminalize ownership of quantum tech, but it will almost certainly work no better than any other attempts they’ve made to keep a technological genie in the bottle. Currencies like Bitcoin that depend on strong crypto will become worthless, as will the vaunted “blockchains” that every cyber-libertarian is predicting will transform our world.

Furthermore our lives will become entirely transparent to anyone with the money and power to buy the tech to look. And they will certainly exploit this ability. True privacy on the web will become impossible.

Eventually, like all other tech, quantum computers will become affordable to regular people and we will again be able to have really uncrackable crypto. This likely will take at least a decade, and that’s assuming no one tries to prevent it, which governments likely will.

I don’t know what impact this is going to have on our world. But it’s a question not enough people are asking.

How the Web’s interface is broken

screen-shot-2016-10-10-at-1-05-48-pmHow often has this happened: you click on something you didn’t actually want to see (maybe because you were trying to scroll with your finger), causing an image to fill the screen obscuring whatever you were actually trying to read. Instinctively you hit the ‘back’ button to get back to whatever you were trying to look at.

And…you’ve lost everything. You’re somewhere else completely. You go back to the page you were on before Facebook. Annoyed, you try to go forward again, but you’re looking at an entirely different post. You scroll down, but the post you were reading is nowhere to be seen. What happened?

Let’s go back a few years, like maybe 15. I was making websites back in the days when dinosaurs roamed the web. Modern developers, in the middle of fighting over whether to use React or Angular2, might entertain themselves looking at this list of old 15-20 year websites moldering on servers that nobody ever bothered to update or shut down. They laid things out with tables. Tables!

If that doesn’t mean anything to you, let me explain. Back in the day, when you got a Photoshop mockup from a designer, the first thing you’d do is chop it up into little boxes, export them from Photoshop as jpegs or gifs (no pngs or svgs in those days). Then you’d use the HTML <table> feature to plan the page out in rows and columns. This was a hack; the tables tag was made to create, well, tables, like rows and columns with headers. But before browsers had consistent and reliable stylesheets, it was the only certain way to always get the layout you were looking for.

Dole/Kemp '96!
No, we can’t have those Republicans back.

But in the middle of laughing at the silly old animated gif backgrounds, you might notice something, as for example on this page for Dole Kemp ’96: before the page even finishes loading everything is in exactly the right place, even before any of the images loaded. And after it loads everything stays exactly where it’s supposed to.

There’s a reason for that. Back then, instead of using styles, every image had a HEIGHT and WIDTH attribute (yeah, back then some people capitalized their HTML too). In the days of 56k dial-up modems, every kilobyte that went over the was precious, so you exported the images at the precise right size and then set that through the attributes in a table.

Compare that to many framework-driven applications today, especially when you’re loading them on a phone. You’ll be in the middle of reading a paragraph, and it will jump 300-400 pixels above and below you. The Talking Points Memo site for example (whose content I love, by the way), is terrible at this; when I read it on my phone I feel I’m chasing the content all over the page.

Nobody uses tables to build pages anymore (except Visual Studio’s .NET templates, because Microsoft). Now people declare the size of their images using stylesheets, if they even bother. When they do it’s probably done dynamically, sometimes by resizing on the fly using Javascript.

Now let’s get back to the lost Facebook post you meant to read, and lost when you hit ‘back.’

Back in the primitive days of the Web, the back button was a reliable thing. It took you back to whatever you were looking at last. Sure sleazy advertisers could try to override it with Javascript, but you learned to avoid those sites.

But the back button won’t get you back to what you were looking at now. Why didn’t it just close the image and go back to the post you were reading? Because the image you were looking at is actually the same url that you were reading before (because Facebook is what developers today call a ‘single page application’). There was actually some little ‘x’ in the upper right hand corner of the screen that would have closed the image and allowed you to read what you were reading, but you didn’t see it.

Good old back button
Old reliable

Now it’s too late, because you went off Facebook. When you tried to go back, in the continuously loading application the particular post you were reading is far down the feed. Facebook has loaded twenty or forty new posts in the time you were away; there’s no way to know how far you’ll have to scroll to get back to where you were. And because of Facebook’s constantly shifting algorithm weighing what should and shouldn’t be shown, it might be gone altogether. You may never even get a chance to like your friend’s cat pictures or make an angry face in sympathy to her political rant.

But it has to be that way, say the developers as they look up from their scrambling efforts to learn whatever Javascript framework displaced the one they were using last year. It’s Web 2.0! Anyways, why don’t you just get the app?

Listen: whenever engineers tell you ‘it has to be that way,’ they are failing at their job. There is no technical impediment to making a web that works the way people expect it to. Instead of fighting over what Javascript superset to transpile from, maybe we should be talking about that. Let’s start with making pages that stay in place while people read them, and making pages where the ‘back’ button does what it’s supposed to.

Help, I’m supposed to teach tech! What should they know?

Yesterday I got a message from a teacher on Twitter. She mostly teaches science but this year she’s supposed to teach a 9-week tech class. She said she was “not a techy but willing to learn” and asked me what I thought the kids should know by the time they are done. I was flattered to be asked, and it inspired me to write an answer I was happy with, especially the six things I think kids should learn in a tech class. Here’s a slightly modified version of what I wrote:

Thanks so much for asking this; it gives me a reason to re-think what I want my own students to learn. I started out thinking about specific concrete skills (using variables or understanding files, eDebuggingtc.), but realized that those aren’t the most important things.

The things that I think kids should learn from technology education are skills that all good programmers and engineers have, but aren’t specifically tech skills. Some of the main ones are:

  • Think algorithmically: learn to plan out a sequence of steps that can solve a problem
  • Break down a problem: separate it into smaller parts that are easier to solve than the original problem
  • Debug independently: when a solution you have isn’t working, start testing smaller parts of the solution to see which part isn’t giving you the result you were expecting so you can hunt down the problem
  • Modularize solutions: look for ways you can re-use parts of earlier solutions that worked in other problems
  • Open-source your solutions: put your solution in a form that your peers can understand them and use different parts as needed.
  • Import solutions into your own: when a peer has come up with a good way to solve a problem that’s part of the problem you’re working on, don’t re-invent the wheel. Use a modified version of their idea, while giving them credit of course.

Of course these are huge goals and not easy to impart to a student even if you have whole year with them, let alone 9 weeks. You didn’t say how many classes you have a week, but I’d focus on just a couple of them, maybe the first and second or first and third.

As for what specifically to do, this is challenging even if you are given clear goals, let alone if you don’t. I’m sure you already have, but the first thing I’d do is feel out the administration more to try to get a better idea of what they expect to come out of it.

Assuming they really don’t have a particular goal in mind, my advice is to be a little bit ambitious and aim for a target you might not achieve at least the first few times around. If you’re a Google Apps school, the students will learn how to use the apps in their other classes pretty quickly on their own. If this is the main focus of your class I predict they and you will be bored very soon.

Khan Academy ProgrammingOne of the things I highly recommend for this is the Khan Academy tech classes. It’s easy for the kids to log in with their Google Drive accounts and for you to create a class where you can monitor them. The classes are very self-directed, with videos accompanying an interactive programming window, so if students have headphones they can all proceed at a pace that works for them. As a teacher I’m sure you know that with any subject some students will take to it like a fish to water and others will have a great deal of difficulty. This is doubly true for programming.

Some things you might have them learn are:

If you continue to do this class and your school is willing to spend a little money (really very little) on some hardware, I’d recommend ordering some Arduinos from Adafruit. and teach kids to make some simple electronic devices such as these ones .

 

Best first “pro” language (part 2 – Javascript)

Javascript LogoThis is part of a series on what is the best first ‘pro’ language, meaning something that’s actually used for professional applications. Last week I talked about Python, this week I’ll attempt to face the monster that Javascript has become.

I’m old enough to remember when people didn’t even really consider Javascript a programming language. They called it a “scripting” language or some other diminutive. To be fair, in those days they weren’t necessarily wrong. In the late 90s and early 2000s when I was in the Web business, Javascript was good for nothing but juggling the HTML Document Object Model. The DOM is the complex framework in the browser the controls the appearance and content of your web page. It’s what gets changed when text changes on a rollover or a menu drops down.

That is what made me think, once, that Javascript was a good first language for all its flaws. One of the challenges of any programming language is getting the students’ work in front of other people in a way they can see what the students have accomplished. Java used to be able to do this with Java Applets that ran on a browser. But Applets are dead as a doornail because Oracle could never deal with the security vulnerabilities they entailed, so browser makers stopped running them. With Javascript, if your students can make a simple rollover or dropdown, you can put it live and tell people to come see it.

But there are serious obstacles to this approach. The main problem is that first the students must learn HTML, Cascading Style Sheets and the Document Object Model. HTML is pretty easy, you can teach them enough to be able to do something useful in a month or two. But CSS and the DOM are convoluted and unpredictable, scarred with the remnants of the late 90s browser wars when the two major browsers roamed the earth with DOMs completely different from the World Wide Web Consortium’s official version, and hapless front-end developers had to kluge their Javascript to deal with all of them at the same time.

For all that it might still be worth it it Javascript was sitting still enough to be able to get students to the point they could do a simplified version of what web front end programmers do today. But real-world Javascript has been transforming itself at a terrifying pace. In a way it no longer makes sense to think of Javascript as a single programming language. It’s more like the flu; just because you could deal with last season’s version, it doesn’t necessarily help you with the next one.

Javascript ModulesEvery few months, it seems, everyone is excited about a new front-end “framework.” Frameworks are new downloadable modules of Javascript and CSS that come up with some (supposedly) better way of handling things in the DOM of various browsers. A few years ago everyone was using jQuery, which isn’t exactly a framework maybe but was an easy way to do a lot of visual things like dropdown menus and more importantly get fresh information from the server without loading a whole new page using AJAX. But Google had developed their own way to do that using a framework called Angular which is based on the Model View Controller web paradigm. At the same time Facebook developed a framework called React that wasn’t made for client-server interactions but which many people consider better than Angular for dealing with events in the user interface. Now Google has made Angular 2 which is very different from Angular.

But there are a million other different approaches and ways to use Javascript, including add-ons that do “polyfills” which trick browsers into using features they don’t have built in, completely different languages like Typescript that “transpile” into Javascript so browsers can run it, the npm module loader and Node.js, which is a version of JS that can be used on the server side where languages like Java, Ruby or Python would normally go. Javascript itself has added new features like returning functions from functions; ECMA16, the new version of JS, has a bunch of entirely new syntax even though it mostly does the same thing the old version does. This post at Hacker News gives an idea of how confusing Javascript is today even for people who used to think they knew it.

None of this is necessarily bad; it may just be Javascript growing up and becoming a mature programming language. But maybe not a safe environment for a learner to be wandering around in. Of course you don’t need to learn Angular or React or Node or whatever to learn Javascript; by itself it can still be a pretty simple language. But if you learn it all by itself you lose the advantages of being able to put your programs in front of the user, and you have to deal with all of the other weaknesses of the language.

And there are a lot.

When Javascript was new it attempted to integrate the then cutting-edge paradigm of coding, which was Object Oriented Programming. This might make you think it had a lot in common with the similarly named Java, but it was an illusion. Java, like any other OOP language, is built around classes which become objects in a program. Javascript doesn’t have classes, it has “prototypes,” which are like classes in the sense that raisins are like chocolate chips in your cookie.

People have been trying to make prototypes more mature so they work like classes (in ECMA16 you can even call them classes, though they’re not really). But along the way everyone got bored and started chasing in the new shiny object in the programming world: functional programming.

I’m just learning pure FP myself (Haskell is the gold standard in the way that Java is the gold standard of OOP), so I can’t say if JS handles FP any better than it handles OOP. But this kind of tacking on is what makes Javascript such a hard language to follow. James Nicoll said of English, “We don’t just borrow words; on occasion, English has pursued other languages down alleyways to beat them unconscious and rifle their pockets for new vocabulary.” This describes the expansion of Javascript perfectly.

Then there is the ugly way that Javascript deals with data types. Some languages, like C or Java, are very strict about declaring what kind of data a variable can hold. Other languages like Python keep that away from the user but behind the scenes still have a good idea of what the data type of a variable is. And when you say x = 10 but you want x to increment by 0.01 you can tell Python to make x a float instead of an Integer.

Number data types in C and JavascriptIf you say x = 10 in Javascript then x’s datatype is…number. As far as JS is concerned x could become 87 billion or 0.0003. But as far as JS is concerned x could become the lyrics of the national anthem or a graphical DOM element. This is very, very far from the way a computer’s memory works, so when a student moves to a language that’s even implicitly typed like Python, let along statically typed like Java, they are going to be in for a terrible shock.

What’s worse is the casual way that JS “converts” one type into another, especially when you compare them, so for example 0 is “equal” to false is “equal” to an empty string is “equal” to undefined. I put “equal” in quotes because they’re not really equal, Javascript just acts like they are. This leads to Javascript’s ridiculous “triple-equals” comparison convention. As you probably know if you’ve done any programming, a double equals (==) is what you use when you want to know if two things are equal, so for example if(a==b){ //some code } means do whatever’s in the curly brackets if a is equal to b. (This is as opposed to “a = b” which assigns a to be whatever b is.) Double equals work in Javascript too, but because of JS’s ridiculous laziness with type conversion, if you want to make sure they are really equal (same value and same type) you have to say if(a===b) . In other words in Javascript (and only Javascript) you have to say “do this if a is equal to b, but I mean really equal!”

I’m not saying (here at least) that Javascript is a terrible language, but I am saying that Javascript is a terrible first language, with a few exceptions. Khan Academy’s Intro to JS is a good way to get kids’ feet wet with a programming language where they actually have to type the commands. In fact what they will be learning is Processing, a useful beginner programming language, but since this is another example of “do things in the little window by the code,” it does not count as a ‘pro’ language in the sense I’m using it here.

The other reason you might want to teach students JS is if you actually want them to build interactive web pages. In this case first teach students HTML and CSS together (start with CSS right away; in 2016 there is no use at all in teaching simple HTML with no styles). This should go on for about six months or so. At that point they’ll be ready to start manipulating the DOM in simple ways with JS.

Otherwise, let them learn JS when they have learned another language first.

When kids do something stupid on the computer

I am old enough to remember when stores like Radio Shack in the mall had computers sitting on display with nothing but a cursor blinking on a command line. There was no program running, no user interface to interact with. Inevitably the screen would look something like this (edited slightly to keep this blog PG):

trs80HELLO
SYNTAX ERROR: ‘HELLO’ IS NOT A COMMAND
WHAT IS A COMMAND
SYNTAX ERROR: ‘WHAT’ IS NOT A COMMAND
*&!# YOU
SYNTAX ERROR: ‘*&!#’ IS NOT A COMMAND

It’s hard to know what people who put the computers expected to happen. But what looks like vandalism isn’t, really. What probably happened here is that a kid who didn’t know how to work with a computer tried, assuming the computer would be designed to be cooperative. When they found it wasn’t, they had a normal angry reaction.

Recently I was co-teaching a class where the other teacher was teaching kids Blender. I knew Blender less than some of the kids, so I was more a fellow student than a co-teacher. But I’m also a grown-upSuzanne, so I studiously mimicked my co-teacher’s lessons, and soon learned a lot.

Some of the other kids did that too. But others, when it came to selecting the starting shape, picked not a sphere or a column but Suzanne, Blender’s built-in monkey head shape. Then they randomly selected various panels and stretched them in random directions until Suzanne looked like a jigsaw puzzle with a coupla pieces gone.

My co-teacher was incredibly patient, but I could feel his frustration. “Okay, that’s nice,” he said, on seeing the twisted parody of a monkey. “Now start again and follow the instructions please.”

If you’ve taught kids on computers you are familiar with this problem. I encounter the same thing when my kids, instead of naming their objects MySprite call them something like IAMLAZARRRRRR (and then can’t spell it when they try to refer back), or make a video game where all the sprites, the background and the obstacles are Nicholas Cage’s head or Honey Boo-Boo’s mom so you can’t see what’s going on.

To a child psychologist, what is happening is clear and predictable. When introduced to a new environment, kids start testing the extremities and boundaries. They want to see what can happen, what they can get away with. Play is the work of a child, as it’s said, and play is a step in learning.

From a teacher’s point of view, though, the problem is clear. In a specialized field like programming or using an advanced program there are narrow paths to success through wide fields of failure. The keys of a piano can be struck in an infinite number of ways, but only an insignificant portion of those will make a song. There is a tiny chance a kid will discover something useful this way, but the more advanced the system they’re working in the less likely they will.

Also, you have a lesson plan, and they are missing out on it as they screw around! You have got to get them on track NOW or they will be forever behind!

A hint to working with children: when you find yourself saying “I have to fix this NOW,” you’re courting failure (except, obviously, for situations where the children are literally in danger).

Firmly discouraging a child’s play is likely to lead to disinterest and alienation. So what do you do instead?

Here’s what I do:

“That’s a weird result! How did you get that?”

(Yes, I usually know, but I’ll let them tell me.)

“Wow, that’s cool, I’m going to try that later myself! Hey, I want to give you time to experiment later, but can you do the lesson right now, because I don’t want you to get behind.” (Yes, you really do have to give them time to experiment later.)

Of course this always gets them back on task 100% of the time. Haha, just kidding. They will probably continue to screw around and do inappropriate things sometimes. But at least you haven’t discouraged their natural curiosity, and in the future you can start to try to direct it.

As you go along, give them places where exploratory actions can get them useful results. Start to define boundaries for play that will get them somewhere. When they see this happening, they will become eager and want to follow it further. Now they’re on the hook, and you can start to reel them in!