Programming (Crash Course)

This tutorial is made in the notion that anyone can program. Keep in mind that this does not mean that anyone should program. This document will meerly take an individual and bring them up to speed with important terminology and concepts. This does not take into consideration good programming standards and practices.
  • A computer is a device or piece of hardware that follows instructions
  • A program gets its instructions from a user or hard coding with the program
  • Program - a set of carefully written logical instructions
  • When a computer performs those instructions it is running or is being executed
  • The steps that are your set of instructions are known as algorithms
  • An algorithm is not always a math formula
  • Algorithm is a set of well defined logical steps, must be performed in order to perform a task
  • Algorithms are understandable by humans (natural language)


  • Compiler or interpreter converts into machine code
  • 8 bits = 1 byte
  • Operators: +-*/
  • (addition subtraction multiplication division)
  • Perform arithmetic and functions on data
  • Syntax – set of rules that have to be followed
  • Similar to the set of rules that you follow in a natural language
  • Writing program = writing code
  • Programs consist of keywords, operators, punctuation and more arranged in proper sequence.
  • Save, compile executable program
  • Alice uses objects (tent, frog, island)
  • Objects perform actions (turn, move, fly, wave)
  • Objects are made of other objects
  • Objects are named in camel case
  • Methods are used to manipulate an object
A world contains all other objects
-Also has its own properties
Atmosphere color, lighting, fog

Objects are created from classes

Class set of specifications that describe a particular object
Gallery is a collection of different objects

Class: chicken
Chicken1
Chicken2
Chicken3
Each instance (chicken) has its own properties, methods, functions
Alice worlds and objects have height width and depth

----------------------------------------------------------------

Programming: Putting together the piece

built-in functions and expressions in Alice
A MAJOR PART OF LEARNING HOW TO PROGRAM IS FIGURING OUT HOW TO “PUT THE PIECES TOGETHER” THAT COMPOSE A PROGRAM.
Purpose:

define the fundamental pieces of a program
demonstrate how to put the pieces together
The four fundamental pieces:


Instruction
An instruction is a statement that executes (is carried out by the computer at runtime)
In Object Oriented Programming, an instruction is defined as a method
Instructions can be used to make objects do an action
Control Structure
A statement that controls which instructions are executed and in what order
Function
Asks a question (to check a condition) or compute a value
A function is not a standalone command it is nested inside another command
Values:
When a function is used to a question or perform a computation, an answer is returned.
The answer is called a value.
The type of value depends on the kind of function.
Types of values:
Boolean – true, false
String - “Oh, Yeah!”
Object – snowman, helicopter
Position in the world – (0, 0, 0 – the center of the Alice world)
Built in functions:
Proximity
Size
Spatial relation
Point of view
Other
In Alice, a function is used to determine
Properties of an object
The relationship between one object and another
A current condition
Expression
An expression is a math or logic operation on numbers or other types of values
Alice provides math expressions:
Addition +
Subtraction –
Multiplication x
Division /

*over-use parenthesis – it is always best to control the execution of equations

(Width of the pharaoh + with of mummy)/2

Programming Simple Control Statements
We have used do together and do in order but they can also be used for conditional execution and repetition

Conditional execution is where some condition is checked and a decision is made about whether a block of the program will be executed

Conditional execution is extremely useful in
Games
Simulations
Real-time controls e.g. robot systems

If/Else is a control statement is used to check a condition and make a decision

In some cases, the built in functions are not sufficient for a condition that we want to check

Relational operators – in situations where you need to write your own comparison you can use a relational operator

Relational operators are provided in the world’s built in functions

== is equal to
!= is not equal to
> is greater than
>= is greater than or equal to
< is less than
<= is less than or equal to

Walking code is complex because we have to think about alternating leg movements and coordinating them with the forward movement


indenting makes control statements easier to understand
Need for repetition:

the loop statement is a simple control structure that provides for repeating an instruction (or block of instructions) a counted number of times.
Variables:

programs may need to store data when running and it stores that data in a variable
A variable is named storage location in the computers memory
The following types of data (or variables) can be stored:
Local variables
Belongs to a specific method
Used only by the instructions that the variable belongs to
When a method stops, the variables cease to exist
Parameter variables
Used to hold an argument that is
Class-level variables
World level variables
Variable Names

must be unique within the method
should be meaningful and reflect the variable’s purpose
named using camelCase
Variable Types

Numbers, Boolean, Objects, String Color Sound
Initial Value

Value initially stored in the variable
Tile appearance shows the type of variable
All Boolean values should be initialized first as true (as programmers we think of everything as being true first)
Creating the variable is called variable declaration

Variables need to have an initial value
Initial value held until a different value is assigned
New values can be assigned while the method is running

Boolean logic, Math, Random, String,

Math Operators are used to create math expressions
Math expressions perform a calculation and return a value
Working with strings and text

a string is a sequence of characters
strings represent
names
addresses
messages
etc.
Asking the user to enter a string

world’s primitive function can ask user to enter string (text)
the function returns the text the user enters
joining separate sets of strings is called concatenation
Joining Strings
Strings Concatenation

