Programming Paradigms
-
Upload
leo-hernandez -
Category
Software
-
view
88 -
download
0
Transcript of Programming Paradigms
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
Four paradigms we’re going over1. Imperative2. Functional3. Object Oriented Programming4. Dynamic languages
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.
FunctionalMost modernAlso considered declarativeTells the computer what to do and not how todo it.F#, Scala, Lisp, Haskell, Erlang, Clojure
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
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
Object Oriented Programmingpublic class Customer{ public string Name {get;set;} public void MakePurchase();}
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