đ
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.
You can go back to the homepage right here: Homepage





