Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program...

16
Programming Paradigms By Tyler Smith

Transcript of Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program...

Page 1: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

Programming Paradigms

By Tyler Smith

Page 2: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

Event DrivenEvent driven paradigm means that the program executes code in reaction to events.

The limitation of this paradigm is that makes execution order ambiguous, and these threads can use a lot of memory.

*Thread: Events are executed in a separate process so they can run simultaneously.

Page 3: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

Event Driven ExampleThis example will popup a message when the body of the document is clicked. HTML elements have methods that waits for them to be clicked. When it is clicked, it executes the function stored.

```JavaScript

document.getElementById(‘body’).onclick=function() {

alert(“STOP CLICKING”);

}

```

Page 4: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

Traditional Procedural Paradigm

A procedural paradigm executes commands linearly. This means that it’s not possible to use more than one processor core, making the paradigm unusable for more efficient programming(This is the main limitation), but it is useful for having multiple users connected at the same time. One application of this is on web servers with PHP.

Page 5: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

Procedural ExampleBelow is an example of a PHP API that will return all data on a name stored in a database, given the predefined function ‘make_sql_request’. This code executes line by line, in order.

```PHP

$name = mysql_real_escape_string($_REQUEST[‘name’])

$request = ‘SELECT * FROM `db` WHERE `name` = `‘ . $name . ‘`’

$recv = make_sql_request($request);

print_r($recv)

```

Page 6: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

Traditional Object Oriented Paradigm

Object orientation is the focus on the ‘object’ datatype. The object data type was built to mimic objects in real life. An object type variable has properties and methods. These are used to gather data from the object, or execute actions using the object. The limitations of this data type is that you are unable to iterate it, and it takes more time to initialize.

Page 7: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

Object Oriented Example

Creating an object called student, and using that object in a function:

```Python

class Student(object): name = "" age = 0 major = "" def __init__(self, name, age, major): self.name = name self.age = age self.major = major

def make_student(name, age, major): student = Student(name, age, major) return student

```

Page 8: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

Data Types

Page 9: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

DatatypesName Example size Comment

String <Python>mystring = ‘Hello World’

12Gb, in x86. Feasibly infinite in x64, dependant on RAM (In Python)

A string is a list of characters. Strings are iterable, and can be used in an array of functions.

Integer <PHP>$myinteger = 10;

4 bytes An integer is another term for ‘Whole number’. Integers aren’t iterable, but they can be used in various maths functions, such as adding, multiplying and more.

Float <NASM x86 assembly>global _startsection .data val: dq 123.45

4 bytes Floating point numbers are useful for data presentation. Note: Floating point numbers are never accurate.

Boolean <JavaScript>var myboolean = true;

1 bit Booleans are useful to return from functions and to test for in conditions.

Array <C>int myarray[1] = {0, 1};

array is made up of all datatypes within the array IE: 8 bytes

Arrays are very much iterable, and are useful to store lots of information that is editable and flexible within programming.

Associative Array <Ruby>myassociativearray = {'Hello' => ‘World’, 'Answer' => 42}

associative array is made up of all datatypes within the array IE: 8 bytes, along with the string used to list it

This data type is useful for categorizing data, but still passing it as a single variable, similar to an object.

Page 10: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

1. StringA string is a list of characters. This is how to define a string in Python:

mystring = ‘Hello World’

A string is a list of characters. Strings are iterable, and can be used in an array of functions. Strings in the Python interpreter can be of almost any size due to Python’s modern architecture.

Page 11: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

2. IntegerAn integer is another term for ‘Whole number’. Here’s and example of defining an integer in PHP:

$myinteger = 10;

An integer is another term for ‘Whole number’. Integers aren’t iterable, but they can be used in various maths functions, such as adding, multiplying and more. PHP also has modern arch, so integers can be of almost any length.

Page 12: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

3. FloatA float type is a number with decimal places. This how to define a floating point in NASM x86 assembly syntax:

global _start

section .data val: dq 123.45

Floating point numbers are useful for data presentation. Note: Floating point numbers are never accurate. Assembly can buffer memory in any size, as the language is almost the lowest of levels.

Page 13: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

4. BooleanA boolean value is a variable that can only be in two forms. Usually ‘true’ or ‘false’, but can be ‘0’ or ‘1’. This is an example of setting a boolean in JavaScript:

var myboolean = true;

Booleans are useful to return from functions and to test for in conditions. Booleans in Javascript use a single bit. A 1 or 0.

Page 14: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

5. ArrayAn array is a variable that can contains multiple values. Here is an example of an array in C:

int myarray[1] = {0, 1};

Arrays are very much iterable, and are useful to store lots of information that is editable and flexible within programming. In C, the number of bytes in the array is defined by the statement. In this case, there are two buffers of a 4 bits.

Page 15: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

6. Associative ArrayAn associative array is another type of array that can contain string type definitions. Here is an example of an Associative array in Ruby:

myassociativearray = {'Hello' => ‘World’, 'Answer' => 42}

This data type is useful for categorizing data, but still passing it as a single variable, similar to an object.

Page 16: Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.

ConclusionChoosing a data type is important to a programmer as a datatype that can store the required information efficiently. When an appropriate data type is chosen, code is easier to read, programs are faster, and storage is more efficient. For example: Trying to store a time as a string would take a lot of code to convert it back to a format that we can use (Depending on the string format).