Hello, and welcome back.
In this lecture, I want to discuss some of the specific features related
to the c programming language.
So we know all the advantages of c.
I talked about that kind of ad nauseam.
We know that c produces compact and efficient programs. That is a language
feature though, that's important.
It's one of the most important programming languages and will
continue to be so. We know all this.
So I just again, want to reiterate it.
But the main features of the c language are that they're
efficient, portable, powerful and flexible and programmer oriented.
And we're going to cover these in more detail what this means.
But these are important characteristics of c.
We need to understand them again, in order to understand how to
write the code in this language.
So what does efficiency and portability mean?
Well, c is an efficient language.
It takes advantage of all the capabilities of current computers.
It's very compact programs and written in c.
They're very fast and compact.
I talked earlier about how the mapping of c statements to instructions in
some language is very efficient.
This is one of the reasons it's so fast.
One of the complaints about java in the past used to be,
hey, java is really slow.
Well, you don't have this problem with c.
When you write a program in C, it runs fast, it's very compact.
So that's a language feature.
That's an efficiency.
Programmers can fine tune their programs to make them
even more efficient because it is such low level.
They can use more efficient use of memory.
You can't do things like this in java.
Java has its own garbage collector and you can't manipulate the
memory to be more efficient.
So c is an efficient language and it's a portable language.
So I touched on this briefly in a previous lecture, but this
is important because what this means is if you write a c program
on one operating system, you can run it on another operating
system without modifying it.
One of the issues when writing code in today's world is sometimes
it's not going to work unless you write in multiple languages
or modify it extensively.
So for example, if you write an android application for
an android phone, it's not going to work on an iOS phone.
You don't have those types of issues with c.
You write c, and it will work on all sorts of different hardware, all
sorts of different operating systems.
In fact, c is the leader in portability, this capability and
the compilers are easily available.
You can get a compiler on Windows, Linux, no problem.
Linux/Unix systems typically come with a c compiler, so you don't even
have to download it when you're on Linux/Unix same with the Macintosh.
So you can start writing c programs immediately, no external downloads.
They're also available obviously for Windows.
But typically for Windows, you will have to download a compiler.
And we're going to be doing that when we download our required software.
So there's a good chance that you get a c compiler for any
device that you're using.
You can get a c compiler also for an android device or an iOS
device, really low level micro or mini computers as well like
processors and automobiles.
It's also very flexible which is important, and it's also very powerful.
So the Unix Linux kernels are written in c.
What is a kernel?
Well, we know Unix and Linux is an operating system.
We know an operating system will help you more efficiently -
a user more efficiently - use a computer, and it controls a lot
of the aspects of interacting with hardware and so forth.
The kernel is the brain of the operating system.
So just like a CPU is a brain of a computer, a kernel is where really
all the brain and knowledge of the operating system go, so it typically
contains interfaces the hardware and the kernel it manages memory, it
does all sorts of different things.
And that is all written in C.
So that can tell you the powerful aspect of the language.
If the kernel of an operating system is written in that language,
that language is powerful.
So many compilers and interpreters for other languages are built
on c or have been written in c.
So if that doesn't tell you the powerful nature of the
language, I don't know what will.
But Fortran, Perl, Python, any compilers that are written in those
type of languages are written in c.
So c programs have been used for solving physics and engineering
problems and even for animating special effects for movies, widely
used for many different things.
Flexibility is also important, especially when you're a developer
and you're writing this code.
You want to be able to do things in different ways.
You want to be able to solve a problem in many ways.
More flexibility typically the better.
However, there is a trade-off between flexibility and performance.
So sometimes it's - it's catchy when you're designing a language,
but c was designed to be flexible and is very flexible.
So you can do just about everything you want in a c program.
You can write out all different application types.
And you can also manage memory and do different things that many
other languages restrict you on.
There is a trade-off because sometimes the flexibility causes
more bugs or causes developers not to fully understand certain concepts
because they may be more complex.
But ultimately flexibility is a good thing, especially if you're
a developer that understands the language very well.
It's also the basis for more advanced languages, such as
c++, mentioned that earlier.
It's used for developing mobile phone apps in the form of objective-c.
Objective-c is a proprietary language by Apple.
Basically, it's c with objects just like c++, but they decided
to write their own language.
But it is used in iOS less and less so because Swift is being
more popular, but it's also easy to learn because of its compactness.
It's an ideal first language to learn if you want to be a programmer.
And I think I've given the rationale for that pretty good.
You're going to acquire sufficient knowledge for
practical application development very quickly and very easily.
So that's why it's the good first one to learn.
And that's what you're going to notice in this class is, wow now that
I learned c wow, it's much easier to learn java, it's much easier to
learn php, it's a lot easier to learn these other languages because it
has everything that those languages have and it's very easy to learn.
It's programmer oriented.
That's a language feature.
It fulfills the needs of the programmers.
I told you how Dennis Ritchie when he created the language
wanted to make it more developer focused, and he did that.
He accomplished that goal.
It gives you direct access to hardware, enables you to direct access
to memory and manage your own memory.
So the flexibility comes into play when it's when
it is programmer oriented.
In java, you can't do a lot of these things like manage your own memory.
C also has many other capabilities that allow flexibility.
And I think that flexibility allows to be more programmer oriented,
because programmers like that.
They like that flexibility, they don't want to be told what to do.
It contains a large selection of operators, which allow you
to express yourself succinctly.
Now this means we don't know what an operator is yet.
But an operator can be things like adding and subtracting
mathematical operators or assignment operators assigning data to memory.
And the more operators you have allow you to express
yourself more in your code.
And so a language feature with being more programmer oriented is
this list of operators which we'll talk about in a lot more detail.
It's less strict than most languages limiting what you can do kind
of talked about this already.
I mentioned the trade-off with this, flexibility versus strictness.
It's an advantage in that you can do things in many different ways.
However, it could be a danger because it's more prone to
error programmers, especially with something like pointers.
So the fact that you can manage your own memory in c is very flexible, but
it's also very complicated sometimes.
And as a result, many programmers introduce bugs into programs.
Now java doesn't allow you to manage your memory.
But it's also less flexible but it also reduces your
bugs in your program.
So there's a trade-off.
You want to basically have flexibility by also allowing
things to be less complex.
C gives you more freedom, but also puts more responsibility
on the developer, and that's why it's program oriented.
C implementations have a large library of useful c functions.
So you don't have to write everything in c if you want to do something.
Programming languages would typically contain other program functionality
that comes with the language.
So for example if you want to read input from the user, you don't want
to write low level c code to do that.
There will be codes in c that already does it for you and
you just reuse that code.
And that's usually encapsulated in something called the library.
And so c has all sorts of library functions to read data from the
keyboard, to write data to files, to create all sorts of nice things with
different processes and threat.
I mean all sorts of nice things.
So the fact that that a lot of implementation comes with the
language and you don't have to actually implement it yourself
you just have to learn how to use the libraries is very advantageous
and very programmer oriented.
Some other features of c are provides low level features that are
generally provided by the lower level languages, we talked about this.
But again, best example this is memory management, direct access to memory.
Programs can be manipulated using bits.
Well, if that's not a low level I don't know what is. It is
the ability to manage memory representation at a bit level.
Bits and bytes are how we actually store data on computers,
provides a wide variety of bit manipulation operators.
Again, something in the language that we'll talk about in more detail.
Pointers play a big role in c.
This is a concept that you may have heard of before, you may
not have heard of, but it's related to memory management.
We're going to have many lectures on pointers. But
It is a very, very important feature of c that you should be familiar
with at the very high level.
C manage memory, c pointers. Often when you think of the
c programming language, first thing you think of is pointers.
And all this is direct access to memory.
Disadvantages of c, we talked about that flexibility trade-off,
flexibility versus freedom.
It also requires added responsibility.
Some view this as a disadvantage, some view that pointers are abused.
And as a result, many people write bad c programs.
Well, yeah, if you if you give somebody a tool that you do something, they
do it incorrectly, who's at fault?
It's kind of, again, do you want to restrict that tool because it's
abused or do you want to allow that tool to allow flexibility.
So you can often be more flexible but it's at the risk of making more errors
and a lot of times these errors are very difficult to find and trace
especially if they're memory stuff.
So that can be a problem.
Other things because of its wealth of operators and its conciseness,
it makes the language difficult to read and follow sometimes.
For the most part, c is very easily readable.
But if you use a lot of these different operators, that
can make it more complex.
So there's an opportunity to write up obscure code, but that's any
language can be badly written.
So you can use the English language when you speak and
you can have bad grammar.
It's no different when you write - use a programming language.
But some say with c it's disadvantage because of all these operators.
If you use it incorrectly, it can be harder to follow the code.
So just to summarize.
This is a nice illustration again I found on the web that
I'd like to provide you with.
The core features of the c language: fast and efficient, portable, a
lot of nice libraries where you can reuse code and you don't
have to do things on your own,
modularity, talked about earlier, but this is the idea of
organizing code around functions,
easy to extend and then all these powerful operators
that allow you to do things.
So a lot of nice features.
And most the features that we just talked about are in
many modern languages because they're built off of c.