Computer Programming General Flashcards

1
Q

How is thinking like a computer scientist incorporate aspects of mathematics, engineering, and natural science?

A

“Like mathematicians, computer scientists use formal languages to denote ideas (specifically computations). Like engineers, they design things, assembling components into systems and evaluating tradeoffs among alternatives. Like scientists, they observe the behavior of complex systems, form hypotheses, and test predictions.” - p.1, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the single most important skill for a computer scientist to have?

A

“Problem solving. Problem solving means the ability to formulate problems, think creatively about solutions, and express a solution clearly and accurately. As it turns out, the process of learning to program is an excellent opportunity to practice problem-solving skills. That’s why this chapter is called, ‘The way of the program.’ On one level, you will be learning to program, a useful skill by itself. On another level, you will use programming as a means to an end. As we go along, that end will become clearer.” - p.1, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are examples of high-level languages?

A

“Python is an example of a high-level language; other high-level languages you might have heard of are C, C++, Perl, and Java.” - p.1, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are low-level languages?

A

“There are also low-level languages, sometimes referred to as ‘machine languages’ or ‘assembly languages.’ Loosely speaking, computers can only execute programs written in low-level languages. So programs written in a high-level language have to be processed before they can run. This extra processing takes some time, which is a small disadvantage of high-level languages.” - p.1, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are some advantages of high-level languages?

A

“The advantages are enormous. First, it is much easier to program in a high-level language. Programs written in a high-level language take less time to write, they are shorter, and easier to read, they are more likely to be correct, and are easier to maintain. Secondly, high-level languages are portable, meaning that they can run on different kinds of computers with few or no modifications. Low-level programs can only run on one kind of computer and have to be rewritten to run on another. Due to these advantages, almost all programs are written in high-level languages. Low-level languages are used only for a few specialized applications.” - p.1, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What two kinds of programs process high-level languages into low-level languages?

A

“Interpreters and compilers.” - p.1, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does an interpreter process high-level languages into low-level languages?

A

“An interpreter reads a high-level program and executes it, meaning that it does what the program says. It processes the program a little at a time, alternately reading lines and performing computations.

Source Code –> Interpreter –> Output” - p.1-2, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does a compiler process high-level languages into low-level languages?

A

“A compiler reads the program and translates it completely before the program starts running. In this context, the high-level program is called the source code, and the translated program is called the object code or the executable. Once a program is compiled, you can execute it repeatedly without further translation.

Source Code –> Compiler –> Object Code –> Executor –> Output” - p.2, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Is Python considered an interpreted or a compiled language?

A

“Python is considered an interpreted language because Python programs are executed by an interpreter.” - p.2, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In what ways can you use the interpreter in Python?

A

“There are two ways to use the interpreter: interactive mode and script mode.” - p.2, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does interactive mode work using the interpreter in Python?

A

“In interactive mode, you type the Python programs and the interpreter prints the result:

> > > 1 + 1
2

The chevron,&raquo_space;>, is the prompt the interpreter uses to indicate that it is ready. If you type 1 + 1, the interpreter replies 2.” - p.2, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does script mode work using the interpreter in Python?

A

“In script mode, you can store code in a file and use the interpreter to execute the contents of the file, which is called a script. By convention, Python scripts have names that end with .py” - p.2, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you execute a script once it is saved/stored in an executable file?

A

“To execute the script, you have to tell the interpreter the name of the file. In a UNIX command window, you would type: python dinsdale.py . In other development environments, the details of executing scripts are different. You can find instructions for your environment at the Python website, python.org” - p.2, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are some advantages for using either interactive mode or script mode in Python?

A

“Working in interactive mode is convenient for testing small pieces of code because you can type and execute them immediately. But for anything more than a few lines, you should save your code as a script so you can modify and execute it in the future.” - p.2, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a program?

A

“A program is a sequence of instructions that specifies how to perform a computation. The computation might be something mathematical, such as solving a system of equations or finding the roots of a polynomial, but it can also be a symbolic computation, such as searching and replacing text in a document or (strangely enough) compiling a program.” - p.2, Think Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are a few basic instructions that appear in just about every language?

A