joins string a with string b
strings are arguments
does not change the values of the strings a or b… but combines the two strings
strings are not just text… but any alphanumeric character
can convert to a string for use as well
Text can be added to Alice worlds
3D text option is available at the end of the local gallery

Boolean Values

- True or False?
- Boolean values hold only two values: true or false
Also primitive functions that are Boolean

user prompted to answer yes (true), or no (false)
Variables should always be initialized as true.
The If/Else Decision structure executes one set of instructions if a Boolean condition is true and a different set if the condition is false
All previous instructions have been in sequential order

If is the true structure
Else is the false structure

If else is a dual-alternative decision structure

two paths of execution: one following true and one following false
Single-alternative decision structures are similar to the dual-alternative accept there is only one set of alternate code
If am if/else instruction is nested within another if else instruction they are nested

“When you identify who you are you will become a better programmer”
The loop instruction cause one or more other instructions to retest or loop a certain number of times

Loops use integers (whole numbers) and decimal proportions are discarded (truncated)
Infinite loops NEVER stop

use for objects that shouldn't stop
if placed in consecutive order the next instruction will never occur, since the loop never ends
Flowcharting loops:
Process box that sets index value to 0 decision symbol does true or false increment index value (add 1 to index value)

  • Programmers hold on to languages and specialize in them
    • Examples of languages: C++, Java, Perl, Python
  • IDE – interactive development environment
  • OOP – object orient programming
    • objects are items that the user can interact with
    • EX: a checkbox

  • OOP for:
    • Graphical objects
    • Mathematical objects
    • Input-output devices
    • Simulation
    • Reusable software components

  • Machine Languages:
    • Also known as machine code
    • Programming instructions are written in 0s and 1s
    • Very tedious and error-prone
    • Used by highly trained programmers

  • Assembly Languages:
    • Slightly more advanced programming languages
    • Programmer ruses mnemonics in place of 0s and 1s
    • Mnemonics are memory aids or alphabetic instructions
    • Requires an assembler to convert the code to machine lang.
    • Tedious and requires highly trained programmer

  • High-level languages
    • Interpreter – a program that converts high-level instructions into machine code before, line by line as the program is running

Description of visual basic

  • any part of the code can be changed at any time
  • the programmer does not need to write an general code to initialize windows, handle events, or interact with users.
  • Visual Studio – is the development environment provided by Microsoft to write the applications

OOP

  • a programmer can define the data types and methods
  • a general type of object is called a class
  • one class is defined, specific instances of that class
  • OOP uses:
    • Graphical objects
    • Mathematical objects
    • Input-output components
    • Reusable software

  • Assembly language


  • High level languages
    • Allow the programmer to use instructions that more closely resemble the English language
    • Compiler – a program that converts code into9 machine language

Procedure oriented high level languages
-The emphasis of a program is on how to accomplish a task
-The programmer determines

  1. must instruct the computer every step of the way
  2. determines the order in which the computer interpreted the instructions

Windows software provides an easy to-to-use graphical user interface
-GUI – (gooey)
-Graphical Use Interface
-Is a way of communicating with the computer by manipulating icons (pictures) and windows with a mouse?
-The first widely used GUI machine was the Apple Mackintosh in 1984
-The release of Microsoft Windows 3.0 on IMB PC compatibles

Object-Oriented Event-Driven High Level Languages

  • Simplified the tasks of programming applications

OOP – object oriented programming – using an object-oriented language to create a program that contains one or more objects

OOD – Object-oriented-design – the design methodology uses to plan object-oriented programs; divide a problem into several smaller objects

Object

  • anything that can be seen or touched
  • has attributes that describe the object
  • has behaviors that the object can either perform of have preformed on it
  • Examples of objects: clock, book, car

Class

  • a pattern or blueprint for creating a class
  • the pattern or blueprint of referred to as the instance of the class:
    • cookie cutter, dress pattern

Encapsulation
  • "to enclose in a capsule"
  • Combining an objects attributes and behaviors into one package – a class

Extraction
  • hiding the details of an object to prevent the user from making inadvertent changes to an object
  • Some attributes and behaviors are hidden, while others are exposed.

Inheritance
  • allows you to create one from another class
  • the new class is called the derived class
  • the original class is called the base class
  • same as someone's children having similar traits to them

Hungarian notation naming convention
  • First three characters represent the type of object
  • Remaining characters represent objects purpose
  • Name is entered in camel case (for camels hump)
  • Example: frmCalculateTaxes

New naming convention

  • Indicate the form purpose and class
  • Form names are entered using Pascal case
  • Example: CopyrightForm

Recursion

Recursion is the ability of code to call itself. This is used when we don’t know how many times we want something to repeat. In programs where a count of repetitions is not known (indefinite), we can use one of two repetition control mechanisms:

  • Recursion
  • While statement

Many of the pieces we use to create a program are identified by using special words. A second form of recursion is subroutines (events).

Randomness

Testing a program that uses random numbers requires extra caution.


No comments:

Post a Comment