Fireship · @fireship

Object Oriented vs Functional Programming with TypeScript

Uploaded December 14, 2018 · Length 12:07

Object Oriented vs Functional Programming with TypeScript

Summary

comparing object-oriented and functional programming paradigms with examples in TypeScript

  • object-oriented programming
  • functional programming
  • typescript
  • programming paradigms
  • javascript

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    [Music]

  2. 0:06

    which is better

  3. 0:07

    object-oriented or functional

  4. 0:09

    programming how about composition or

  5. 0:11

    inheritance semicolons or no semicolons

  6. 0:14

    is it pronounced Jif or gif and is a hot

  7. 0:17

    dog of sandwich today you'll get all the

  8. 0:19

    answers and I encourage you to just

  9. 0:20

    accept these as the facts and not try

  10. 0:22

    out anything on your own there's only

  11. 0:24

    one correct way to write code and if

  12. 0:26

    there's one thing that employers hate

  13. 0:27

    it's creative problem-solving skills

  14. 0:29

    from their programmers if you're new

  15. 0:30

    here like and subscribe and congrats to

  16. 0:32

    Alexander Torres here the random t-shirt

  17. 0:34

    winner from last week and a huge thank

  18. 0:36

    you to Patrick Neal Lou

  19. 0:37

    he contributed to the content of this

  20. 0:39

    video and has helped out hundreds if not

  21. 0:41

    thousands of developers on our slack

  22. 0:42

    Channel so make sure to spam him with a

  23. 0:45

    thank you message let's go ahead and

  24. 0:46

    take care of the easy ones first when

  25. 0:48

    writing your code you should leave some

  26. 0:49

    Mikael arms out and then have prettier

  27. 0:51

    add them back when you save the file gif

  28. 0:53

    stands for graphics interchange format

  29. 0:55

    so it's obviously pronounced gift

  30. 0:57

    following the first word in the acronym

  31. 0:58

    itself is a hot dog sandwich well that

  32. 1:01

    one's a little more complex so let's

  33. 1:03

    wait till the end of the video

  34. 1:04

    how about object-oriented versus

  35. 1:06

    functional programming

  36. 1:07

    if you guessed object-oriented is better

  37. 1:09

    you're completely wrong and if you

  38. 1:11

    guessed functional programming you're

  39. 1:12

    way off base debating programming

  40. 1:14

    paradigms at this level is like debating

  41. 1:16

    art there is always more than one way to

  42. 1:18

    solve a problem especially in JavaScript

  43. 1:20

    and it's great to debate these things

  44. 1:21

    but there are no absolutes there's going

  45. 1:23

    to be a trade-off for every decision

  46. 1:25

    that you make let's start by taking a

  47. 1:27

    look at some functional typescript code

  48. 1:29

    the most important concept in functional

  49. 1:32

    programming is the concept of pure

  50. 1:33

    functions this means that the output of

  51. 1:36

    your function should only depend on its

  52. 1:37

    inputs for example here we have a

  53. 1:39

    function called two string which takes a

  54. 1:41

    value as its argument and then returns

  55. 1:43

    that value formatted as a string we can

  56. 1:46

    make this an impure function by mutating

  57. 1:48

    the number variable directly this would

  58. 1:50

    be considered a side-effect and

  59. 1:51

    functional code should produce no

  60. 1:53

    side-effects in addition they should not

  61. 1:55

    rely on any outside value to produce a

  62. 1:57

    return value pure functions are easier