The First Programming Languages: Crash Course Computer Science #11 - YouTube

Channel: CrashCourse

[3]
This episode is brought to you by CuriosityStream.
[5]
Hi, I’m Carrie Anne and welcome to CrashCourse Computer Science!
[8]
So far, for most of this series, we’ve focused on hardware -- the physical components of
[12]
computing -- things like: electricity and circuits, registers and RAM, ALUs and CPUs.
[17]
But programming at the hardware level is cumbersome and inflexible, so programmers wanted a more
[21]
versatile way to program computers - what you might call a “softer” medium.
[24]
That’s right, we’re going to talk about Software!
[27]
INTRO
[36]
In episode 8, we walked through a simple program for the CPU we designed.
[40]
The very first instruction to be executed, the one at memory address 0, was 0010 1110.
[46]
As we discussed, the first four bits of an instruction is the operation code, or OPCODE
[50]
for short.
[51]
On our hypothetical CPU, 0010 indicated a LOAD_A instruction -- which moves a value
[57]
from memory into Register A.
[59]
The second set of four bits defines the memory location, in this case, 1110, which is 14
[64]
in decimal.
[65]
So what these eight numbers really mean is “LOAD Address 14 into Register A”.
[69]
We’re just using two different languages.
[71]
You can think of it like English and Morse Code.
[74]
“Hello” and “.... . .-.. .-.. ---” mean the same thing -- hello! -- they’re just
[79]
encoded differently.
[80]
English and Morse Code also have different levels of complexity.
[83]
English has 26 different letters in its alphabet and way more possible sounds.
[88]
Morse only has dots and dashes.
[89]
But, they can convey the same information, and computer languages are similar.
[93]
As we've seen, computer hardware can only handle raw, binary instructions.
[97]
This is the “language” computer processors natively speak.
[100]
In fact, it’s the only language they’re able to speak.
[103]
It’s called Machine Language or Machine Code.
[105]
In the early days of computing, people had to write entire programs in machine code.
[109]
More specifically, they’d first write a high-level version of a program on paper,
[113]
in English, for example...
[115]
“retrieve the next sale from memory, then add this to the running total for the day,
[119]
week and year, then calculate any tax to be added”
[122]
...and so on.
[123]
An informal, high-level description of a program like this is called Pseudo-Code.
[126]
Then, when the program was all figured out on paper, they’d painstakingly expand and
[130]
translate it into binary machine code by hand, using things like opcode tables.
[135]
After the translation was complete, the program could be fed into the computer and run.
[139]
As you might imagine, people quickly got fed up with this process.
[141]
So, by the late 1940s and into the 50s, programmers had developed slightly higher-level languages
[146]
that were more human-readable.
[148]
Opcodes were given simple names, called mnemonics, which were followed by operands, to form instructions.
[153]
So instead of having to write instructions as a bunch of 1’s and 0’s, programmers
[157]
could write something like “LOAD_A 14”.
[160]
We used this mnemonic in Episode 8 because it’s so much easier to understand!
[163]
Of course, a CPU has no idea what “LOAD_A 14” is.
[166]
It doesn’t understand text-based language, only binary.
[169]
And so programmers came up with a clever trick.
[171]
They created reusable helper programs, in binary, that read in text-based instructions,
[176]
and assemble them into the corresponding binary instructions automatically.
[180]
This program is called -- you guessed it -- an Assembler.
[182]
It reads in a program written in an Assembly Language and converts it to native machine
[187]
code.
[187]
“LOAD_A 14” is one example of an assembly instruction.
[190]
Over time, Assemblers gained new features that made programming even easier.
[194]
One nifty feature is automatically figuring out JUMP addresses.
[198]
This was an example program I used in episode 8:Notice how our JUMP NEGATIVE instruction
[202]
jumps to address 5, and our regular JUMP goes to address 2.
[205]
The problem is, if we add more code to the beginning of this program, all of the addresses
[209]
would change.
[210]
That’s a huge pain if you ever want to update your program!
[212]
And so an assembler does away with raw jump addresses, and lets you insert little labels
[217]
that can be jumped to.
[218]
When this program is passed into the assembler, it does the work of figuring out all of the
[221]
jump addresses.
[222]
Now the programmer can focus more on programming and less on the underlying mechanics under
[226]
the hood enabling more sophisticated things to be built by hiding unnecessary complexity.
[231]
As we’ve done many times in this series, we’re once again moving up another level
[235]
of abstraction.
[236]
A NEW LEVEL OF ABSTRACTION!
[242]
However, even with nifty assembler features like auto-linking JUMPs to labels, Assembly
[247]
Languages are still a thin veneer over machine code.
[249]
In general, each assembly language instruction converts directly to a corresponding machine
[254]
instruction – a one-to-one mapping – so it’s inherently tied to the underlying hardware.
[258]
And the assembler still forces programmers to think about which registers and memory
[262]
locations they will use.
[264]
If you suddenly needed an extra value, you might have to change a lot of code to fit
[267]
it in.
[268]
Let’s go to the Thought Bubble.
[269]
This problem did not escape Dr. Grace Hopper.
[272]
As a US naval officer, she was one of the first programmers on the Harvard Mark 1 computer,
[277]
which we talked about in Episode 2.
[278]
This was a colossal, electro-mechanical beast completed in 1944 as part of the allied war effort.
[284]
Programs were stored and fed into the computer on punched paper tape.
[287]
By the way, as you can see, they “patched” some bugs in this program by literally putting
[291]
patches of paper over the holes on the punch tape.
[294]
The Mark 1’s instruction set was so primitive, there weren’t even JUMP instructions.
[298]
To create code that repeated the same operation multiple times, you’d tape the two ends
[302]
of the punched tape together, creating a physical loop.
[305]
In other words, programming the Mark 1 was kind of a nightmare!
[308]
After the war, Hopper continued to work at the forefront of computing.
[312]
To unleash the potential of computers, she designed a high-level programming language
[315]
called “Arithmetic Language Version 0”, or A-0 for short.
[319]
Assembly languages have direct, one-to-one mapping to machine instructions.
[323]
But, a single line of a high-level programming language might result in dozens of instructions
[327]
being executed by the CPU.
[329]
To perform this complex translation, Hopper built the first compiler in 1952.
[334]
This is a specialized program that transforms “source” code written in a programming
[338]
language into a low-level language, like assembly or the binary “machine code” that the
[342]
CPU can directly process.
[344]
Thanks, Thought Bubble.
[345]
So, despite the promise of easier programming, many people were skeptical of Hopper’s idea.
[350]
She once said, “I had a running compiler and nobody would touch it.
[354]

 they carefully told me, computers could only do arithmetic; they could not do programs.”
