Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Programming Paradigms

Tan Quach
January 09, 2015

Programming Paradigms

A brief introduction to programming paradigms and how to use them.

Tan Quach

January 09, 2015
Tweet

More Decks by Tan Quach

Other Decks in Programming

Transcript

  1. STRUCTURED DECLARATIVE IMPERATIVE PARADIGMS PROGRAMMING Examples of Common PARALLEL PROGRAMMING

    • Express the intent of programs through logical steps • Specify what is computed, not how • Functional programming (based on mathematical functions) • Higher-order functions for composition and reduction • Abstract data types, inheritance, polymorphism • Improve the clarity of programs through block structures and subroutines. • Model the "real-world" • Object-oriented programming • Class-based vs. prototype based • Programs written for parallel computation • Distributed computing across processors (CPU and GPU) • Message passing, actor model • States, sequences and assignments • Define sequences of commands to accomplish tasks • Procedural programming
  2. DECLARATIVE ! var arr = [1, 2, 3, 4, 5]

    ! var total = arr.reduce(function(sum, x) { return sum + x ! }) ! return total
  3. ! int arr[] = [1, 2, 3, 4, 5] !

    ! int total = 0; for (int i = 0 ; i < arr.length ; i++) { total += arr[i]; } ! return total; IMPERATIVE
  4. STRUCTURED ! ! public class ValHolder extends Object { public

    int sum(int[] intArray) { int total = 0; for (int i = 0; i++; i < intArray.length) { total += intArray[i]; } return total; } } ! public static void main(String args[]) { ValHolder vh = new ValHolder(); System.out.println(vh.sum(new int[]{1, 2, 3, 4})) } ! !
  5. ! ! import scala.actors.Actor import scala.actors.Actor._ case class Inc(amount: Int)

    case class Value class Counter extends Actor { var counter: Int = 0; def act() = { while (true) { receive { case Inc(amount) => counter += amount case Value => println("Value is "+counter) exit() } } } } object ActorTest extends Application { val counter = new Counter counter.start() for (i <- 0 until 100000) { counter ! Inc(1) } counter ! Value // Output: Value is 100000 } PARALLEL PROGRAMMING
  6. STRUCTURED DECLARATIVE IMPERATIVE PARADIGMS PROGRAMMING Examples of Common PARALLEL PROGRAMMING

    • Functional languages • Scala, Haskell, Clojure, Python • Logic Programming • Prolog • Domain-specific • SQL, Markdown, HTML • Object-oriented • Smalltalk, Java, JavaScript, C# • Ruby, Python, PHP • Scala, C++ • Actor Model • Smalltalk, Scala (Akka) • Multi-threaded • Go, Clojure, Java, C++ • Procedural • FORTRAN, Pascal, Cobol • Python, PHP, Prolog • Go, C, C++, Lisp
  7. In the end, you may end up using more than

    one to build a complete solution.