The First Programming Languages: Crash Course Computer Science #11

The First Programming Languages: Crash Course Computer Science #11

CrashCourse

0:03 This episode is brought to you by CuriosityStream.

0:05 Hi, I’m Carrie Anne and welcome to CrashCourse Computer Science!

0:08 So far, for most of this series,

0:10 we’ve focused on hardware— the physical components of computing— things like:

0:14 electricity and circuits, registers and RAM, ALUs and CPUs.

0:17 But programming at the hardware level is cumbersome and inflexible,

0:20 so programmers wanted a more versatile way to program

0:22 computers- what you might call a “softer” medium.

0:24 That’s right, we’re going to talk about Software!

0:27 INTRO In episode 8, we walked through a simple program for the CPU we designed.

0:40 The very first instruction to be executed,

0:42 the one at memory address 0, was 0010 1110.

0:46 As we discussed, the first four bits of an instruction is the operation code,

0:50 or OPCODE for short.

0:51 On our hypothetical CPU, 0010 indicated a LOAD_A instruction— which moves

0:56 a value from memory into Register A.

0:59 The second set of four bits defines the memory location,

1:02 in this case, 1110, which is 14 in decimal.

1:05 So what these eight numbers really mean is “LOAD Address 14 into Register A”.

1:09 We’re just using two different languages.

1:11 You can think of it like English and Morse Code.

1:14 “Hello” and“....

1:16 mean the same thing— hello!

1:18 they’re just encoded differently.

1:20 English and Morse Code also have different levels of complexity.

1:23 English has 26 different letters in its alphabet and way more possible sounds.

1:28 Morse only has dots and dashes.

1:29 But, they can convey the same information, and computer languages are similar.

1:33 As we've seen, computer hardware can only handle raw, binary instructions.

1:37 This is the “language” computer processors natively speak.

1:40 In fact, it’s the only language they’re able to speak.

1:43 It’s called Machine Language or Machine Code.

1:45 In the early days of computing,

1:47 people had to write entire programs in machine code.

1:49 More specifically, they’d first write a high-level

1:51 version of a program on paper, in English, for example...

1:55 “retrieve the next sale from memory,

1:56 then add this to the running total for the day,

1:59 week and year, then calculate any tax to be added” ...and so on.

2:03 An informal, high-level description of a program

2:05 like this is called Pseudo-Code.

2:06 Then, when the program was all figured out on paper,

2:09 they’d painstakingly expand and translate it into binary machine code by hand,

2:13 using things like opcode tables.

2:15 After the translation was complete,

2:16 the program could be fed into the computer and run.

2:19 As you might imagine, people quickly got fed up with this process.

2:21 So, by the late 1940s and into the 50s,

2:24 programmers had developed slightly higher-level

2:26 languages that were more human-readable.

2:28 Opcodes were given simple names, called mnemonics,

2:30 which were followed by operands, to form instructions.

2:33 So instead of having to write instructions as a bunch of 1’s and 0’s,

2:37 programmers could write something like “LOAD_A 14”.

2:40 We used this mnemonic in Episode 8 because it’s so much easier to understand!

2:43 Of course, a CPU has no idea what “LOAD_A 14” is.

2:46 It doesn’t understand text-based language, only binary.

2:49 And so programmers came up with a clever trick.

2:51 They created reusable helper programs,

2:53 in binary, that read in text-based instructions,

2:56 and assemble them into the corresponding binary instructions automatically.

3:00 This program is called— you guessed it— an Assembler.

3:02 It reads in a program written in an Assembly

3:05 Language and converts it to native machine code.

3:07 “LOAD_A 14” is one example of an assembly instruction.

3:10 Over time, Assemblers gained new features that made programming even easier.

3:14 One nifty feature is automatically figuring out JUMP addresses.

3:18 This was an example program I used in episode

3:20 8:Notice how our JUMP NEGATIVE instruction jumps to address 5,

3:23 and our regular JUMP goes to address 2.

3:25 The problem is, if we add more code to the beginning of this program,

3:28 all of the addresses would change.

3:30 That’s a huge pain if you ever want to update your program!

3:32 And so an assembler does away with raw jump addresses,

3:35 and lets you insert little labels that can be jumped to.

3:38 When this program is passed into the assembler,

3:39 it does the work of figuring out all of the jump addresses.

3:42 Now the programmer can focus more

3:44 on programming and less on the underlying mechanics

3:46 under the hood enabling more sophisticated things