[358]
But the idea was a good one, and soon many efforts were underway to craft new programming
[363]
languages -- today there are hundreds!
[364]
Sadly, there are no surviving examples of A-0 code, so we’ll use Python, a modern
[369]
programming language, as an example.
[370]
Let’s say we want to add two numbers and save that value.
[374]
Remember, in assembly code, we had to fetch values from memory, deal with registers, and
[378]
other low-level details.
[379]
But this same program can be written in python like so:
[382]
Notice how there are no registers or memory locations to deal with -- the compiler takes
[385]
care of that stuff, abstracting away a lot of low-level and unnecessary complexity.
[389]
The programmer just creates abstractions for needed memory locations, known as variables,
[394]
and gives them names.
[395]
So now we can just take our two numbers, store them in variables we give names to -- in this
[400]
case, I picked a and b but those variables could be anything - and then add those together,
[405]
saving the result in c, another variable I created.
[407]
It might be that the compiler assigns Register A under the hood to store the value in a,
[412]
but I don’t need to know about it!
[414]
Out of sight, out of mind!
[415]
It was an important historical milestone, but A-0 and its later variants weren’t widely used.
[421]
FORTRAN, derived from "Formula Translation", was released by IBM a few years later, in
[426]
1957, and came to dominate early computer programming.
[428]
John Backus, the FORTRAN project director, said: "Much of my work has come from being
[432]
lazy.
[433]
I didn't like writing programs, and so ... I started work on a programming system to make
[437]
it easier to write programs."
[439]
You know, typical lazy person.
[441]
They’re always creating their own programming systems.
[443]
Anyway, on average, programs written in FORTRAN were 20 times shorter than equivalent handwritten
[447]
assembly code.
[448]
Then the FORTRAN Compiler would translate and expand that into native machine code.
[452]
The community was skeptical that the performance would be as good as hand written code, but
[456]
the fact that programmers could write more code more quickly, made it an easy choice
[460]
economically: trading a small increase in computation time for a significant decrease
[465]
in programmer time.
[466]
Of course, IBM was in the business of selling computers, and so initially, FORTRAN code
[470]
could only be compiled and run on IBM computers.
[473]
And most programing languages and compilers of the 1950s could only run on a single type
[477]
of computer.
[478]
So, if you upgraded your computer, you’d often have to re-write all the code too!
[482]
In response, computer experts from industry, academia and government formed a consortium
[486]
in 1959 -- the Committee on Data Systems Languages, advised by our friend Grace Hopper -- to guide
[492]
the development of a common programming language that could be used across different machines.
[496]
The result was the high-level, easy to use, Common Business-Oriented Language, or COBOL
[500]
for short.
[501]
To deal with different underlying hardware, each computing architecture needed its own
[504]
COBOL compiler.
[505]
But critically, these compilers could all accept the same COBOL source code, no matter
[510]
what computer it was run on.
[511]
This notion is called write once, run anywhere.
[513]
It’s true of most programming languages today, a benefit of moving away from assembly
[517]
and machine code, which is still CPU specific.
[520]
The biggest impact of all this was reducing computing’s barrier to entry.
[524]
Before high level programming languages existed, it was a realm exclusive to computer experts
[528]
and enthusiasts.
[529]
And it was often their full time profession.
[531]
But now, scientists, engineers, doctors, economists, teachers, and many others could incorporate
[536]
computation into their work .
[538]
Thanks to these languages, computing went from a cumbersome and esoteric discipline
[542]
to a general purpose and accessible tool.
[544]
At the same time, abstraction in programming allowed those computer experts – now “professional
[548]
programmers” – to create increasingly sophisticated programs, which would have taken
[552]
millions, tens of millions, or even more lines of assembly code.
[556]
Now, this history didn’t end in 1959.
[558]
In fact, a golden era in programming language design jump started, evolving in lockstep
[562]
with dramatic advances in computer hardware.
[565]
In the 1960s, we had languages like ALGOL, LISP and BASIC.
[568]
In the 70’s: Pascal, C and Smalltalk were released.
[571]
The 80s gave us C++, Objective-C, and Perl.
[574]
And the 90’s: python, ruby, and Java.
[576]
And the new millennium has seen the rise of Swift, C#, and Go - not to be confused with
[580]
Let it Go and Pokemon Go.
[582]
Anyway, some of these might sound familiar -- many are still around today.
[585]
It’s extremely likely that the web browser you’re using right now was written in C++
[589]
or Objective-C.
[590]
That list I just gave is the tip of the iceberg.
[593]
And languages with fancy, new features are proposed all the time.
[596]
Each new language attempts to leverage new and clever abstractions to make some aspect
[600]
of programming easier or more powerful, or take advantage of emerging technologies and
[603]
platforms, so that more people can do more amazing things, more quickly.
[607]
Many consider the holy grail of programming to be the use of “plain ol’ English”,
[610]
where you can literally just speak what you want the computer to do, it figures it out,
[614]
and executes it.
[615]
This kind of intelligent system is science fiction
 for now.
[618]
And fans of 2001: A Space Odyssey may be okay with that.
[621]
Now that you know all about programming languages, we’re going to deep dive for the next couple
[625]
of episodes, and we’ll continue to build your understanding of how programming languages,
[629]
and the software they create, are used to do cool and unbelievable things.
[633]
See you next week.
[634]
Hey guys, this week’s episode was brought to you by CuriosityStream which is a streaming
[639]
service full of documentaries and non­fiction titles from some really great filmmakers,
[643]
including exclusive originals.
[645]
I just watched a great series called “Digits” hosted by our friend Derek Muller.
[649]
It’s all about the Internet - from its origins, to the proliferation of the Internet of Things,
[653]
to ethical, or white hat, hacking.
[655]
And it even includes some special guest appearances
 like that John Green guy you keep mentioning
[660]
in the comments.
[661]
And Curiosity Stream offers unlimited access starting at $2.99 a month, and for you guys,
[667]
the first two months are free if you sign up at curiositystream.com/crashcourse
[672]
and use the promo code "crash course" during the sign-up process.