00:00:00
what's the first thing you should do
00:00:01
when your code throws an error obviously
00:00:03
you should change nothing and try to run
00:00:05
it again a few times if that doesn't
00:00:06
work you're gonna need a computer
00:00:08
science degree the awesome thing about
00:00:09
software engineering is that you can
00:00:11
learn to code and get a high paying job
00:00:13
while literally having no idea how
00:00:15
anything actually works it all just
00:00:16
feels like magic like a pilot driving a
00:00:18
giant metal tube in the sky while
00:00:20
knowing nothing about aerodynamics
00:00:23
[Music]
00:00:24
welcome to computer science 101 in
00:00:26
today's video you'll learn the science
00:00:28
behind the garbage code you've been
00:00:29
writing by learning 101 different
00:00:31
computer science terms and concepts this
00:00:33
is a computer it's just a piece of tape
00:00:35
that holds ones and zeros along with a
00:00:37
device that can read and write to it
00:00:39
it's called a turing machine and in
00:00:41
theory it can compute anything like the
00:00:43
graphics in this video or the algorithm
00:00:44
that recommended that you watch it at
00:00:46
the core of modern computers we have the
00:00:48
central processing unit if we crack it
00:00:50
open we find a piece of silicon that
00:00:52
contains billions of tiny transistors
00:00:54
which are like microscopic on off
00:00:55
switches the value at one of these
00:00:57
switches is called a bit and is the
00:00:59
smallest piece of information a computer
00:01:00
can use however one bit by itself is not
00:01:03
very useful so they come in a package of
00:01:05
eight called a byte one byte can
00:01:06
represent 256 different values like all
00:01:09
the characters that you type on your
00:01:11
keyboard in fact when you type into your
00:01:12
keyboard the character produced is
00:01:14
actually mapped to a binary value in a
00:01:16
character encoding like ascii or utf-8
00:01:19
binary is just a system for counting
00:01:21
like the base 10 system you normally use
00:01:23
when counting on your fingers but it
00:01:25
only has two characters one and zero
00:01:27
humans have a hard time reading binary
00:01:29
so most often it's represented in a
00:01:31
hexadecimal base 16 format where ten
00:01:33
numbers and six letters can represent a
00:01:35
four bit group called a nibble as a
00:01:37
developer when you write code in a
00:01:39
programming language it will eventually
00:01:40
be converted into machine code which is
00:01:42
a binary format that can be decoded and
00:01:44
executed by the cpu what it doesn't do
00:01:47
though is store data for your
00:01:48
applications for that computers have
00:01:50
random access memory or ram it's like a
00:01:53
neighborhood and inside of every house
00:01:55
lives a byte every location has a memory
00:01:57
address which the cpu can read and write
00:01:59
to you can think of the cpu and ram as
00:02:01
the brain of the computer but in order
00:02:03
for a computer to be useful it needs to
00:02:05
handle input and output an input device
00:02:07
might be the keyboard and mouse while an
00:02:09
output device might be your monitor
00:02:10
luckily most developers don't need to
00:02:12
worry about how this hardware fits
00:02:13
together because we have operating
00:02:15
system kernels like linux mac and
00:02:17
windows that control all hardware
00:02:18
resources via device drivers now to
00:02:21
start hacking on the operating system
00:02:22
your first entry point is the shell
00:02:24
which is a program that exposes the
00:02:26
operating system to the end user it's
00:02:28
called a shell because it wraps the
00:02:30
kernel it takes a line of text as input
00:02:32
and produces an output this is called a
00:02:34
command line interface not only can it
00:02:36
connect to your own computer but with
00:02:37
the secure shell protocol it can also
00:02:39
connect to remote computers over a
00:02:41
network now that you have access to the
00:02:43
mainframe it's time to pick a
00:02:44
programming language which is a tool
00:02:46
that uses the abstraction principle to
00:02:48
make computers practical to work with
00:02:50
for humans by simplifying different
00:02:52
systems layer by layer some languages
00:02:54
like python are interpreted that means
00:02:56
there's a program called an interpreter
00:02:57
that will execute each line of code one
00:02:59
by one other languages like c plus are
00:03:02
compiled they use a compiler to convert
00:03:04
the entire program into machine code in
00:03:06
advance before the cpu attempts to
00:03:08
execute it this results in an executable
00:03:10
file that can be run by the operating
00:03:12
system without any extra dependencies
00:03:14
now every programming language has a
00:03:16
variety of built-in data types to
00:03:18
represent the data we're working with in
00:03:20
our code instead of bytes we work with
00:03:22
more human-friendly things like
00:03:23
characters and numbers now the most
00:03:25
fundamental way to use data in your
00:03:26
application is to declare a variable
00:03:29
this attaches a name to a data point
00:03:31
allowing you to reuse it somewhere else
00:03:32
in your code python is a dynamically
00:03:35
typed language which means we don't need
00:03:36
to tell the program exactly which data
00:03:38
type is assigned to a variable it just
00:03:40
figures it out automatically however
00:03:42
other languages like c are statically
00:03:44
typed and that means you need to specify
00:03:46
the data type of a variable in your code
00:03:48
when you define a variable its value is
00:03:50
stored somewhere in memory on the
00:03:52
hardware and you may need to allocate
00:03:53
and free up memory throughout the
00:03:55
program a pointer is a variable whose
00:03:57
value is the memory address of another
00:03:59
variable which can be used for low-level
00:04:02
memory control many languages don't want
00:04:04
to deal with low-level memory management
00:04:06
and instead implement a garbage
00:04:07
collector which automatically allocates
00:04:09
and de-allocates memory when an object
00:04:11
is no longer referenced in the program
00:04:16
[Music]
00:04:19
now the data types available are
00:04:21
different in every programming language
00:04:22
but typically you'll find int to
00:04:24
represent whole numbers which may or may
00:04:26
not be signed or unsigned to represent
00:04:28
negative numbers as well when numbers
00:04:30
require a decimal point they typically
00:04:32
use the floating point type it's called
00:04:34
a float because there's only enough
00:04:35
memory to represent a certain range of
00:04:37
numbers at a certain precision and is
00:04:39
basically a form of scientific notation
00:04:41
to make computers faster if you need
00:04:43
more range or precision many languages
00:04:44
also have a double that doubles the
00:04:46
amount of memory used for the number now
00:04:48
when it comes to characters you'll
00:04:49
typically find the char data type to
00:04:51
represent a single character or more
00:04:53
commonly a string to represent multiple
00:04:55
characters together ultimately these
00:04:57
characters get stored in a memory
00:04:58
address somewhere but they need to be
00:05:00
stored in a certain order when the order
00:05:02
starts with the most significant byte
00:05:03
and the smallest memory address it's
00:05:05
called big endian or vice versa if the
00:05:07
least significant byte is stored in the
00:05:09
smallest address it's called little
00:05:10
endian when it comes to practical
00:05:12
software engineering one of the most
00:05:13
fundamental things we do is organize
00:05:15
data into data structures the most
00:05:18
useful data structure is probably the
00:05:19
array or list just like a shopping list
00:05:22
it organizes multiple data points in
00:05:24
order however it also maintains an index
00:05:27
of integers that starts at zero and goes
00:05:29
up for every new item in the list that
00:05:31
can be useful but you don't actually
00:05:33
need an index to create a list of items
00:05:35
another option is a linked list where
00:05:36
each item has a pointer to the next item
00:05:39
in front of it another option is a stack
00:05:41
that follows the last in first out
00:05:43
principle it's like stacking a set of
00:05:45
plates then when you want to access the
00:05:46
data you pop the last one off the top
00:05:49
the inverse option is a queue which is
00:05:51
first in first out just like when you
00:05:53
get into the red line the first person
00:05:54
there is the first one to be fed now
00:05:56
another extremely useful data structure
00:05:58
is the hash which might also be called a
00:06:00
map or dictionary it's like an array but
00:06:02
instead of an index of integers you
00:06:04
define the keys that point to each
00:06:06
individual item giving you a collection
00:06:08
of key value pairs in many cases though
00:06:10
it's not efficient to organize data in a
00:06:12
linear way to address that problem we
00:06:14
have trees which organize nodes together
00:06:16
in a hierarchy that can often be
00:06:18
traversed more quickly this can
00:06:20
sometimes be too rigid of a data
00:06:21
structure though so instead a graph can
00:06:23
be created to connect multiple nodes
00:06:25
together in a virtually unlimited number
00:06:27
of ways a graph has a node for the data
00:06:29
and an edge for the relationship between
00:06:31
the data points data structures are
00:06:33
essential but they don't do anything by
00:06:34
themselves to do something useful you'll
00:06:36
need to code up an algorithm which is
00:06:38
just code that solves a problem i took
00:06:40
the initiative in
00:06:42
creating the internet in our code we
00:06:44
have several mechanisms for implementing
00:06:45
algorithms the most fundamental of which
00:06:47
is a function which is a block of code
00:06:49
that takes an input then does something
00:06:52
and returns an output like a variable a
00:06:54
function has a name and it can be called
00:06:56
from other parts of your code with
00:06:57
different input parameters called
00:06:59
arguments one thing you might do in the
00:07:00
function body is compare one value to
00:07:02
another every language has a variety of
00:07:05
built-in operators like equality greater
00:07:07
than and less than that you can use to
00:07:09
compare two values if a is greater than
00:07:11
b then it forms a value of true but if b
00:07:14
is greater than a then the value is
00:07:15
false true false is what's known as a
00:07:18
boolean data type and whenever your code
00:07:19
produces a value like this it's known as
00:07:21
an expression but not all code will
00:07:23
produce a value sometimes your code will
00:07:25
simply do something which is known as a
00:07:27
statement a good example is the if
00:07:29
statement which handles conditional
00:07:31
logic for example if the condition is
00:07:33
true it will execute this code otherwise
00:07:35
it will short circuit and run the code
00:07:37
inside of the else block another very
00:07:39
common type of statement is a loop a
00:07:41
while loop will run this block of code
00:07:43
over and over again until the condition
00:07:45
in the parentheses becomes false that
00:07:47
can be useful but more often than not
00:07:49
you'll want to loop over an iterable
00:07:50
data type like an array most languages
00:07:53
have a for loop that can run some code
00:07:54
for every object in the array or
00:07:56
iterable data structure now in some
00:07:58
cases a function may not have an output
00:08:00
which is generally called a void
00:08:02
function an interesting thing about
00:08:04
functions is that they can call
00:08:05
themselves when a function calls itself
00:08:07
it's called recursion because when done
00:08:09
like this by default it will recurse
00:08:10
forever creating an infinite loop that
00:08:13
happens because when you call a function
00:08:14
the programming language will put it
00:08:16
into memory on what's known as the call
00:08:18
stack which is a short-term chunk of
00:08:19
memory for executing your code when a
00:08:21
function keeps calling itself the
00:08:23
language will keep pushing frames onto
00:08:24
the call stack until you get a stack
00:08:26
overflow error to avoid this your
00:08:28
algorithm needs a base condition so it
00:08:30
knows when to terminate the loop now
00:08:32
when you write an algorithm you'll need
00:08:33
to determine if it's any good and the
00:08:34
system for doing that is called big-o
00:08:36
notation it's a standard format for
00:08:38
approximating the performance of an
00:08:40
algorithm at scale it may reference time
00:08:42
complexity which is how fast your
00:08:44
algorithm will run and space complexity
00:08:46
which deals with how much memory is
00:08:47
required to run it developers have many
00:08:49
different algorithm types at their
00:08:51
disposal the most crude option is brute
00:08:53
force where you might loop over every
00:08:54
possible combination to hack somebody's
00:08:56
credit card pin a more sophisticated
00:08:58
approach might be divide and conquer
00:09:00
like binary search where you cut the
00:09:02
problem in half multiple times until you
00:09:03
find what you're looking for another
00:09:05
option is dynamic programming algorithms
00:09:07
where a problem is broken down into
00:09:09
multiple smaller sub-problems and the
00:09:11
result of each computation is stored for
00:09:13
later use using a technique called
00:09:16
memoization that means if a function has
00:09:17
already been called it will use the
00:09:19
existing value instead of recomputing it
00:09:21
again from scratch then we have greedy
00:09:23
algorithms that will make the choice
00:09:24
that is most beneficial in the short
00:09:26
term without considering the problem as
00:09:28
a whole one example of this is
00:09:29
dijkstra's shortest path algorithm on
00:09:31
the flip side we have backtracking
00:09:33
algorithms which take a more incremental
00:09:35
approach by looking at all the possible
00:09:37
options like a rat and a maze exploring
00:09:39
all the different potential paths now
00:09:41
when it comes to implementing your code
00:09:42
there are always multiple ways to get
00:09:44
the job done one programming paradigm is
00:09:46
declarative where your code describes
00:09:48
what the program does and the outcome
00:09:50
but doesn't care about things like
00:09:51
control flow this style of programming
00:09:53
is often associated with functional
00:09:55
languages like haskell the other
00:09:56
paradigm is imperative programming where
00:09:58
your code uses statements like if and
00:10:00
while providing explicit instructions
00:10:02
about how to produce an outcome it's
00:10:04
associated with procedural languages
00:10:06
like c today most general purpose
00:10:08
languages like python javascript kotlin
00:10:10
swift and so on are multi-paradigm which
00:10:13
means they support all these options at
00:10:14
the same time in addition to
00:10:16
object-oriented programming the idea
00:10:18
behind oop is that you use classes to
00:10:20
write a blueprint for the data or
00:10:22
objects in your code a class can
00:10:24
encapsulate variables which are commonly
00:10:26
called properties as well as functions
00:10:28
which are usually called methods in this
00:10:29
context it's a common way to organize
00:10:31
and reuse code because classes can share
00:10:34
behaviors between each other through
00:10:35
inheritance where a subclass can extend
00:10:37
and override the behaviors of the parent
00:10:39
class and it opens the door to all kinds
00:10:41
of other ideas called design patterns
00:10:43
now a class by itself doesn't actually
00:10:45
do anything instead it's used to
00:10:47
instantiate objects which are actual
00:10:49
chunks of data that live in your
00:10:51
computer's memory often you'll want to
00:10:52
reference the same object over and over
00:10:54
again in your code when data is
00:10:56
long-lived it can't go in the call stack
00:10:58
instead most languages have a separate
00:11:00
area of memory called the heap which
00:11:01
unlike the call stack can grow and
00:11:03
shrink based on how your application is
00:11:05
used it also allows you to pass objects
00:11:07
by reference which means you can use the
00:11:09
same object in multiple variables
00:11:11
without increasing the memory footprint
00:11:12
because it always points to the same
00:11:14
chunk of memory in the heap now what's
00:11:15
interesting is that if we go back to the
00:11:17
cpu that we talked about in the
00:11:18
beginning you'll notice that it contains
00:11:20
multiple threads a thread takes the
00:11:22
physical cpu core and breaks it into
00:11:24
virtual cores that allow it to run code
00:11:26
simultaneously there are some
00:11:28
programming languages that support
00:11:29
parallelism where you can write code
00:11:31
that literally executes on two different
00:11:33
threads at the same time however many
00:11:35
languages out there are only single
00:11:36
threaded but that doesn't mean they
00:11:38
can't do two things at the same time
00:11:40
instead they implement concurrency
00:11:41
models like an event loop or co-routines
00:11:44
that can pause or delay the normal
00:11:45
execution of code to handle multiple
00:11:47
jobs on a single thread at the same time
00:11:49
now in modern computing we're rarely
00:11:51
working with the bare metal cpu and ram
00:11:53
instead we work in the cloud with a
00:11:55
virtual machine which is just a piece of
00:11:57
software that simulates hardware that
00:11:59
allows us to take really big computers
00:12:01
and split them up into a bunch of
00:12:02
smaller virtual computers these machines
00:12:04
are the backbone of the internet and are
00:12:06
connected via the internet protocol each
00:12:08
machine has a unique ip address to
00:12:10
identify it on the network that ip
00:12:12
address is usually alias to a url that
00:12:14
is registered in a global database
00:12:16
called the domain name service now to
00:12:18
establish a connection the two computers
00:12:20
will perform a tcp handshake which will
00:12:22
allow them to exchange messages called
00:12:24
packets on top of that there's usually a
00:12:26
security layer like ssl to encrypt and
00:12:29
decrypt the messages over the network
00:12:31
now the two computers can securely share
00:12:33
data with the hypertext transfer
00:12:35
protocol the client may request a web
00:12:37
page then the server will respond with
00:12:38
some html modern servers provide a
00:12:41
standardized way for a client to request
00:12:43
data which is called an application
00:12:45
programming interface or api the most
00:12:47
common architecture is rest where urls
00:12:49
are mapped to different data entities
00:12:51
available on the server and that brings
00:12:53
us to our final topic mother effin
00:12:55
printers you're gonna need to learn how
00:12:56
these things work inside and out because
00:12:58
every time you go to grandma's house
00:12:59
she's going to ask you to fix it which
00:13:01
shouldn't be a problem for a computer
00:13:03
scientist like you thanks for watching
00:13:05
and i will see you in the next one