3:48 to be built by hiding unnecessary complexity.

3:51 As we’ve done many times in this series,

3:53 we’re once again moving up another level of abstraction.

3:56 A NEW LEVEL OF ABSTRACTION!

4:02 However, even with nifty assembler features like auto-linking JUMPs to labels,

4:06 Assembly Languages are still a thin veneer over machine code.

4:09 In general, each assembly language instruction

4:11 converts directly to a corresponding machine

4:14 instruction– a one-to-one mapping– so it’s

4:16 inherently tied to the underlying hardware.

4:18 And the assembler still forces programmers to think

4:21 about which registers and memory locations they will use.

4:24 If you suddenly needed an extra value,

4:25 you might have to change a lot of code to fit it in.

4:28 Let’s go to the Thought Bubble.

4:29 This problem did not escape Dr.

4:31 Grace Hopper.

4:32 As a US naval officer,

4:33 she was one of the first programmers on the Harvard Mark 1 computer,

4:37 which we talked about in Episode 2.

4:38 This was a colossal,

4:40 electro-mechanical beast completed in 1944 as part of the allied war effort.

4:44 Programs were stored and fed into the computer on punched paper tape.

4:47 By the way, as you can see,

4:49 they “patched” some bugs in this program by literally putting

4:51 patches of paper over the holes on the punch tape.

4:54 The Mark 1’s instruction set was so primitive,

4:57 there weren’t even JUMP instructions.

4:58 To create code that repeated the same operation multiple times,

5:01 you’d tape the two ends of the punched tape together, creating a physical loop.

5:05 In other words, programming the Mark 1 was kind of a nightmare!

5:08 After the war, Hopper continued to work at the forefront of computing.

5:12 To unleash the potential of computers,

5:13 she designed a high-level programming language called

5:16 “Arithmetic Language Version 0”, or A-0 for short.

5:19 Assembly languages have direct, one-to-one mapping to machine instructions.

5:23 But, a single line of a high-level programming language might

5:26 result in dozens of instructions being executed by the CPU.

5:29 To perform this complex translation, Hopper built the first compiler in 1952.

5:34 This is a specialized program that transforms “source” code

5:37 written in a programming language into a low-level language,

5:39 like assembly or the binary “machine code” that the CPU can directly process.

5:44 Thanks, Thought Bubble.

5:45 So, despite the promise of easier programming,

5:48 many people were skeptical of Hopper’s idea.

5:50 She once said, “I had a running compiler and nobody would touch it.

5:54 they carefully told me, computers could only do arithmetic;

5:56 they could not do programs.” But the idea was a good one,

6:00 and soon many efforts were underway to craft

6:02 new programming languages— today there are hundreds!

6:04 Sadly, there are no surviving examples of A-0 code,

6:07 so we’ll use Python, a modern programming language, as an example.

6:10 Let’s say we want to add two numbers and save that value.

6:14 Remember, in assembly code, we had to fetch values from memory,

6:17 deal with registers, and other low-level details.

6:19 But this same program can be written in python like so:

6:22 Notice how there are no registers or memory locations

6:24 to deal with— the compiler takes care of that stuff,

6:27 abstracting away a lot of low-level and unnecessary complexity.

6:29 The programmer just creates abstractions for needed memory locations,

6:33 known as variables, and gives them names.

6:35 So now we can just take our two numbers,

6:37 store them in variables we give names to— in this case,

6:40 I picked a and b but those variables

6:42 could be anything- and then add those together,

6:45 saving the result in c, another variable I created.

6:47 It might be that the compiler assigns Register A under the hood

6:50 to store the value in a, but I don’t need to know about it!

6:54 Out of sight, out of mind!

6:55 It was an important historical milestone,

6:57 but A-0 and its later variants weren’t widely used.

7:01 FORTRAN, derived from "Formula Translation",

7:02 was released by IBM a few years later,

7:05 in 1957, and came to dominate early computer programming.

7:08 John Backus, the FORTRAN project director, said:

7:10 "Much of my work has come from being lazy.

7:13 I didn't like writing programs, and so...

7:15 I started work on a programming system

7:17 to make it easier to write programs." You know, typical lazy person.

7:21 They’re always creating their own programming systems.

7:23 Anyway, on average, programs written in FORTRAN were

7:26 20 times shorter than equivalent handwritten assembly code.

7:28 Then the FORTRAN Compiler would translate

7:30 and expand that into native machine code.

7:32 The community was skeptical that the performance

7:34 would be as good as hand written code,

