You are on page 1of 18

Programming

Fundamentals
Michiel van der Blonk
Contents
 Scripting

 Principles& Structures
 Types and variabeles

 Constants

 Functions

 Objects
Scripting
 What is a script language?
 What is compiling?

Sub x
11010101010101000
Do
01011010010010101

Loop Compilatie 10010101010010101
01111100101010100
If
10101010010101010
..
10111010010101001
End If
01010101001010111
End Sub
Differences
Compiler Interpreter (script)
 Fast  Slow

 Rigid  Flexible

 Strict typing  Loose typing

 Early Binding  Late binding

 Platform dependent  Platform independent

 Independent .EXE  Runtime Host (VM)


Local Script TAG
 <script>

 E.g. type=“text/javascript”
 functions in <head> or

 In separate document
The JavaScript language
 Similar syntax to
 C
 Java
 PHP
 Case sensitive
Basis principles
 Algorithms
 Loop
 Choice
 Statement
 Compound statement
 Variables

 Routines
Algorithm

Input

Statement
Output Choice
Loop
Structures
 for, foreach (LOOP)
 while (LOOP)

 If (CHOICE)

 Switch (CHOICE)
Types
 One value
 Number
 String
 Boolean
 Date
 Multiple values
 Object
 Array
Variables
 PHP: $x=1;
 JavaScript: x=1;

 Basic: x=1

 Special values
 Null
 Empty
Constants and operators
 Define(‘PI’, 3.14);
 Operators
 Math: +, -, *, /
 Comparison: ==, !=, <, >
 Special: typeof
Function examples
 Array: count, current, map
 Conversion

 Date and time

 Format and rounding

 Math: sin, cos, pow, random

 String: str_replace

 Logic: isempty
Your own functions
 Calculate the area of a land property you
own:

function Area(width, height)


result = width * height
return result

myarea = Area(10,25)
otherArea = Area(40,20)
Objects
 Created with templates (classes)
 Include functions and data

 PEAR library

 Roll your own


 Class Rectangle
 Width
 Height
 Function: Area()
Databases
 Use DB-libraries
 Functions
 E.g. mysql_connect(db,user,pw)
 Classes
 E.g. DB::connect
Resources
 Programming

 JavaScript
 Tutorial
 Function reference
 PHP.net
 Tutorial
 Function reference
Summary
 Scripting

 Principles

 Structures

 Types and variables


 Constants

 Functions

 Objects

You might also like