good Monday morning I am mpj and you are
watching fun fun function a recurring
comment on this channel is that I waste
a lot of paper people in the comments
are constantly suggesting that I should
use did you two overlays or that I
should I use a whiteboard this
frustrates a lot of you and I hate waste
too but this this is not waste today I
am going to try to convince you please
you’re not trying to expand your view on
what what waste is believe it or not
this ties into programming as well so
we’re going to look at some code later
on in this in this episode and expanding
your view on what waste is it’s going to
make you a better programmer so at first
glance me using paper it looks like
waste these papers are not reusable well
I do you reuse the the back of them but
and these papers they come from trees so
this is waste this is bad
right right look how much paper i’m
wasting i’m just i’m just tearing it up
this is this is horrible isn’t it wait
on this one
I’m not look I’m not even reusing the
back of this one horrible now I would
like to State for the record here that I
that I hate waste for instance I really
hate throwing food away and whenever I
eat at McDonald’s it makes me feel bad
because they have so much packaging on
their food but these specific papers I
do not consider these to be a waste they
are a different category so there is
this amazing book called Thinking Fast
and Slow by Nobel prize-winner called
his name is Daniel Kahneman I’ve linked
to
in the episode description the book is
basically about how your brain has two
systems one system is really fast and
it’s good at doing really quick quick
thinking intuitive thinking rough
approximations really quickly stuff like
that and then we have another system one
that is a lot slower but it’s also more
deliberate and more logical and can make
much more advanced thoughts now the fast
system is really good when you’re
driving in your car and suddenly there’s
a deer on the road and you have to
swerve around it and wow that you had to
do that really fast and now there is
some asshole on the internet tearing up
paper and your ancestors your fresh
system is going to go oh that’s waste
waste waste waste and that is going to
trigger the emotion anger in you and
research has shown that anger is very
very that the emotion that is most
likely to get us to interact on social
media so you go to write an angry
comment and you’re gonna rap but instead
if you let your slow brain system do do
the work you can watch like this person
is tearing up a lot of paper here hmm
and you can you can watch behind the
screen we monitor or your phone or
whatever and you see that it’s not
actually a person here you are watching
a two dimensional artifact of a video
production the experience that you are
having right now it’s going to be
replicated to at least 10,000 people the
first week that I release it so in order
for you to judge if there is actual
waste being done
you have to imagine like the paper
resource being expelled the paper being
used and divide that by the number of
views that this video has on and you
actually also had two experts do an
extrapolation of of the growth of the
video so that you kind of do an
approximation of the lifetime of the
video during the time it will stay on
the internet was it which is probably a
few years during the production of these
videos there’s also a lot of
resources being used that you don’t see
mostly my time producing one of these
videos takes takes approximately a day I
the script writing and editing and
shooting of course and then a lot of
setup and lighting and makeup as well
and there’s usually a bit of technical
hassle as well that I have to solve
every time plus uploading and rendering
and it’s probably something I forget
basically this channel eats up my Sunday
I there’s nothing else I can do on
Sundays so basically I allocate 1/7 of
my allotted life to this using these
videos and it’s not a waste of time
I mean I’m spending my day explaining a
single programming topic I could be
spending time with my family I could be
reading a book that could be cooking
some nice meal that I love to do I could
be going to the gym which I don’t love
to do I never do really I could do some
consulting
I was recently I recently turned down a
consulting gig for 200 bucks an hour
that’s real money that I could be doing
instead of doing this channel or on the
other hand I could go like help out in a
homeless shelter
I could go play a quantum break on my
xbox it’s right over there I owe I would
really love to play that right now
instead I’m sitting at a computer and
editing video and shooting video and
writing scripts all day just to explain
a single programming concept isn’t that
a waste no of course not this is the
single most important thing I do all
week this is the best and most efficient
use of my time possible why because
every episode is seen by tens of
thousands of people nothing else that I
could do will create this much good per
minute of life that I invested in it if
I spent an entire day explaining monads
to another person oh this link to that
episode the Mona Depa sewed in the
description by the way
if I spent an entire day explaining
monads to person that might not even get
it that could be a very bad use of my
time
but the monad video is not to one person
it’s it’s beneficial to tens of
thousands of people and in just the same
way this is not a waste of paper before
this episode I went to over to
McDonald’s and I bought two
cheeseburgers one of them I ate on the
spot because I lack self-discipline and
that was a waste the paper wrapping that
hamburger was a total waste because it
it just benefits one person that is
wasteful this one however is a problem
and this paper waste is divided by all
the people watching this video that I’m
trying to make a point to all over you
that put into each meal is multiplied
tens of thousands of times that is why
and that is why it’s not a waste for me
to spend half an hour trying to get a
sentence and important sentence of the
script just right because even if it
adds just a little value it’s still a
big value because of this multiplication
in the same way I used to have this
digital text overlays and I moved to
paper because I like that I can throw
them and I couldn’t I can’t stick things
on them I can’t ever you know there’s so
much more fun they also give the channel
a cool distinct look that does it looks
fun fun functioning a whiteboard I guess
would do some of that but a whiteboard
is I don’t know if you thought about
this but a whiteboard has a glassy
surface and I have these two big-ass
lights in my face all the time so I
would have to deal with the glare
somehow it feels to me like a whiteboard
would be a step back from paper these
burgers are like my guilty pleasure
number one
Yushu good not sponsored you should not
anyway the concept that I’m trying to
get across here is that just because
something looks like waste doesn’t mean
it that it is because of I tore
that house because waste yes
waste is context-sensitive you cannot
determine if something is waste by
looking at it in isolation
you cannot accurately conclude that
something is waste just because you’re
fast brain system will identify it as
waste you have to consider the whole
picture using your slow brain system I’m
pointing at the right side and left side
of the brain but that’s not what it’s
about I don’t even know if they have a
location let me show you the
implications that this has in
programming I’m going to show you two
functions they both locate an element in
an array by checking it’s ID property
and I want you to think about if we need
to optimize one of them so in this
example this first one we have an
function find by ID and it has a a for
loop it loops through an array that it
gets here and it will compare the the ID
property on the array with the ID that
it gets from from as a second argument
and if it matches it will return that
item element this is example two it has
the same signature it’s fine by ID it
takes an array and it takes an ID and
it’s a bit different though it has a
wash let’s call make this a let it sets
up a found variable and then it uses for
each to loop through the and the erect
and for each item it’s going to do the
same thing that we did up here it’s
going to compare the ID property on the
the the element or the item with the ID
that we’re passing and we’re passing in
as an argument and if it does if it does
match it will assign the item to the
found variable and once it’s done it’s
going to return found here at the end so
again I’m asking you do we need to
optimize any of these functions I am
tempted to answer both it’s a bit of a
cop-out answer because then we cover all
bases but optimizing all code in our
code base it’s it’s simply not a
realistic way of doing development
development time is very expensive and
it is very expensive because developers
take a long time to train and then they
are useful for a little while and then
they retire and then they die if we
spend our development time on optimizing
every single line of code that we ever
write and ever run across we would
pretty much be doing only that and not
getting any work done we really need to
have a thought process that allows us to
pick and choose the battles when it
comes to optimization so with that in
mind I again ask you do we need to
optimize any of these functions
if you answered example1 you would be
wrong if you answered example2 you’d
also be wrong if however you answered I
don’t know you get a golden star because
we cannot know we need more information
where is context-sensitive we need to
know the context in which this function
is being executed so let me make up some
context that conveniently makes my point
let’s say that you look at it and you
find out that the function in example 2
was used in a
batch processing script that runs one or
two times an hour you also find out that
the array that it’s looking at it’s it
sometimes 500 items sometimes a thousand
items but it doesn’t grow beyond that
and it won’t really grow as the
application load grows it won’t grow
much over time and what if I told you
that the decoding example one once used
in an animation library that did this
operation multiple times per second on
an array that could easily grow to
100,000 items when we look at these two
examples in isolation without knowing
anything about how they’re used I am
tempted to think that the one in example
two s are the the performance villain of
the two it uses for each which is not as
fast as a simple for loop and also
unlike example one it doesn’t stop when
it finds the item it just loops through
the entire array regardless of whether
or not it has found it however if we
find out that this code is just looping
through a few thousand items and is only
doing it a couple of times per hour when
the user isn’t waiting for it
optimizing this does not matter
optimizing it would just be some kind of
academic procrastination it wouldn’t
really add any value it would be me just
moving code around if a friend of mine
and end-user asked me what I did at that
moment I would just be saying like oh
I’m making this faster oh so the
software will be faster uh not for you
but this specific part will be faster
because it will emotion and that will
emotionally make me feel better as a
developer I wouldn’t really add any
benefit to anyone except me if with you
example one and in comparison to example
two here just in isolation without
knowing the context that they are called
looks a lot better in comparison but
when you introduce the context and you
get that oh I need to search 100,000
items per second you realize that this
algorithm it this is not gonna cut it
it’s too slow we need to optimize this
maybe we would create a lookup table for
the items in the array as we add them or
something I don’t know really
that’s not important for this discussion
the important part is that it is the
context in which a function is is being
executed that determines if it’s being
wasteful or not we need to know what
contacts this function is going to get
called from in order to know if it’s
worth the effort to optimize it or not
in summary waste is context-sensitive
just because something looks like waste
does not mean that it is when you see a
piece of code that you’re fast brain
quickly identifies that goo that’s
inefficient always ask yourself a second
time in what context is this code being
called it’s this really hot code is this
really worth optimizing if you liked
this video please share it with a
colleague if you are that colleague you
have your watch an episode of fun fun
function I release this every Monday
morning Oh 800 GMT time don’t miss out
subscribe hi mmm PJ that’s the Twitter
bird ah until next Monday morning stay curious