Top-Rated Free Essay
Preview

Programming Language

Good Essays
1249 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Programming Language
Announcements and Demos (0:00-10:00)
• This is CS50.
• Check out what is possible in the programming language called Scratch that we will begin the course with! Scratch will enable you to wrap your mind around the fundamental constructs of programming while making a cool game or animation.
• Be sure to check out the second annual CS50 Puzzle Day this Saturday! Thanks to Facebook for sponsoring!
• CS50 is all about getting you through CS50. We want you to make it to the final days and gain that practical skill set to take with you to engineering sciences, applied math, natural sciences, or really any discipline.
• As you make your way through the semester, try to keep the following snippet in mind: what ultimately matters in this course is not so much where you end up relative to your classmates but where you, in Week 11, end up relative to yourself in Week 0
• Know that you are not at a disadvantage at all for being one of those “less comfortable” or “somewhere in between.” We have specially designed several different tracks through this course and we’ll help you fit into one of them.
• Avail yourself of CS50 Discuss, our online discussion forum.
• Office Hours begin on Monday! They’ll be held Mondays through Thursdays, 8 p.m. to 11 p.m. in Annenberg Hall.
• Sometime this weekend, please visit cs50.net/section to give us your sectioning preferences.
• The first Walkthrough is today at 3 p.m. in Harvard Hall 104! Zamyla Chan will be your fearless leader for Walkthroughs this semester.
Intro to Programming (10:00-63:00)
• Let’s begin our foray into programming with pseudocode. Pseudocode is not a programming language, per se, but rather a way of expressing ourselves somewhat precisely, and somewhat algorithmically without having to worry about real syntax.
Putting on Socks
• Let’s see if we can write an algorithm for putting on socks in the morning. David will follow our instructions exactly and Joseph will write them down:
1. bend down
2. pick up your sock
• Here we have a bit of ambiguity. Which sock? Before long, we’ll need to express ourselves more precisely so the computer knows exactly what we’re trying to accomplish.
• Now, we want to find a matching sock. This is instinctive for a human (who can scan them all quickly with his eyes), but not so for a computer. In order to find a matching sock, we have to iterate or loop through all of the socks and compare them to the one we have. Something like this:
1. bend down
2. pick up your sock
3. find matching pair
4. for each sock
5. pick it up...
6. if it's the same shape/size
7. take it
8. identify right and left
• Notice that Joseph has already started following one programming convention: indentation. When you construct a loop, the chunk of code that gets executed with each iteration of the loop is usually indented. Likewise with the code that meets a certain condition (e.g. take it in the example above).
1. bend down
2. pick up your sock
3. find matching pair
4. for each sock
5. pick it up...
6. if it's the same shape/size
7. take it
8. identify right and left
9. lift up right leg
10. find open end of sock
11. touch toes
12. put on sock
• Now that we’ve taken care of one foot, we need to make a design decision to take care of the second foot. Should we write another loop? Perhaps. Since we only have two cases to handle, we could simply copy and paste the steps above. However, anytime you find yourself copying and pasting code, you should probably consider using a loop instead.
• Our program is buggy! What happens if there’s no matching sock? What if there is only one sock? What if David already has socks on? We haven’t handled these so-called corner cases, which could cause problems going forward. Generally, when you make assumptions while writing programs (e.g. of course there will be enough disk space!), you risk introducing bugs.
C
• Let’s take a look at a short program in C:
• #include


• int main(void)
• {
• printf("hello, world!");
• }
• The syntax is fairly cryptic, but you can probably guess what this program does: it writes “hello, world!” to the screen.
• Whether you have a Mac or a PC, you can use software applications to write programs like this. On a Mac, you can use a program called Terminal to execute programs like this. The Terminal interface is reminiscent of computers from the past which didn’t have graphical user interfaces (GUIs).
• After we open up a text editor, we insert the lines of code above and save the file as hello.c. This file now represents our source code. As we’ve already learned, computers can’t understand anything but binary, so we need to translate this source code into binary. This same code in binary is called object code. To do this translation, we run the following from the command line:
• clang hello.c
• Although nothing seems to have happened, we can actually now see that a file named a.out has been created in our home directory. a.out contains the 0’s and 1’s of our converted program. Now that it has been converted, we can execute it like so: ./a.out
• It worked! Unfortunately, it’s not very pretty. It seems to have printed hello, world! followed by something like air:~ jharvard. That last bit, however, is actually printed at the beginning of every line of our Terminal window. It designates the computer’s name, the current directory, and the username. So it seems that our program worked, but it would have been prettier if we could have hit Enter after hello, world!. We can do this by inserting what’s called a linebreak. We represent a linebreak in code with a \n like so:
• #include


• int main(void)
• {
• printf("hello, world!\n");
• }
• Now if we rerun our program, we get…the same thing. Oops, we forgot to re-translate our source code to object code. The process of translating source code to object code is called compiling. We need to recompile our program. If we do so and then rerun it, we get our pretty output as we’d hoped for.
• What does a.out actually contain? If we try to examine it using a text editor, we get junk. This is because the text editor is misinterpreting the 0’s and 1’s as ASCII characters. Somewhere amidst the junk, you can actually see the words “hello, world!”
• To look at the actual 0’s and 1’s that a.out contains, we can execute the following command:
• xxd -b a.out
• Back in the day (when David was like 34 or so), a programmer would have had to physically punch holes in cards to represent his or her program. Luckily, we now have CPUs that can interpret the 0’s and 1’s directly.
Scratch
• To start working with Scratch, you’ll need to download the program from MIT’s website.
• Once you install Scratch and open it, take note of the following layout: o On far left, notice the “palette” of puzzle pieces, which represent programming statements. Programs will be composed by putting puzzle pieces together in a particular order. o At bottom right are sprites, or characters that will carry out your instructions. o At top right is the stage, where the program will be carried out. o To the left of the stage is the scripts area, where puzzle pieces must be dragged and strung together.

