Nothing Special   »   [go: up one dir, main page]

What Is Programming?: Writing Games Writing Application Programs (Like Excel)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

What is programming?

-Series of instructions to a computer to accomplish a task

-Instructions must be written in a way the computer can understand

-Programming languages are used to write programs

-Once the code (language) of a program has been written, it must be executed (run, started).

-You may need to type the name of the program to start it , or use a word like RUN and the
name of the program (in the old days, anyway).

-Some programming languages (like Java or C++) require the code to be compiled (translated
to binary) before it can be started.

-Others (like JavaScript) are interpreted, meaning that each command is translated separately
when the program is started.

What is a programming language?

-A set of rules that provides a way of telling a computer what operations to perform

-Set of commands that a computer has been "taught" to understand

-Languages that look like "machine code" (e.g., 82A8: jsr r5, @#82AE 82 AC: sob r0, 8296) are
used for...

~Writing games

~Writing application programs (like Excel)

-Other languages look like English ("high level," e.g., PRINT "HELLO")

~Logo

~JavaScript

~And many more

The principal paradigms

-Imperative Programming (C)

-Object-Oriented Programming (C++)

-Logic/Declarative Programming (Prolog)

-Functional/Applicative Programming (Lisp)


Levels of Programming Languages

-High-level program

-Low-level program

-Executable Machine E

HIGH-LEVEL LANGUAGES

~FORTRAN

* FORmula TRANslation

* Developed at IBM in the mid- 1950s

* Designed for scientific and mathematical applications by scientists and engineers

~COBOL

* COmmon Business Oriented Language.

* Developed in 1959

* Designed to be common to many different computers.

* Typically used for business applications.

~BASIC

* Beginner's All-purpose Symbolic Instruction Code.

* Developed at Dartmouth College in mid 1960s.

* Developed as a simple language for students to write programs with which they could interact
through terminals.

~C

* Developed by Bell Laboratories in the early 1970s

* Provides control and efficiency of assembly language while having third generation language
features.

* Ofter used for system programs.

* UNIX is written in C
~C++

* it is C language with additional features.

* Widely used for developing system and application software

* Graphical user interfaces can be developed easily with visual programming tools.

~JAVA

* An object-oriented language similar to C++ that eliminates lots of C++'s problematic features

* Allows a web page developer to create programs for applications, called applets that can be
used through a browser.

* Objective of JAVA developers is that it be machine, platform and operating system


independent

Markup Languages

~HTML

* HyperText Markup Language

* Used on the Internet and the World Wide Web (WWW).

* Web page developer puts brief codes called tags in the page to indicate how the page should
be formatted

~XML

* Extensible Markup Language

* A language for defining other languages.

How do you write a program?

-Decide what steps are needed to complete the task


-Write the steps in pseudocode (written in English) or as flowchart (graphic symbols)
-Translate into programming language
-Try out the program and debug it (fix if necessary)

What is pseudocode?

-List of steps written in English


-Like the instructions for a recipe
-Must be in the right sequence
Imagine saying bake the cake and then mix it up

Sample Pseudocode

-Task: add two numbers


-Pseudocode
Start
Get two numbers
Add them
Print the answer
End

What does a flowchart look like?

-The pseudocode from the previous slide would look like this as a flowchart:

Start
Print Answer

Get 2 numbers

End

Add them

What are those funny symbols?

-START/END
Used at the beginning and end of each flowchart

-INPUT/OUTPUT
Shows when information/data comes into a program or is printed out.

-PROCESS
Used to show calculations, storing of data in variables, and other processes that
take place within a program.

-DECISION
Used to show that the program must decide whether something (usually
comparison between numbers) is true or false. YES and NO (or T/F) branches are

usually shown.
Start
Another Sample: Calculating Age
Get yr
-Pseudocode
Start
Calc age
Get year born
Calculate age
Print age
Print age
If age > 50 print OLD Y
End Age>50
OLD

End

Elements of a Program

-All programming languages have certain features in common. For example:


Variables
Commands/Syntax (the way commands are structured)
Loops
Decisions
Functions
-Each programming language has a different set of rules about these features.

Variables
-Variables are part of almost every program.
-A variable is a place to put data and is usually represented by a letter or a word. (Think of a
variable as a Tupperware container with a label on it.)
-Variable names cannot contain spaces.
-Some programming languages have very specific limits on variable names.
-Usually there are several ways to put information into a variable.
-The most common way is to use the equal sign (=).
-X = Y + 7 means take the value of Y, add 7, and put it into X.
-COUNT = COUNT + 2 means take the current value of COUNT, add 2 to it, and make it the
new value of COUNT.
-Sometimes you must specify the type of data that will be placed in a variable
-Here are some examples of data types:
Numeric (numbers of all kinds)
String (text, strings of letters)
Integer (whole numbers)
Long (large numbers)
Boolean (true/false)
-Variables may be classified as global or local
-A global variable is one that can be shared by all parts of a program including any functions or
subprograms.
-A local variable is one that is used only within a certain part of the program for example, only in
one function or subprogram.

Commands/Syntax

-Programming languages are truly languages


-They have rules about grammar, spelling, punctuation, etc.
-You need to learn the rules of a programming language, just as you learned to speak and write
English.

Loops

-A loop is a repetition of all or part of the commands in a program


-A loop often has a counter (a variable) and continues to repeat a specified number of times.
-A loop may also continue until a certain condition is me (e.g., until the end of a file or until a
number reaches a set limit)

Decisions

-You saw a flowchart symbol for decisions.


-A program often needs to decide whether something is true or false in order to see which way
to continue
-Programs often use IF (or IF THEN or IF THEN ELSE) statements to show a decision.
-An IF statement always has a condition to check, often a comparison between variable and a
number.
-The IF statement also must specify what to do if the condition/comparison is true.
-These instructions (for true) may come after the word THEN, or they may simply be listed.
-In an IF THEN statement, when the condition is false, the program simply ignores the THEN
commands and continues to the next line.
-In an IF THEN ELSE statement, commands are given for both the true and false conditions

Functions

-In most programming languages, small subprograms are used to perform some of the tasks.
-These may be called functions, subroutines, handlers, or other such terms.
-Functions often have names (e.g., getName or CALCTAX).
-A function generally gets information from the main program, performs some task, and returns
information back to the program.
-Functions follow the same rues of syntax, etc. as the main program.
-JavaScript code is primarily made of a series of functions.

Hints for Writing Code

-Code means writing the program in the appropriate language


-Be sure the code is exact (spelling, capitals/lower case, punctuation, etc).
-Write part of the code, try it, and then write more.
Debugging

-To debug means to try a program, then fix any mistakes.


-Virtually no program works the first time you run it. There are just too many places to make
errors.
-When you are debugging a program, look for spelling and punctuation errors.
-Fix one error at a time, then try the program again.

You might also like