computer_basics:programming_fundamentals
Table of Contents
Programming Fundamentals
Mithat Konar
with material from Capron's “Essentials of Computing”, 2/e
What is programming?
- programming: the discipline of creating computer programs.
- computer program:
- a set of step-by-step instructions
- that directs the computer to do the tasks you want it to do
- and produce the results you want.
- Programmer → computer program → software.
What programmers do
- “Write programs”
- Prepare the instructions of a computer program.
- Test and correct programs.
- Document the way a program works.
- Interact with other programmers, systems analysts, clients.
Programming languages
- programming language:
- a set of rules used to write computer programs.
- a way of telling the computer what operations to perform.
- Computers are binary machines.
- Use only ON/OFF switches to control internal states.
- Only understand instructions that are expressed in ON/OFF (or 1/0) terms.
- Programming languages have been invented to make it easier for humans to write programs.
Levels of language
- Programming languages exist on a spectrum of low to high level.
- low level: close to the 1/0 language the computer directly uses.
- high level: closer to natural language or mathematics.
- Five levels:
- machine language
- assembly languages
- high level languages
- very high level languages
- natural language programming
Machine language
10110110100100101101011101001010 10110110110101101101011011000111
- Lowest level of language.
- Just 1’s and 0’s.
- Very hard not to make a mistake.
- Each type of computer processor has its own machine language.
Assembly language
MOV AL, 1h MOV CL, 2h MOV DL, 3h
- Alphanumeric abbreviations or mnemonic codes replace 1's and 0's.
ADD
for Add,CMP
for Compare,MOV
for Move, etc.
- Assembler program converts assembly language programs into machine language.
High-level languages
if score > 60: print('You passed!') else: print('Try harder!')
- Uses math-like or English-like notation systems.
- Allows programmer to think less about language details and more about solving problems.
- Portability
Very high-level languages
- Try to come closer to natural language than high-level languages.
Natural language programming
- Tries to let people program using everyday language.
- “Show a list of names from the contact list,” same as “Display the names of everyone in the contact list.”
Kinds of translation
- High-level languages need to be translated into machine language.
- Three approaches:
- interpreted: translate one line of the program, run it, move to the next.
- compiled: translate the whole program at once. Produces a new file full of machine code.
- hybrid: translate the whole program into an in-between language; execute the in-between language in an interpreter.
Kinds of errors
- syntax error: you broke a language rule.
- semantic or logic error: the program runs and doesn't complain, but it doesn't produce the desired result.
- runtime error: you ask the program to do something it can't, like divide A by B when B happens to be zero.
Programming process
- Define the problem.
- Design a solution.
- Code the solution.
- Test the solution.
- Document the solution.
Define the problem
- Undefined problems cannot be solved.
- May be formal or informal.
- Sometimes simple, often not.
Design a solution
- Design your solution before you try to build it!
- 80/20 rule: spend 80% of your time designing, 20% writing.
Code the solution
- Write the programming language statements and other resources you need to implement the design.
Test the solution
- debugging: detecting, locating, and fixing mistakes.
- desk checking: working through your code without running it to find mistakes.
Document the solution
- documentation: a written detailed description of the programming cycle and specific facts about the program.
- Most languages let you include some documentation in the program code.
- Documentation is needed:
- to help organize program planning
- to help communicate with others about your program.
- to help remind you what your program is doing.
- Very important!!!
Programming tools
- code editor: used to write the program code (i.e., source code).
- translator: used to translate source code into a form the computer can execute.
- debugger: used to interactively run a program and observe its internal state.
- project manager: used to organize source code and other files associated with a program.
- IDE (integrated development environment): integrates a number of these tools into one unified environment to help increase productivity.
Fin
<html> <script> var uls = document.getElementsByTagName('ul'); for(var i=0,j=uls.length;i<j;++i){uls[i].setAttribute('class','incremental')} </script> </html>
computer_basics/programming_fundamentals.txt · Last modified: 2019/01/12 02:32 by mithat