[MUSIC PLAYING]
DOUG LLOYD: All right, so welcome to the portion of CS50
where we're going to begin to do transition our coding away from scratch
and we're going to start programming in c.
In order to do that, we need to have a terminal-based environment where
we can write commands at the command line, write our code,
compile it, and execute it.
The platform that we provide in CS50 is called CS50 IDE.
And it's entirely a cloud-based infrastructure
that uses an implementation of Ubuntu, which is one flavor of the Linux
operating system.
The advantage here is it is cloud-based, which
means that you can start your work on one computer,
save, head home, switch to a different computer, use a friend's computer,
and all your work is saved remotely in the cloud.
To get started, what I want to do is walk you
through how to set up your CS50 IDE the very first time
and walk you through some of the features that it has.
So all you need to do to get started with your CS50
IDE is head to a web browser.
And in the URL, just type in cs50.io.
And just give that a second.
You'll be prompted to log in using CS50 ID.
The options that you'll probably use are either Edx, Harvard, or Yale.
So if you have an Edx account, you'd use the Edx logins.
If you have a Harvard credentials, you'd use Harvard.
If you have Yale credentials, you'd use Yale.
So I'm going to set up with Harvard credentials, hit Submit.
And you would enter your username and password here.
And the very first time, if you haven't done this before, what it's going to do
is create for you a brand new environment, pre-configured, ready
to go, using CS50 IDE's framework within Cloud9.
Now, I already have an implementation of CS50 IDE,
but I'm going to show you how to create another one using a different method.
So alternatively, if you already have a CS50 IDE workspace and you want to,
for example, create another one, which is what I'm going to do here,
or for example, the cs50.io log in somehow didn't work,
you can also create new workspaces from your Cloud9 dashboard.
I'm going to show you how to do that here.
So what I did was I logged on to my IDE.
And in the File menu, I just chose dashboard to bring me to the screen
that you're seeing here.
Then what I wanted to do is just create a new workspace,
which I can do just by hovering over this button here.
And then it's going to ask me to provide some parameters.
So my workspace name, lets call it demo.
A short description of it, demo for CS50 IDE.
Now in general, particularly if this is your first work space,
you're actually going to want to choose private here.
The way that this is set up, though, is that you're
restricted to one private workspace.
And I already have one in my example here.
So I'm going to choose public because I don't really have another option.
But if this is your first workspace that you're using for CS50 IDE,
you do want to create a private workspace if you can.
And then at the bottom there, it gives you some options
for different templates you can use.
So this is not just restricted, necessarily, to CS50.
But there is a CS50 template right here at the end,
with happy cat, Harvard CS50.
And I can just hit Create Workspace.
Now, depending on how old your system is and the speed
of your internet connection, this could take anywhere from a couple of seconds
to maybe one or two minutes.
So after about 45 seconds or so on my machine,
I was brought to this screen, which is basically the CS50 IDE, what
it looks like by default. The first thing you're going to want to do,
again, one more time sensitive step here,
is as soon as you visit your IDE for the first time,
or generally when you're visiting it as you go,
you're generally going to want to check to see,
make sure that you have the most up to date version of CS50 IDE.
We occasionally will push updates to change some formatting things
or to include some distribution, or sample code, or staff solutions.
And those are pushed via updates.
So you're going to want to, first, go to the terminal at the bottom
here and type in the command update 50.
And then hit Enter.
And again, this will take about, possibly, about a minute or so,
depending on the speed of your internet connection.
And what it's going to do is go through and download all of the packages
and make sure that your system is fully up to date.
So again, after about a minute or so, I'm
notified that the update has completed and I'm
prompted to close and reopen all terminal windows.
So I'll just do that really quick.
I'll just close to this terminal.
Confirming.
And I will reopen a new terminal here.
And now we are good to go.
So our CS50 IDE has three main areas.
At the bottom, you've already seen me working here in blue.
This sort of light bluish color is my terminal.
These windows are also resizable, so I can make
this bigger or smaller if I would like.
I'm going to keep it right about here for now.
On the left over here is my file tree.
As I add files and folders to my workspace, this will become larger
and I'll be able to navigate this using just a GUI interface,
being able to double click on files, double click on folders, as opposed
to just having to do everything at the terminal window.
Although as you become more acquainted with the Linux commands,
you may want to just use the terminal window anyway
because you may find it faster.
And then at the top here is my main workspace, sort of area.
This is where when I'm opening files, where I'll see my source code
and can edit it.
And this is where the bulk of your work will take place
when you're writing code.
I'm going to show you how easy it is to create a file in CS50 IDE.
There's a little icon here with a plus.
All I have to do is click on that.
I'm asked if I want a new file or a new terminal.
As you can see, I actually could put terminals at the top if I wanted to,
generally not a good idea.
I already have one at the bottom.
So I'm just going to create a new file.
Doesn't have a name right now.
You can see it created something for me called Untitled 1,
but that's all right.
And let's just quickly write a little Hello World program.
So first I need to pound include standard I/O, which
is where the print f function lives.
We're going to need that to be able to print that out later.
Int main void.
And I'll tab in here and just print f, hello world.
A little backslash character, close curly brace.
Now nothing like syntax highlighted for me.
Maybe you're familiar with this if you've used other editors before.
And the reason for that is that I haven't given this file a file
extension or a name yet, so the IDE doesn't know what type of file it is.
If I try and hit Save, so Control S on a Windows machine,
Command S on an Apple machine, then I'm prompted
what file do I want to say this as.
We'll save it as hello.c, it as a C program after all.
Hit save.
Now notice that actually now that it knows it's a C file,
it's going to syntax highlight it just like a c file.
So my pound include, my string there is in green, my keywords are in blue,
and we're ready to go.
So I've saved this file as hello.c.
Now you may recall that in order to execute our programs,
we don't just run the source code, we have
to compile them from the source code into a binary file.
And we do that using make.
So we can go down to the bottom here.
And I can type make hello.
Hit Enter.
So then some cryptic clang string ran for me.
And then I can just type ./hello and I'm told hello world at the bottom there.
So that was how easy it was to get our first program set up.
What else can we do here?
There's a lot of menu options at the top.
Let's take a look at some of those really quick,
so you're pretty standard CS50 IDE, which has a menu there.
Files for opening and saving files and so on.
One that you might definitely use is in this View tab.
There's a less comfortable option, which can abstract or hide away
some of the menu options.
You notice some stuff disappeared there.
My screen got a little bit bigger.
I'm going to keep it in more comfortable mode for now,
but this just hides away some of the menu options
that you might not use quite as frequently.
Another option that I personally really like, when I'm coding,
I actually like to be in night mode, which
looks a little something like this.
So it inverts all of my colors.
I like to program on a dark background typing light colored text.
But you might prefer the opposite.
I'm going to keep it as day view for purposes of this video.
But know that that is an option.
And there are other options as well you can do with themes.
There are many, many different types of options
here that you could use instead.
So let me just quickly put this back into day mode.
And then one that is going to be useful, and I'm going to use it from this point
forward in this video, is presentation mode.
And presentation mode you would use when you're giving a presentation, which
is what I'm doing here.
And you'll see what it does is it actually
makes the text a little bit bigger.
It gets rid of some of the details in the corner there at the top right.
I'll take this off again for a second to show you some of those things
briefly near the end of the video.
But it's a useful tool when you want to show your code a little more--
in a larger font size, to have your terminal window
have a larger font size, so that people can read it a little more easily.
And hopefully now you can read it a little more easily because I
put the IDE into presentation mode.
There are a couple of other ways to open files,
though, besides just clicking on the plus icon at the top.
So really quickly I'm going to clear my terminal, which
I do by typing control L. And it just kind of makes everything go away.
And I'm going to try and open a file using the Cloud9 file opening
command, which is known as C9 open.
So I'm going to try and C9 open hello2.c, for example.
Now you notice what it did there is it created a new tab for me at the top.
And it already now has a name.
So unlike before, where I had an untitled tab, now I have--
now I have the--
tab has a name in it.
And we're going to write a really similar program to the one we
did before, with one little twist.
We're still going to include standard I/O. Now
we're going to include CS50.h as well.
CS50.h is a header file that contains some user input functions that
are quite handy for this example.
Int main void.
Now notice, unlike before, now that this file knows that I'm working in C,
you may have caught this.
I'll go back and do it again.
When I was writing the original hello, when I typed the open curly brace,
it didn't do anything for me because it didn't know I was writing a c file.
When I do it here and I hit Enter, notice it actually gives me
a corresponding close brace already.
This will also be done for for loops, while loops, if blocks,
and so on, where it will automatically, if you open a parenthesis
or open a curly brace, it will correspondingly close it for you
so you don't have to go through the process of typing it out.
It's not a huge deal but a lot of modern editors do this for you
because it makes your life a little more convenient.
So this time what we're going to do is we're
going to have a variable where we're going to capture the user's name
and we're going to print their name out.
So I'm first going to prompt them by saying, enter your name.
Then I'm going to have a variable of type string called
name that is going to be used to capture user input using get string.
And then instead of printing out hello world,
what I want to print out is hello %s, where %s is eventually going to be
plugged in with someone's name.
So %s exclamation point, and we're going to plug in whatever we just got there.
So let's go ahead and try and compile this into a--
wait a minute, what's this?
So this is kind of a useful feature, as well.
If you forget to-- remember that you're not
going to be able to compile a program if you haven't saved the file.
And what that was a little warning to me that if I left my code editor window
and I switched, but I haven't saved any of this file yet.
And I have that little red dot in the tab corner as well to remind you.
So that's just a little pop up reminder that's
useful that's part of a CS50 IDE feature that just reminds you,
oh right, before I go, I need to hit Save S, Control S, and save my file.
So I'll do that here.
Now I can make hello2, because this file is called hello2.c
so I want to make hello2.
Clear my terminal really quick again and run hello2.
So that's my second program now that I've written in CS50 IDE.
All right, so what I'm going to do now is
I'm going to turn presentation mode off really briefly, again,
so I can show you some of the features that go
around the perimeter of your IDE area.
But you're pretty much familiar now with the basics here.
We have our file tree, which now has our two files,
two .c files and our two source files--
or excuse me, our two binary files.
We have our terminal area at the bottom and we have our code editing main area,
sort of, at top right.
So I'm going to go ahead and turn presentation back off again
and show you some of these things around the edge.
So this CS50 IDE menu contains some things
that will be mostly useful for you towards the end of the class,
in particular, PHP, my admin, and web server,
which will come in handy for the later portions of the class when
we're doing some web-based programming.
You'll be able to figure out your PHP SQL password, username, and stuff here.
And to be able to check any websites that you have created and are
running by going to web server here.
File has the basics if you've ever used like a Microsoft Word type thing where
you can create files, open them, close them, save, and so on, pretty much all
of those things are there.
If you have any keyboard preferences, you can alter them in the Edit menu.
View, again, has a lot of aesthetics changing things,
for example, the presentation mode, the night mode,
where you can set the way things look.
You want to do that here.
Go, Tools, Window, and Support you probably
will not use quite as frequently.
At the top here is the version number of CS50 IDE.
Don't worry if your version number is different than mine.
At the time we're recording this in May of 2017, we're at version 98.
But if the aesthetics of things change a little bit here and there,
totally nothing to worry about.
It just lets you know what your version number is.
Here is the memory CPU and disk area.
It lets you know if you have too much data saved in your IDE.
Right now, I have plenty of room.
I'm only using 153 megabytes of 5,000 or so.
So I'm in no danger.
But if you write a lot of code and you eventually fill this up,
this is still a cloud-based hard drive, but it is a hard drive nonetheless
that you're using, so you have a limited amount of space.
You have here the Share icon.
So the share icon can be really useful if you're
stuck and need to get some help, perhaps from a teacher, or a colleague,
or a friend.
You can actually share your workspace and give others read and read
and write access to your workspace.
If you click on the Share icon, you're popped up with awesome information
here.
Here is the information for this demonstration workspace.
And if I know somebody's username--
and you can tell, for example, that mine is Lloyd1 because that
appears repeatedly in the URLs here.
If you know somebody's Cloud9 CS50 IDE username,
you can type that here and invite them.
And they'll get a link to be able to access your workspace for read access
or read and write access if you want to be able to collaborate remotely.
It's a very useful feature.
Once you are collaborating with someone remotely,
you can usually collaborate tab here on the right.
And what this will do is this will actually
allow you to have a group chat.
So I'm not collaborating with anybody right now,
but I could write hello, for example, or have any message of any kind
to any of my collaborators.
And if they were also currently viewing my workspace, they would see the chat.
They'd be able to participate.
And so for example, if I was getting some debugging help from a friend,
we could have a chat here on the window on the right
and be able to help me figure out what's wrong with my code just to the left
there.
If you write more complex programs, the outline tab might be more useful.
So really quickly, I'm just going to create a dummy function that
does nothing at all.
But when I do, notice that now I have gotten
this little extra item in my outline.
And if I click on the different portions,
it will jump me to that section of the code.
So as my files get really, really big, and maybe I
want to scroll quickly through them, I can use the outline tab
to jump to different functions in my programs.
That's also pretty useful.
And then finally, here on the right, is the debugger.
And we're going to cover that in a separate video on debugging shortly.
But know that all these features and more,
if you dig into some of the other things around the perimeter
or dig into some of those menus at the top, are available to you
in the CS50 IDE, trying to make your experience getting
started writing code in a text-based programming language a little better.
I'm Doug Lloyd, this is CS50.