1 / 16

Programming Paradigms

Programming Paradigms. By Tyler Smith. Event Driven. Event 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.

melba
Download Presentation

Programming Paradigms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Paradigms By Tyler Smith

  2. Event Driven Event 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.

  3. Event Driven Example This 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”); } ```

  4. 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.

  5. Procedural Example Below 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) ```

  6. 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.

  7. 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 = majordef make_student(name, age, major): student = Student(name, age, major) return student ```

  8. Data Types

  9. Datatypes

  10. 1. String A 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.

  11. 2. Integer An 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.

  12. 3. Float A 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.

  13. 4. Boolean A 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.

  14. 5. Array An 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.

  15. 6. Associative Array An 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.

  16. Conclusion Choosing 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).

More Related