Computer Programming General Flashcards
How is thinking like a computer scientist incorporate aspects of mathematics, engineering, and natural science?
“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
What is the single most important skill for a computer scientist to have?
“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
What are examples of high-level languages?
“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
What are low-level languages?
“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
What are some advantages of high-level languages?
“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
What two kinds of programs process high-level languages into low-level languages?
“Interpreters and compilers.” - p.1, Think Python
How does an interpreter process high-level languages into low-level languages?
“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 does a compiler process high-level languages into low-level languages?
“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
Is Python considered an interpreted or a compiled language?
“Python is considered an interpreted language because Python programs are executed by an interpreter.” - p.2, Think Python
In what ways can you use the interpreter in Python?
“There are two ways to use the interpreter: interactive mode and script mode.” - p.2, Think Python
How does interactive mode work using the interpreter in Python?
“In interactive mode, you type the Python programs and the interpreter prints the result:
> > > 1 + 1
2
The chevron,»_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 does script mode work using the interpreter in Python?
“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 do you execute a script once it is saved/stored in an executable file?
“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
What are some advantages for using either interactive mode or script mode in Python?
“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
What is a program?
“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