“The details look different in different languages, but a few basic instructions appear in just about every language:

input: Get data from the keyboard, a file, or some other device.
output: Display data on the screen or send data to a file or other device.
math: perform basic mathematical operations like addition and multiplication

conditional execution: check for certain conditions and execute the appropriate sequence of statements.

repetition: perform some action repeatedly, usually with some variation.

Believe it or not, that’s pretty much all there is to it. Every program you’ve ever used, no matter how complicated, is made up of instructions that look pretty much like these. So you can think of programming as the process of breaking a large, complex task into smaller and smaller subtasks until the subtasks are simple enough to be performed with one of these basic instructions.

That may be a little vague, but we will come back to this topic when we talk about algorithms.” - p.2-3, Think Python

17
Q

What is debugging?

A

“Programming is error-prone. For whimsical reasons, programming errors are called bugs and the process of tracking them down is called debugging.” - p.3, Think Python

18
Q

What kinds of errors or bugs an occur in a program?

A

“Three kinds of errors can occur in a program: syntax errors, runtime errors, and semantic errors. It is useful to distinguish between them in order to track them down more quickly.” - p.3, Think Python

19
Q

What is a syntax error?

A

“Python can only execute a program if the syntax is correct; otherwise, the interpreter displays an error message. Syntax refers to the structure of the program and the rules about that structure.
For example, parentheses have to come in matching pairs, so (1 + 2) is legal in Python, but 8) is a syntax error.” - p.3, Think Python

20
Q

What happens in Python when there is a syntax error?

A

“In English readers can tolerate most syntax errors, which is why we can read the poetry of E. E. Cummings without spewing error messages. Python, however, is not so forgiving. If there is a single syntax error anywhere in your program, Python will display an error message and quit, and you will not be able to run your program. During the first few weeks of your programming career, you will probably spend a lot of tie tracking down syntax errors. As you gain experience, you will make fewer errors and find them faster.” - p.3, Think Python

21
Q

What are runtime errors?

A

“The second type of error is a runtime error, so called because the error does not appear until after the program has started running. These errors are also called exceptions because they usually indicate that something exceptional (and bad) has happened.

Runtime errors are rare in the simple programs you will see in the first few chapters, so it might be a while before you encounter these.” - p.3, Think Python

22
Q

What are semantic errors?

A

“The third type of error is the semantic error. If there is a semantic error in your program, it will run successfully in the sense that the computer will not generate any error messages, but it will not do the right thing. It will do something else. Specifically, it will do what you told it to do.

The problem is that the program you wrote is not the program you wanted to write. The meaning of the program (its semantics) is wrong. Identifying semantic errors can be tricky because if requires you to work backward by looking at the output of the program and trying to figure out what it is doing.” - p.4, Think Python

23
Q

What is a major part of problem solving when it comes to programming, and also one of the most important skills you will acquire as a programmer?

A

Debugging. “One of the most important skills you will acquire is debugging. Although it can be frustrating debugging is one of the most intellectually rich, challenging, and interesting parts of programming. In some ways, debugging is like detective work. You are confronted with clues, and you have to infer the processes and events that led to the results you see.” - p.4, Think Python

24
Q

Why is debugging like an experimental science?

A

“Debugging is also like an experimental science. Once you have an idea about what is going wrong, you modify your program and try again. If your hypothesis was correct, then you can predict the result of the modification, and you take a step closer to a working program. If your hypothesis was wrong, you have to come up with a new one. As Sherlock Holmes pointed out, ‘When you have eliminated the impossible, whatever remains, however improbable, must be the truth.”

25
Q

Why do some people consider programming and debugging to be the same thing?

A

” For some people, programming and debugging are the same thing. That is, programming is the process of gradually debugging a program until it does what you want. The idea is that you should start with a program that does something and make small modifications, debugging them as you go, so that you always have a working program.

For example, Linux is an operating system that contains thousands of lines of code, but it started out as a simple program Linus Torvalds used to explore the Intel 80386 chip. According to Larry Greenfield, ‘One of Linus’s earlier projects was a program that would switch between printing AAAA and BBBB. This later evolved into Linux.’” - p.4, Think Python