Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Programming Paradigms Which One Is The Best?

44,368 views

Published on

Slides by Adrian Kashivskyy from @netguru.

Published in: Technology

Programming Paradigms Which One Is The Best?

  1. 1. PROGRAMMING PARADIGMS WHICH ONE IS THE BEST? @akashivskyy
  2. 2. PROGRAMMING
 PARADIGMS
  3. 3. WAY OF LOOKING AT
 CONTROL FLOW AND EXECUTION OF A PROGRAM
  4. 4. 1. OBJECT-ORIENTED PROGRAMMING
  5. 5. PROGRAM IS DEFINED BY OBJECTS WHICH COMBINE STATE AND BEHAVIOR
  6. 6. 3 ASSUMPTIONS
  7. 7. 1. ABSTRACTION 2. ENCAPSULATION 3. INHERITANCE
  8. 8. protocol Shape ! var area: Double " func printShapeArea(shape: Shape) ! println("area = (shape.area)") "
  9. 9. struct Square: Shape ! let side: Double let area: Double ! return side # side " " printShapeArea(Square(side: 4)) // 16.$
  10. 10. struct Circle: Shape ! var radius: Double var area: Double ! return M_PI # radius # radius " " printShapeArea(Circle(radius: 2)) // 12.56
  11. 11. struct Plane: Shape ! var area: Double ! return Double.infinity " " printShapeArea(Plane()) // infinity
  12. 12. 1. ABSTRACTION 2. ENCAPSULATION 3. INHERITANCE
  13. 13. class EncryptionAssistant ! private var key = "42$mlg$crub" public func encrypt(pass: String) -> String ! return rsaEncrypt(pass, key) " "
  14. 14. let assistant = EncryptionAssistant() assistant.encrypt("secret") // 1Ll$$Myn4RtY assistant.key // compile error!
  15. 15. 1. ABSTRACTION 2. ENCAPSULATION 3. INHERITANCE
  16. 16. VEHICLE RAILWAY ROAD TRAM TRAIN BICYCLE CAR
  17. 17. class Car ! var color: String = "red" var name: String ! return "(color) car" " " class BlueCar: Car ! override var color = "blue" "
  18. 18. Car().name // red car BlueCar().name // blue car
  19. 19. 2. IMPERATIVE
 PROGRAMMING
  20. 20. IMPERATIVE PHRASES WHICH CHANGE THE GLOBAL STATE OF A PROGRAM
  21. 21. let numbers = [1, 2, 3, 4, 5, 6] var sum = $ var odds: [Int] = [] for number in numbers ! sum += number if number % 2 == 1 ! odds.append(number) " "
  22. 22. getRemoteData("url", ! data, error in if error == nil ! parseData(data, ! parsed, error in if error == nil ! handleParsedData(parsed) " else ! displayError(error) " ") " else ! displayError(error) " ")
  23. 23. IMPERATIVE
 PROGRAMMING IS
 THE MOST POPULAR
  24. 24. IMPERATIVE
 PROGRAMMING IS
 THE EASIEST
  25. 25. IMPERATIVE
 PROGRAMMING IS
 THE WORST
  26. 26. 1. ERROR-PRONE 2. NOT SCALABLE 3. TOO COMPLICATED
  27. 27. getRemoteData("example.com", ! data, error in if error == nil ! parseData(data, ! parsed, error in if error == nil ! handleParsedData(parsed) " else ! displayError(error) " ") " else ! displayError(error) " ")
  28. 28. getRemoteData("example.com", ! data, error in if error == nil ! parseData(data, ! parsed, error in if error == nil ! if parsedDataValid(parsed) ! handleParsedData(parsed) " " else ! displayError(error) " ") " else ! displayError(error) "
  29. 29. getRemoteData("example.com", ! data, error in if error == nil ! parseData(data, ! parsed, error in if error == nil ! if parsedDataValid(parsed) ! saveParsedDataInCache(parsed, ! error in if error == nil ! handleParsedData(parsed) " else ! displayError(error) " ") " " else !
  30. 30. getRemoteData("example.com", ! data, error in if error == nil ! parseData(data, ! parsed, error in if error == nil ! if parsedDataValid(parsed) ! saveParsedDataInCache(parsed, ! error in if error == nil ! handleParsedData(parsed, ! error in if error == nil ! displaySuccess() " else ! displayError(error) " ")
  31. 31. 3. DECLARATIVE
 PROGRAMMING
  32. 32. DECLARE WHAT YOU’RE TRYING TO ACCOMPLISH, NOT HOW TO DO IT
  33. 33. let numbers = [1, 2, 3, 4, 5, 6] var sum = $ var odds: [Int] = [] for number in numbers ! sum += number if number % 2 == 1 ! odds.append(number) " "
  34. 34. var sum = $ var odds: [Int] = [] let numbers = [1, 2, 3, 4, 5, 6] for number in numbers ! sum += number // reduction if number % 2 == 1 ! // filtration odds.append(number) " "
  35. 35. let numbers = [1, 2, 3, 4, 5, 6] let sum = reduce(numbers, $, ! memo, number in return memo + number ") let odds = filter(numbers, ! number in return number % 2 == 1 ")
  36. 36. let numbers = [1, 2, 3, 4, 5, 6] let sum = reduce(numbers, $, +) let odds = filter(numbers, ! $$ % 2 == 1 ")
  37. 37. getRemoteData("example.com" iferror==nil! parseData(data,!parsed, iferror==nil! ifparsedDataValid(pars saveParsedDataInCach iferror==nil! handleParsedData( iferror==nil! displaySuccess "else! displayError(e " ") "else! displayError(error " ") " "else! displayError(error) " ") "else! displayError(error) " ")
  38. 38. PIPES
  39. 39. DOWNLOAD PARSE SAVE IN CACHE DISPLAY ERRORS
  40. 40. DOWNLOAD PARSE SAVE IN CACHE DISPLAY ERRORS
  41. 41. DOWNLOAD PARSE SAVE IN CACHE DISPLAY ERRORS
  42. 42. getRemoteData("example.com") .then(! data in parseData(data) ") .filter(! parsed in parsedDataValid(parsed) ") .then(! parsed in saveInCache(parsed) ") .then(! parsed in handleParsedData(parsed) ") .error(! error in displayError(error) ")
  43. 43. getRemoteData("example.com") .then(! data in parseData(data) ") .filter(! parsed in parsedDataValid(parsed) ") .filter(! parsed in !alreadyInCache(parsed) ") .then(! parsed in saveInCache(parsed) ") .then(! parsed in handleParsedData(parsed) ") .error(! error in displayError(error) ")
  44. 44. getRemoteData("example.com") .then(! data in parseData(data) ") .filter(! parsed in parsedDataValid(parsed) ") .filter(! parsed in !alreadyInCache(parsed) ") .then(! parsed in saveInCache(parsed) ") .then(! parsed in handleParsedData(parsed) ") .error(! error in displayError(error) ")
  45. 45. DECLARATIVE
 PROGRAMMING IS MUCH SIMPLER
  46. 46. DECLARATIVE PROGRAMMING IS MUCH SAFER
  47. 47. DECLARATIVE
 PROGRAMMING IS MORE SCALABLE
  48. 48. WHICH PARADIGM IS THE BEST?
  49. 49. 1. OBJECT-ORIENTED 2. IMPERATIVE 3. DECLARATIVE
  50. 50. 1. OBJECT-ORIENTED 2. IMPERATIVE 3. DECLARATIVE
  51. 51. TOGETHER
  52. 52. THANK YOU ADRIAN KASHIVSKYY @akashivskyy github.com/akashivskyy/talks

×