Hello, and welcome back.
Let's talk about the fundamentals of a program.
Since this is a beginning programming class, specifically
we're going to be talking about C, before you can understand even
a programming language, you need to understand what a program is.
So I want to describe some basic, basic concepts to you before we
get started in the details of C.
Computers are very dumb machines.
You guys are, I'm sure, more than more than not familiar with what a
computer can do and what it does.
Specifically though, under the hood and what's going on in terms of when
you click your browser, when you click your different applications that you
use, what's happening under the hood is there is some kind of program
that's running and that program is telling the computer what to do.
Computers are really dumb.
They only do what they're told to.
So the basic operations of a computer will form what is known
as the computer's instruction set.
An instruction set if you can think about that, it's the it's
how it's going to do something. So
we need to tell this computer how it's going to do.
We do it in the form of a program at an even lower level.
Each computer has what's called an instruction set.
An instruction set is basically the instructions on the CPU,
the processor of the computer.
So to solve a problem using a computer by telling you what to do, you
provide this solution by sending these instructions to the instruction set.
So that's what's happening when you write a computer program is
you're sending specific instructions to solve a specific problem via
commands to the CPU, the processor.
And the approach or method that is used to solve the problem
is known as an algorithm.
So for you guys that understand math, an algorithm is how
you're solving a problem.
So for example if you were to create a entire program and all
it does is test whether or not a user enters an odd or even number.
What would be described as the algorithm itself is the test,
whether or not the number is even or odd, that's the algorithm.
The statements that solve the problem in its entirety becomes the program.
And we'll discuss this concept and algorithm.
Algorithm are even is even more kind of relation - related
to module programming.
So we'll talk about that when we talk more about the details to see.
But again, I want to let you understand what you're doing
when you're writing code.
What's going on at the very, very lowest layer.
You're going to write these algorithms that are
contained inside of a program.
So to write a program, you're going to need to properly
write the instructions to implement the algorithm.
These instructions can be expressed in any kind of statements of a
particular programming language.
So we're going to focus on c for this class, but I'm sure
you've heard of other programming languages like java, c++, objective
c used in iOS applications but actually more now, Swift is used.
But there's all these programming languages that you can learn that
essentially are going to allow you to send instructions to the CPU in the
form of algorithms and statements.
Also, I want to talk about some basic terminology, the CPU,
the central processing unit.
This is the brain of the computer.
This is where most of the work is being done.
This is where instructions are executed.
Memory, you often hear this term memory.
And students often get memory very confused with the hard drive.
Memory is not the same as the hard drive.
Memory is often referred to as ram, which is random access memory.
All the data that's stored in memory,
it's a separate hardware component.
It's not an actual disk drive.
All of the data in the program is stored in memory, the
separate hardware component.
So it stores the data the program while it's running.
And we're going to talk about variables and what they mean.
But a program needs to have data in order to perform calculations
in order to do algorithms.
That data is going to be stored in ram, memory.
The reason we store it in memory as opposed to storing it on
a hard drive is that memory is much faster, it allows the
program to run much quicker.
But memory is also usually not persistent across reboots
another kind of clarification.
But you should understand just this term RAM.
It means memory.
It's the variables and the data in the program itself where it's stored.
The separate hardware component then the hard drive.
The hardware drive is something you buy when the computer --
that's permanent storage.
This is usually really, really large. It contains gigabytes, terabytes of data.
This stores files that may be resources of a program.
And when you turn the computer off and turn it back on,
those files are still there.
When you turn the computer off and on for a program, the
program actually stops executing and there's nothing in ram.
So understand the difference between ram and hard drive.
It's an important concept.
Again, think of ram as related to program, as hard drive is
related to permanent storage
and we usually put resources on there.
We'll have operating system files, all sorts of different program resources.
An operating system is developed to basically make your life a lot easier
when you want to use the computer.
Because at a very low level, a computer is just doing what it's
told and it's just instructions using an instruction set.
It would be very difficult to use if you were to have to
understand all these instructions.
So there's a program called an operating system that makes it
easier for a user to use a computer.
It controls all the operation of the computer, handles all the
input and output via hardware so it understands how to interact
with a keyboard, a mouse, a monitor.
It also manages the computer's resources, handles execution
of different applications.
An operating system is a completely separate class.
There's a lot that goes into an operating system, but
understand the basics of it.
It's just allowing you to use your computer in an easier manner.
Some examples of very common operating systems are
things like Windows, right.
Everybody uses Windows.
Windows 10,
Windows XP, whatever the case may be.
Linux, UNIX which we'll talk more about when we
talk about the history of C.
Android is an operating system for mobile devices, iOS.
These are specific programs that are very large that may contain many
different programs that interact, make your life a lot easier with
interacting with the computer.
The fetch execution cycle.
This is the lifecycle CPU.
I only mention this because, again, we're just
describing basic terminology.
This is how when you send instructions to a computer, the CPU, what's
actually happening is you're fetching the instructions from
memory because that's the program.
And then you're going to execute that on the CPU, and
it's this kind of loop you're doing it over and over and over.
You're repeating it.
And if you've ever heard of the term gigahertz, a gigahertz CPU can
do about a billion times a second, a billion instructions a second.
So you can kind of imagine what's going on when you're
running a computer with this fetch execution life cycle.
And here's a little illustration that I took from an image on the
internet that shows you this effects execution cycle a little bit clearer.
What's going down when you're interacting with the
CPU and these instructions.
What's happening is you're grabbing from ram.
And ram, remember, contains programs data.
You're grabbing data there for instructions.
And you're constantly decoding the data which is stored in registers
and ram and then executing it on different parts of the CPU, either
the control unit or the ALU.
That's a loop though.
It just repeats over and over and over.
And again for CPUs nowadays billion times a second.
So when we talk about c programs and writing c programs, at the very low
level, underneath everything, we're just interacting with the CPU via our
higher level programming language.
So a higher level programming language.
Higher level programming languages make it easier to write programs.
Now if we were to have to again, understand all these
instructions on the CPU, it'd be very difficult to write.
And to understand all the instructions, that usually means
it's an assembly language.
If you've ever heard the term assembly language, it just means you're
writing a program at a very low level where it's such a low level that
you understand the instruction set.
And you can imagine that if you were to write all of your programs
with all these instructions, it would be very inefficient and
very difficult to write a program.
So higher level programming language are the opposite
of an assembly language.
It's a much higher level.
An example is c.
C is a higher level programming language.
It describes the actions that the program is going to perform
in a much more abstract way.
You don't have to memorize the instructions on CPU.
You just understand the language itself, and you solve problems
through these algorithms.
It looks much more like the English language.
It's much more easier to understand.
If you were to look at an assembly language, what you're
going to see is move commands with registers, with numbers,
basically just numeric statements.
And by using a higher level language like c, you don't have
to worry about any of this.
You don't have to worry about the instruction set.
You don't have to worry about assembly language statements.
So it's much more efficient and it's much easier to
accomplish and solve problems.
And so we're going to study c as our higher level programming languages,
but other examples would be java, objective c, things I mentioned.
These are high level programming languages that make your life a
lot easier and much more efficient.
In addition to these higher level programming languages, if you have
this language that's more abstract, you have to be able to take that
language and then run it on a CPU.
You have to convert it essentially to instructions that the CPU understands.
And so this is where a compiler comes into play.
Often when you write code in programming, you're going to
use a compiler that translates this high-level language,
source code into detailed machine language instructions,
basically, assembly language.
So you're going to write a program that's going to do high
level, more abstract thinking.
And then the compiler is going to generate all the millions
of instructions that go to the CPU on the instruction set.
So we're going to use a compiler in this class to do exactly this.
We're going to write source code in a much higher level abstract form.
And then we're going to run a program called the compiler to
convert that code into something that the CPU understands.
Now here's the other thing about compilers is they're also going to check whether
or not your program has valid syntax.
So when you write code, you have to you have to follow
the rules of the language.
The rules of the language are essentially the syntax, whether
or not you have a semicolon at the end of a statement, whether
or not you use certain keywords.
If you do these things incorrectly, you're not going
to be able to run your program.
So the compiler is going to find all these errors, and it's going
to tell you and report back to you and say, hey, you didn't write
your code correctly, you have to fix them before we're going to
actually convert this stuff to the instruction set on the CPU.
So we're going to get familiar with compilers in a general
sense, how to use them, how to understand, what they're telling us.
High level languages are much easier to learn, much easier to
program in than machine languages.
That's the gist of this slide right now is that by utilizing a
language like c, it's going to be much more efficient and easier.
When we write a program, we're going to actually perform
multiple, multiple steps.
And I found this illustration that really describes the
steps in a really nice way.
So I took this from a book.
It's a basic set of steps when you write any kind of program.
From the first step of defining the program objectives, understanding
the requirements, to maintaining and modifying the program.
So let's just walk through these steps real quick and you're going to
be finding that you're doing - going to be doing this in this class.
When you start to write a program, you're going to
follow all these steps.
The first step is going to be to define the program objectives.
This is where you're going to understand the requirements.
You cannot start writing code unless you understand what you need to do.
So you need to get a clear idea of what you want to
accomplish in this step.
After you understand the requirements, you're then going
to start to design the code.
When you design the code, this is how the code is going
to meet the requirements.
What's the user interface going to look like if it's required.
How are you going to organize your program, are you going to create
different functions and try to create different algorithms and so forth.
Then you're going to start implementing code.
This is where you actually write the code and put it into an editor in an
integrated development environment.
You translate the design to the syntax of the programming language,
in this case c, understand the rules of the c language.
So you can use any text editor.
We're going to actually use something called cold blocks.
You'll typically want to use something more than a text editor, something
called an IDE which we'll talk about.
Once you're done writing the code, you have to compile it because
it needs to convert it the source code to the low level language.
We talked about this already, so this is a pretty basic step.
And then you run the program. Running the program is
executing it, is using it.
And then that's going to be the fifth step.
After you run the program, you're not done because even though you
wrote the code and it maybe meet the requirements of the language, it might
not do what it's intended to do so
you have to test it and you have to find and fix your errors.
So just because a program is running, doesn't mean it works.
I get a lot of students to say, hey, compiled, I'm done. No.
You have to make sure that when you run it, it meets the
requirements and it does what you think it's going to do.
So you have to constantly test.
And you'll be performing steps one through six over and over and over
again. You're going to be finding that you're going to be
writing code, testing, writing code testing, writing code, testing.
And typically, when you do this, you want to do it in very small chunks.
You want to write two lines of code, test. Another two lines
of code, test and so forth.
So you need to test and debug.
Debugging is another concept.
We'll have many lectures on debugging, but this is when you find
and fix your programming errors.
There are certain techniques you can do, certain tools you can use
to help you find these errors.
And you'll learn a ton by testing and debugging because you always
can learn a great amount of information by making mistakes.
And that's going to be normal.
You're going to compile and the program's not going to do what
you do what you said it did and you're going to learn from that.
And that's what we're going to do in this class.
I'm not just going to show you the correct way to do things.
I'm going to show you the wrong way to do things, and then you're
going to see why this is wrong.
The last step is maintenance.
This is when the programs are released and then used by many
people, but still may have bugs.
So for example when windows 10 is released, you'll notice that it
still has bugs or still crashes.
And so you're constantly getting updates.
And when you get those updates, that's called maintaining the program.
So just because you're done writing the code and releasing
it to the public, it doesn't mean you're done maintaining it.
Maintenance is the often the most extensive phase, the most
extensive step because when you release a program it could be
out there for five or ten years.
You're going to have to fix these bugs so that your customers are happy.
You may also want to add new features to keep it up to date in the market.
So maintenance is really important as well.
Maintenance happens after you release the product to the customer.
So for all these steps you may jump around, execute steps in
different order, depending on what programming methodology, that's
a whole other lecture as well.
You're not always going to necessarily do these steps in a waterfall approach
where you start at the beginning and end at the -- end at the last step.
You may be designing and then going back and doing your
testing and then going back and redesigning and so forth.
So you're going to be jumping around all depending on
what's the most practical.
From my experience, many new programmers in many of the
classes in udemy are ignoring steps one and two and going
directly to writing the code.
They're showing you how to write the code, but they're not showing
you why you're writing the code.
So this is a big mistake.
When you start to write code, you need to understand the concepts, you
need to understand the requirements.
And you can get away with this in really tiny programs, but with
larger programs, you're going to need to fully focus on design.
So the larger and the more complex the program is, the
more planning it requires.
You should develop the habit of planning before coding.
Do not just dive in, and you're going to notice from the lectures in this
class that I do a lot of planning.
I'm going to tell you in the challenges when you start to write
some code that what you need to do and how you should design it.
Because this is going to make it easier for you to actually implement
the code, which is step three.
So keep that in mind you can often plant things by
writing things down on paper.
There's all sorts of nice documentation designing languages
out there and things you can use.
But you always want to basically plan efficiently.
And then as you're coding, I mentioned this earlier, but this
is another very, very important concept, you always want to work
in small steps, divide and conquer you want to constantly test.
You do not want to write 100 lines of code and then say,
oh, I'm done, let me go test.
Because now, if it doesn't work there could be an error
in any 100 lines of code.
It's going to be much harder to solve that problem.
But if you write code in little chunks, five lines of code, test
it, then write another five lines of code, test it, It's going to be much
easier to find and fix your errors.
So let's focus on divide and conquer when we write our code in this class.
I hope this helped.
Again, this is just some basics.
I wanted to provide some basic terminology.
A lot of you may already know a lot of this information.
But when you're learning a programming language, you have
to understand these basics.
Thank you.