7:36 but the fact that programmers could write more code more quickly,

7:39 made it an easy choice economically:

7:40 trading a small increase in computation time

7:43 for a significant decrease in programmer time.

7:46 Of course, IBM was in the business of selling computers, and so initially,

7:49 FORTRAN code could only be compiled and run on IBM computers.

7:53 And most programing languages and compilers of the 1950s

7:55 could only run on a single type of computer.

7:58 So, if you upgraded your computer,

7:59 you’d often have to re-write all the code too!

8:02 In response, computer experts from industry,

8:04 academia and government formed a consortium

8:06 in 1959— the Committee on Data Systems Languages,

8:09 advised by our friend Grace Hopper— to guide the development

8:12 of a common programming language that could be used across different machines.

8:16 The result was the high-level, easy to use,

8:18 Common Business-Oriented Language, or COBOL for short.

8:21 To deal with different underlying hardware,

8:23 each computing architecture needed its own COBOL compiler.

8:25 But critically, these compilers could all accept the same COBOL source code,

8:29 no matter what computer it was run on.

8:31 This notion is called write once, run anywhere.

8:33 It’s true of most programming languages today,

8:35 a benefit of moving away from assembly and machine code,

8:38 which is still CPU specific.

8:40 The biggest impact of all this was reducing computing’s barrier to entry.

8:44 Before high level programming languages existed,

8:46 it was a realm exclusive to computer experts and enthusiasts.

8:49 And it was often their full time profession.

8:51 But now, scientists, engineers, doctors, economists, teachers,

8:54 and many others could incorporate computation into their work.

8:58 Thanks to these languages, computing went from a cumbersome and esoteric

9:01 discipline to a general purpose and accessible tool.

9:04 At the same time, abstraction in programming allowed those computer

9:07 experts– now “professional programmers”–

9:09 to create increasingly sophisticated programs,

9:11 which would have taken millions, tens of millions,

9:14 or even more lines of assembly code.

9:16 Now, this history didn’t end in 1959.

9:18 In fact, a golden era in programming language design jump started,

9:21 evolving in lockstep with dramatic advances in computer hardware.

9:25 In the 1960s, we had languages like ALGOL, LISP and BASIC.

9:28 In the 70’s: Pascal, C and Smalltalk were released.

9:31 The 80s gave us C++, Objective-C, and Perl.

9:34 And the 90’s: python, ruby, and Java.

9:36 And the new millennium has seen the rise of Swift, C#,

9:39 and Go- not to be confused with Let it Go and Pokemon Go.

9:42 Anyway, some of these might sound familiar— many are still around today.

9:45 It’s extremely likely that the web browser you’re

9:47 using right now was written in C++ or Objective-C.

9:50 That list I just gave is the tip of the iceberg.

9:53 And languages with fancy, new features are proposed all the time.

9:56 Each new language attempts to leverage new and clever abstractions

9:59 to make some aspect of programming easier or more powerful,

10:01 or take advantage of emerging technologies and platforms,

10:04 so that more people can do more amazing things, more quickly.

10:07 Many consider the holy grail of programming

10:09 to be the use of “plain ol’ English”,

10:10 where you can literally just speak what you want the computer to do,

10:13 it figures it out, and executes it.

10:15 This kind of intelligent system is science fiction… for now.

10:18 And fans of 2001: A Space Odyssey may be okay with that.

10:21 Now that you know all about programming languages,

10:23 we’re going to deep dive for the next couple of episodes,

10:26 and we’ll continue to build your understanding of how programming languages,

10:29 and the software they create, are used to do cool and unbelievable things.

10:33 See you next week.

10:34 Hey guys, this week’s episode was brought to you by CuriosityStream which is

10:38 a streaming service full of documentaries

10:40 and non­fiction titles from some really great filmmakers,

10:43 including exclusive originals.

10:45 I just watched a great series called “Digits” hosted by our friend Derek Muller.

10:49 It’s all about the Internet- from its origins,

10:51 to the proliferation of the Internet of Things,

10:53 to ethical, or white hat, hacking.

10:55 And it even includes some special guest appearances… like

10:58 that John Green guy you keep mentioning in the comments.

11:01 And Curiosity Stream offers unlimited access starting

11:04 at $2.99 a month, and for you guys,

11:07 the first two months are free if you sign up at curiositystream.com/crashcourse

11:12 and use the promo code "crash course" during the sign-up process.

Study with Looplines Download Captions Watch on YouTube