Fireship · @fireship
Object Oriented vs Functional Programming with TypeScript
Uploaded December 14, 2018 · Length 12:07
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.
- 0:00
[Music]
- 0:06
which is better
- 0:07
object-oriented or functional
- 0:09
programming how about composition or
- 0:11
inheritance semicolons or no semicolons
- 0:14
is it pronounced Jif or gif and is a hot
- 0:17
dog of sandwich today you'll get all the
- 0:19
answers and I encourage you to just
- 0:20
accept these as the facts and not try
- 0:22
out anything on your own there's only
- 0:24
one correct way to write code and if
- 0:26
there's one thing that employers hate
- 0:27
it's creative problem-solving skills
- 0:29
from their programmers if you're new
- 0:30
here like and subscribe and congrats to
- 0:32
Alexander Torres here the random t-shirt
- 0:34
winner from last week and a huge thank
- 0:36
you to Patrick Neal Lou
- 0:37
he contributed to the content of this
- 0:39
video and has helped out hundreds if not
- 0:41
thousands of developers on our slack
- 0:42
Channel so make sure to spam him with a
- 0:45
thank you message let's go ahead and
- 0:46
take care of the easy ones first when
- 0:48
writing your code you should leave some
- 0:49
Mikael arms out and then have prettier
- 0:51
add them back when you save the file gif
- 0:53
stands for graphics interchange format
- 0:55
so it's obviously pronounced gift
- 0:57
following the first word in the acronym
- 0:58
itself is a hot dog sandwich well that
- 1:01
one's a little more complex so let's
- 1:03
wait till the end of the video
- 1:04
how about object-oriented versus
- 1:06
functional programming
- 1:07
if you guessed object-oriented is better
- 1:09
you're completely wrong and if you
- 1:11
guessed functional programming you're
- 1:12
way off base debating programming
- 1:14
paradigms at this level is like debating
- 1:16
art there is always more than one way to
- 1:18
solve a problem especially in JavaScript
- 1:20
and it's great to debate these things
- 1:21
but there are no absolutes there's going
- 1:23
to be a trade-off for every decision
- 1:25
that you make let's start by taking a
- 1:27
look at some functional typescript code
- 1:29
the most important concept in functional
- 1:32
programming is the concept of pure
- 1:33
functions this means that the output of
- 1:36
your function should only depend on its
- 1:37
inputs for example here we have a
- 1:39
function called two string which takes a
- 1:41
value as its argument and then returns
- 1:43
that value formatted as a string we can
- 1:46
make this an impure function by mutating
- 1:48
the number variable directly this would
- 1:50
be considered a side-effect and
- 1:51
functional code should produce no
- 1:53
side-effects in addition they should not
- 1:55
rely on any outside value to produce a
- 1:57
return value pure functions are easier


