The Code that took Astronauts to the Moon is full of Comedy and Heroism
MIT’s brightest engineers didn’t lose their sense of humor when taking us to the moon
No astronaut launches for space with their fingers crossed.
Chris Hadfield.
When astronaut Chris Hadfield said that, it is likely that he had not seen the code created by the programmers.
This is part of the code that controlled the Apollo Guidance Computer:

The original code is public on GitHub, and modern programmers have discovered a lot of funny comments and very smart routines that saved the lives of the Astronauts.
Fasten your belt and come with me to discover what was it like to program the machine that took humanity to its more dangerous and adventurous trip.
We choose to go to the moon in this decade and do the other things, not because they are easy, but because they are hard.
President John F. Kennedy. Moon Speech.
Among the people chosen for this challenge were the most brilliant scientists on the planet.
Margaret Hamilton, the director of the Software Engineering Division that developed the on-board flight software for NASA’s Apollo program, was known for her approach to preventing errors in software.
Margaret also looked like a cheerful person who allowed jokes in the code.

She’s probably proud that modern programmers continued this tradition on GitHub:


Take Off
We would need degrees in physics, math, mechanical engineering, and rocket science to understand the process used to put humans on the Moon. But I’ll show you the most important steps in simple words. Starting with the Take-Off.

The Launch Vehicle Digital Computer (LVDC) was a computer that provided the autopilot for the mighty Saturn V rocket from launch to Earth orbit insertion.
This computer, millions of times slower than modern computers, ran a major computation loop every 2 seconds for vehicle guidance, and a minor loop 25 times a second for attitude control. The only remaining copies of this software are probably in the core memory of the Saturn V rockets on display at NASA sites.
Orbit Insertion

After circling the Earth one-and-a-half times, the third stage reignited for six minutes to send Apollo 11 on its way to the Moon.
This strategy is called orbital spaceflight, and it’s the best strategy to travel in space using the least propellant possible.
Let’s see it on an animation:

For the trip to the Moon, the orbits were like this:

Here’s where the Apollo Guidance Computer was the protagonist, correcting the orientation and acceleration of the spacecraft.
On Earth’s surface, it’s easy to know where is up and down, North and South, but in space, we need extra references to know where are we going. A common task for the astronauts was to point to a star to calibrate the gyroscopes connected to the computer.

To operate the computer, the astronauts used the keyboard to enter a verb and a noun (e.g. point to star 27989). In the image, you can see the two buttons for verb and noun.
The programmers dedicated one of the Easter Eggs in the code to this with a quote from Shakespeare:

There are extra references to Shakespeare in the Lunar Landing Guidance Equations file:

Landing the Eagle

The most famous story behind the Apollo Guidance Computer is about what happened when the astronauts were about to touch the Moon.
In the words of Margaret Hamilton:
The computer (or rather the software in it) was smart enough to recognize that it was being asked to perform more tasks than it should be performing. It then sent out an alarm, which meant to the astronaut, ‘I’m overloaded with more tasks than I should be doing at this time and I’m going to keep only the more important tasks’; i.e., the ones needed for landing … Actually, the computer was programmed to do more than recognize error conditions. A complete set of recovery programs was incorporated into the software. The software’s action, in this case, was to eliminate lower priority tasks and re-establish the more important ones … If the computer hadn’t recognized this problem and taken recovery action, I doubt if Apollo 11 would have been the successful moon landing it was.
If you want to know more about this story, you can check this video. This example illustrates the importance of testing software against every probable outcome, especially when you’re trying to protect astronauts from the scary depth of space.
Burn Baby Burn

Burn Baby Burn is the name of one of the most famous routines of the AGC program. It is the Master Ignition Routine for the Lunar Module.
The name is the engineers' own tribute to the people of the Los Angeles riots.
The lines of code of the routine are not easily recognizable for modern developers because it’s assembler code, but in the comments, we can find more interesting Easter Eggs:

The jokes in the code did not replace the seriousness and importance of the situation. The 3 astronauts returned safely to Earth, and we all enjoyed one of the greatest milestones in our history.
When I started programming, over 10 years ago, I felt the indescribable emotion of creation. Seeing a machine behave exactly as you programmed it is comparable to the thrill of driving a race car at high speeds.
I can’t imagine what it must have felt like for the Apollo programmers to see the majestic machine they programmed to deliver 2 astronauts to safety on the surface of another world. They were exploiting the limit of the curiosity that makes us human.
References
· Great Minds: Margaret Hamilton (Youtube) · The Apollo Guidance Computer · Burn Baby Burn on GitHub · How did we get to the Moon? · Basics of Space Flight · GitHub discussion related to Apollo 13 · Apollo 11’s Source Code Has Tons of Easter Eggs, Including an Ignition File Titled ‘Burn Baby Burn’
