Programming Paradigms

9
Programming Paradigms

Transcript of Programming Paradigms

Page 1: Programming Paradigms

Programming Paradigms

Page 2: Programming Paradigms

What are programming paradigms?Programming Paradigms are general style forbuilding computer programs. Over time, paradigms and languages haveevolved to create more elegant code

Page 3: Programming Paradigms

Four paradigms we’re going over1. Imperative2. Functional3. Object Oriented Programming4. Dynamic languages

Page 4: Programming Paradigms

ImperativeOldest.Tell the computer how to do things.Heavy use of if and loops.Most programming that we did in Snap wasimperative.Most languages support imperativeprogramming.

Page 5: Programming Paradigms

FunctionalMost modernAlso considered declarativeTells the computer what to do and not how todo it.F#, Scala, Lisp, Haskell, Erlang, Clojure

Page 6: Programming Paradigms

Imperative vs Functional

var numbers = [1,2,3,4,5];var squaredNumbers = []; for (var i=0; i<numbers.length; i++) { var number = numbers[i]; squaredNumbers.push(number *number);}

var numbers = [1,2,3,4,5]; var squaredNumbers =numbers.map(function(i) { return i*i;});

Code that squares numbers in a list (JavaScript)

Imperative Functional

Page 7: Programming Paradigms

Object Oriented ProgrammingModel code into components that representreal constructus (objects, nouns, verbs) in thereal world.Typical object is a Customer object withproperties that define/describe a customer andactions that a customer may take.Java, C#, C++, Ruby, Python

Page 8: Programming Paradigms

Object Oriented Programmingpublic class Customer{ public string Name {get;set;} public void MakePurchase();}

Page 9: Programming Paradigms

Dynamic ProgrammingCode where type checking of data types isweak or non existent.May interchange types at will.var orderFood = function(food) {

//Food can be any type like when customer orders offmenu by number or name}JavaScript, Ruby, Python