You May Also Find These Documents Helpful

  • Satisfactory Essays

    1.) What is pseudocode? A.) Pseudocode is when you pre write a program in your own type of language to lay it out…

    • 453 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Pt1420 week 2

    • 320 Words
    • 3 Pages

    Pseudocode is an informal language that has no syntax rules, and is not meant to be compiled or executed.…

    • 320 Words
    • 3 Pages
    Satisfactory Essays
  • Powerful Essays

    IT/210 Appendix D

    • 453 Words
    • 4 Pages

    Up to this point, you have identified the processes the program must perform, but you have not given any consideration to exactly how the processes work together to solve the problem. At this point, you must generate a description of the processing using pseudocode, a natural language description of the processing the application must perform.…

    • 453 Words
    • 4 Pages
    Powerful Essays
  • Satisfactory Essays

    IT104 Assignment Unit 5

    • 307 Words
    • 2 Pages

    Pseudocode is an informal language that has no syntax rules, and is not meant to be compiled or executed.…

    • 307 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Pseudocode is “fake” code (as per the pseudo meaning fake and code meaning code). This is where a programmer writes out the code without worry of syntax or logic errors to get a visual feel of how the program should unfold.…

    • 848 Words
    • 4 Pages
    Satisfactory Essays
  • Powerful Essays

    Syllabus Busi 681 Fall 2010

    • 2403 Words
    • 10 Pages

    Office Hours: 5:00-6:00 p.m. before class (in the classroom) and by appointment. I’ll also be available after class for any follow-up questions after the regular lecture period.…

    • 2403 Words
    • 10 Pages
    Powerful Essays
  • Powerful Essays

    Office Hours: Monday 8:30-10:50, 1:45-2:30, Tuesday and Thursday 8:30-9:20, 11-12:20, 1:45-2:30, Wednesday 1:45-2:30, Friday 10:50-12.…

    • 1344 Words
    • 6 Pages
    Powerful Essays
  • Satisfactory Essays

    MAPP plays a role in carrying out public health’s core functions in that it essentially combines the 3 major core functions into one long-term plan of action. The three core functions are assessment, policy development, and assurance. To start, assessment investigates health disputes and tries to find a way to figure out these community health problems. MAPP plays a part in assessment in that it picks the out the greatest health disparities and finds resources or solutions to fix the complication. MAPP identifies solutions to the health disputes that the assessment phase finds. The main idea of policy development is to educate and make people in the community aware of the health concerns that are occurring. MAPP implements policy development…

    • 213 Words
    • 1 Page
    Satisfactory Essays
  • Powerful Essays

    pearson bio 121

    • 3706 Words
    • 15 Pages

    Office Hours: Tuesday and Thursday 8:30 to 11:00 AM; Monday and Wednesday 11 AM to 12 PM; or by appointment.…

    • 3706 Words
    • 15 Pages
    Powerful Essays
  • Good Essays

    Philosophy 101 Study Guide

    • 3868 Words
    • 111 Pages

    When: Thursday, the 26th Day of September, 2013, 3:00pm – 4:15pm Where: The same location our class normally meets…

    • 3868 Words
    • 111 Pages
    Good Essays
  • Good Essays

    Analytical Summaries

    • 4637 Words
    • 19 Pages

    Please read all instructions before beginning the assignment so you do not miss any grading components. The completed tutorial should be posted no later than NOON on Sunday November 20th.…

    • 4637 Words
    • 19 Pages
    Good Essays
  • Good Essays

    Kipbo

    • 440 Words
    • 2 Pages

    By way of example, coding has been defined as the language of the future, and has the ability to shape technology we use throughout our day-to-day lives. From the software on your computer, to the apps installed on your smartphone, these platforms are all made and created with code. Generally speaking, people who know the ins and out of coding have some of the most in-demand jobs in the world-and kids are never too young to start learning the language since studies show that at least 50% of careers require technical skills.…

    • 440 Words
    • 2 Pages
    Good Essays
  • Good Essays

    A Four Day Week

    • 318 Words
    • 2 Pages

    Renewal courses will be held Monday through Friday, March 15 through March 19, and March 22 through March 26, from 7 a.m. to 8 p.m. Renewal courses also will be held Saturday, March 20, from 7 a.m. to 2 p.m. All courses will be held in Wilkins Hall, Room 135.…

    • 318 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Home work

    • 529 Words
    • 3 Pages

    1. Answer all of the questions below. They help you think through your status as a student, analyze your academic goals for this course, and make a plan for accomplishing them.…

    • 529 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    We will all meet at the time scheduled (Friday, December 5 from 8:00 - 10:30 a.m.}for the examination to present your poster.…

    • 409 Words
    • 2 Pages
    Satisfactory Essays