Programming Throwdown - Node.js
Episode Date: April 6, 2015This show covers Node.js: A server-side platform for developing network applications. Books of the Show Jason: You Can Draw in 30 Days: The Fun, Easy Way to Learn to Draw in One Month or Less... http://amzn.to/1CsrFsO Patrick: Abyss Beyond Dreams (Peter F. Hamilton) http://amzn.to/1NYmqJZ ★ Support this podcast on Patreon ★
Transcript
Discussion (0)
Hosting provided by Host Tornado.
They offer website hosting packages, dedicated servers, and VPS solutions.
HostT.net.
Programming Throwdown, episode 41, Node.js.
Take it away, Patrick.
So recently, the FCC came out with their long-awaited net neutrality ruling,
and they've tried several times to effectively get net neutrality to be able to be enforced
and gotten, I think, this is such a complicated topic.
I feel like you need to be a lawyer to really understand it,
or maybe just someone who knows more lawyeries than me.
So the way I understand it is they tried several times to be able to basically enforce net neutrality
and got told by the courts they couldn't do it that way.
And so their most recent attempt was to do it by saying that broadband is essentially a utility
and that therefore the SEC has the right to be able to regulate it.
But of course, this is interesting because some people are opposing the fact
that the FCC is even getting involved at all.
So people in the tech industry generally support the idea that net neutrality is a good thing, but that it may be bad to have the government
somehow having to defend the rights of the internet in that way, may just be asking for
trouble, that they'll start putting their hands into other things on the internet. And of course,
other people are complaining because of what they had to do by saying that broadband was a utility.
Some people are complaining that's you
know not well i guess it's a that becomes a political right wing versus left wing complaint
about that that's anti-company or uh yeah so some such problem i'm going to try to explain
net neutrality and then you can correct me so i think so net neutrality means so a neutral
internet is one where so okay okay, just step back.
So the way the internet works, right?
You say, I want to go to yahoo.com.
And what happens is your machine, so there's a bunch of machines that resolve Yahoo.com to an IP address.
So those are called domain name service machines.
So you contact one of these domain name service machines.
There's typically one for your ISP.
And you say, okay, what is the address for Yahoo.com?
And they give you a number.
And then you start sending packets to that number and each machine along the way
kind of knows where that packet needs to go and also knows what machines it's connected to
and tries to get the packet a little bit closer to its destination and so there's all of these hops
where you're bouncing from one machine to the other until finally you reach Yahoo.com, one of their front-end machines.
And then they fill that packet.
They create their own packet, which has the Yahoo.com site on it, like a bunch of packets which have that site on it.
And then they send those packets back to you.
But along the way
it bounces through all these machines and a neutral internet is one where all those machines
along the way including your isp just forward the packets without any discrimination
so not like a net like if we didn't have net neutrality then what they could do is they could
say oh you know here's a packet containing netflix movie like a piece of a netflix movie
so i'm going to charge patrick you know that a fraction of a cent for this packet but then if
the packet doesn't have a netflix movie if it has something else maybe it's free um did i does that kind of
explain it or yeah i mean this is where it begins that i the mishmash of not understanding the
politics of it and then the uh you know the peering arrangements is another thing that comes
into play here that uh certain website certain computers send a lot of traffic and others receive it or source it or sync it, I guess, is the equivalent.
Google doesn't generate a lot of traffic, but it receives a lot of traffic.
Wait, really?
Isn't it the other way around?
Well, who's requesting it?
Google.com doesn't ask for a lot of traffic.
Like it doesn't cause traffic to be generated.
It's sending lots of packets in reply.
Like you go to YouTube, right?
So if I go to YouTube, I send a small amount of packets,
but I'm the one that is initiating.
YouTube isn't sending me stuff without me asking.
Oh, I see.
I send YouTube stuff without it asking.
Gotcha.
So you ask youtube
for information and then they just like fill you full of information so yeah i send a small amount
of data and they send a large amount of data back but it matters because the you know who like
essentially they're acting in response to a request from me got it got it so there's something
there too and like so my isp has to uh you, bring in a lot of data and doesn't send out much data.
Right.
But the data it does send out is the cause for all the data that's coming back.
Right.
That makes sense.
Yeah.
So, I mean, you have to do a search to get a result or you have to, you know, click play on a video to start getting the video.
So it's always
your um the causal nature is always you but then the effect is that google or youtube or whoever
just dumps a bunch of data on you um yeah so then the belief is that you know google slash youtube
or facebook or insert any large website should pay because they don't,
you know,
it's their,
their traffic isn't symmetrical,
right?
Like it,
because of this asymmetry that there's some,
there's something there and they're not sharing their fair burden or something
versus a ISP probably also has people who host servers there.
And so they actually are sending out traffic as like they are doing both ways.
Yeah. So their traffic is more balanced. Yeah. I mean, there and so they actually are sending out traffic as like they are doing both ways yeah so their
traffic is more balanced yeah i mean part of it is you know to argue to play devil's advocate
i mean people who argue against net neutrality they say that basically you know there's some
people who consume you know i think netflix consumes like a third of the internet or something like that during peak hours.
And so Netflix has no incentive to be judicious and responsible with their bandwidth because it's basically free. I mean, they might pay their ISP to, you know, push out all of that traffic and have the
infrastructure. But then all of those hops in between, they're just kind of freeloading in a
sense. And so there's this idea that kind of the people who are using all of this traffic and
requiring all this infrastructure should also be financially responsible for it and that was kind of the that's the anti
net neutrality argument the net neutrality argument is like this is very complicated and
difficult to enforce and i mean if there's no i think the net net neutrality is slightly more
subtle is that not that netflix should be more less responsible, but that it doesn't matter if you're Netflix, Facebook or a small startup that they should all pay the same rates.
Right. That's right.
Right. So so you may pay more.
Netflix will pay a lot more than a tiny startup, but the amount they pay divided by the amount of traffic is the same.
Yeah, yeah, you're right. You're right. Sorry, sorry. It's like a subtle nuance, but it matters. traffic is the same yeah yeah you're right you're
right sorry sorry it's like a subtle nuance but it matters yeah that makes sense you're right because
yeah you're right if if you it's like a toll road right like if you have more vehicles in your fleet
going on that toll road you're naturally going to pay more um but uh but everyone gets charged but
you can't say oh your truck is a walmart truck and and I don't like Walmart or Walmart, you know, trucks are worse for my business
in some other way.
And so I want to discriminate against Walmart trucks and make them pay twice as much.
Yeah, exactly.
Yeah.
Um, so yeah, we both kind of, I don't know about you, but I'm kind of foreign at neutrality.
I never really understood the idea of charging different people, different amounts, but amounts but uh i also haven't been keeping too up to date with it so yeah my
opinion is hard because it's yes the idea is good i want the internet to be neutral but like how do
you enforce it who enforces it yeah right this becomes where the problem where it gets sticky
yeah that makes sense so um we have a correction from last
episode episode 40 uh and this is by andy andy wrote into us to say that we've made a mistake
no i was giving you time to recover from passing out first time ever
i'm okay yes first time ever uh so we were we were ranting about pre-verse post increment
and we weren't being very careful or i wasn't at least being very careful in how i was stating it
and saying that it kind of doesn't make a difference and how i prefer doing post increment
in like a for loop for instance because that's the way i was taught um and it does actually matter a lot and especially in the case where you have
like classes in c plus plus not basic native data types because doing the post increment requires a
copy operator because it needs to invoke use the before value and the after value
so it needs two copies of the object which does
add overhead and so you have to be careful when you're using post increment that you really need
it and that there is could potentially be a non-trivial cost to it yeah especially with with
iterators yeah i mean if you're using it with an int the compiler will probably just optimize it
for you but yeah that was my well integral type there we go that was the word i was i'm yeah
primitive type or a primitive integral type right something that is kind of native like i don't i
don't know that it makes a big difference but to be fair it's better to adopt a habit that's
good for everything than try to remember the nuances yeah that makes sense makes sense so
i stand corrected all right should have been more specific first time ever we can make a mistake once
um news so this is total cop-out news but uh i'm really proud of this excited about it but uh
i made a wiki a wiki engine um So basically, you know, there's Wikipedia.
Sorry, they're not Wikipedia.
There's MediaWiki, which Wikipedia is based on.
There's Twiki, and there's a couple others that kind of dominate the wiki engine market or space,
mind share, if you will.
And these are good, for like public environments um
but they don't really they never really worked well for corporate environments um you'd always
see people like try to have a meeting uh on wikipedia like try not wikipedia but try to have
like uh like meeting notes in a wiki and then you then two people can't edit it at the same time.
Most of them don't allow that collaborative editing.
Also it's too hard.
If you see a typo in a wiki, like in your internal wiki, it's such a huge pain in the
butt.
You have to click edit, you have to go find the typo in the markup language, correct it,
then click save, and each time it's like a page load, so it's maybe like five seconds.
So it takes probably 30 seconds to fix a typo in a normal wiki.
And so what ends up happening is as code is evolving and processes are changing quickly,
people are just not keeping the wiki up to date.
So I created a wiki where it's very simple to update and it's collaborative so um it's uh node.js and uh javascript on the
browser i'm talking about this i know spoiler and uh mongo db for the database so if you can get
mongo db and node.js, you're good to go. And
everyone on Twitch saw that Angry YOLO is following me on Twitch. Thank you, Angry YOLO
for the follow. Anyway, so if you have all of that, not too bad. You can get it set up on Heroku
or something pretty easily. And you can get this wiki I've been running. It's pretty cool.
When you go into edit mode, it turns into like this Google Doc thing
where like several people can edit at the same time.
So if you have like a meeting,
one person can project the wiki
and everyone else could be editing the wiki
and kind of filling things in or making corrections
and it just kind of naturally works.
And then it's also permanent,
has a full text search and things like that.
So I think it's pretty cool.
Give it a shot.
Let me know what you think.
If you hate your wiki at your company or you haven't started one yet, try this one.
And yeah, let me know how it goes.
Very nice.
I really want to run this and try this, but yeah, we have other things we use and so i'm not sure
it'll go over that well at my company so i'll say i'll do it my spare time yeah you could always
ping somebody and say uh you can run the demo i'll actually change the link this is we need
to talk about software as a service you need to offer this as a service uh i could totally do that
but i don't know.
The thing is, is like most companies are kind of private about their data.
Yeah.
So, but yeah, check this out.
It's a little demo and you can go and edit it.
And I have no friends, so I wouldn't ever be able to see anyone editing it with me.
All right.
I'm just being sad okay my link of the week or link of the week oh man my link to talk
about is the 8cc small c compiler so i ran across this the other day in a news story
and that was interesting because i'm constantly wanting to learn more about kind of compilers
and compiler theory it's one of those things i think uh everyone i don't know maybe not everyone
but i feel like many people in computer science or doing software engineering get interested in
compilers at some level but everyone kind of just has this belief and to be honest i've never looked
at the gcc code so i have no idea how complex it is but i've heard it's really complex and i just
assume it must be really complex yeah same here so i but i've never to be fair i've never looked at it so
i don't know that's a bad assumption it's got to be just total nightmare though i've heard that i
heard that but i i you know i've never looked so i can't say and then there's things like clang llvm
which are you know part of uh their goal is to kind of clean that up right anyways leave all
that aside 8cc is just a compiler for the c language trying
to support all the modern c11 language features um but it also has a goal to be very readable
and simple and small um so i don't think they're trying to be the most optimal one but they are
trying to be uh complete like not implement a c subset but actually implement all of the c language
um and so i was reading through a little bits of the code just to check out.
And I have it on my infinite to-do list to go through this and kind of really
read through a lot of it.
But the parts I read through were like,
oh, I know what this is doing.
Wow, cool.
But I need to kind of get more into the understanding
how it's hooked up and how it flows.
So here's something parsing an abstract syntax tree node.
OK, I can follow kind of what it's doing. But an abstract syntax tree node okay i can follow
kind of what it's doing but how is the tree built where does it go to you know those kind of stuff
i didn't get into but if you're interested i would check it out um and they have some links
to other projects that are similar that may be of use as well yeah this would be totally awesome
i've always wanted to do uh things like uh i had this one crazy idea.
Oh yeah, like if you could turn
C code. There was this project
GCC XML
that turned C into XML
so that you could do crazy things like
like kind of
automatically delete all the comments
and things like that.
And yeah, this would be
good to read just to see if you could do like
kind of these front-end things or like you want to add that one feature to see
that no one will let you did no one ever seems to want to support yeah yeah cool
man it's awesome all right my news is our link I guess is tote 50 totally free
lessons in graphic design theory is Is this BuzzFeed?
No.
No. So I'm totally interested in
graphic design. I've been doing a lot of drawing
in my spare time.
And I've been really interested in
sort of like the psychology behind
it. Like there's all these rules, you know,
like the don't put something in the
middle of the page.
You know, the golden rule. It's like the two-thirds something in the middle of the page uh you know the golden rule
it's like the two-thirds rule all these things but uh you know i wanted to see something like
a little bit more formal that tries to like codify them or at least explain like the intuitions
behind them and things like that and so uh yeah i've been going through a bunch of these and some
other resources and uh try and do a lot of drawing and things like that.
And this was one of the ones I found particularly useful.
So if you're interested in that kind of stuff, if you're building a website, drawing a picture, any of that kind of stuff, this will help.
It's a very broad kind of topic in graphic design.
So check it out.
I have comments about this, but I'm going to save them for later.
Okay. Because I think we'll talk more about this topic soon really okay dude okay never mind all
right yeah we'll just have to wait and see um my next link is uh open gl from zero to hero
sounds like something i need to read um and this is are you doing open gl like is
is that uh thing of yours now no oh okay you just want to read it because it's cool yeah i don't
know it's game graphics i don't know always it's always interesting to me i do do graphic stuff
sometimes i wonder how many people uh got into computer science to make video games i bet it's probably 50 i have very low
desire to make a full-fledged video game but i have more like demo scene inclinations but i want
to like make like demo of like some cool thing and just like you know just play around like toy
programs but with graphics yeah that's the thing i don't want to make the content but i just want
same as you i just want to make something that's kind of cool but yeah i don't want to spend the time like
writing the story and all that stuff yeah that's for people who have more time than i have um
or it's their job uh but this is a series of tutorials um that it looks like there's going
to be more but even the parts they have now take you from the parts i always find really difficult
like getting open gl set up or even installed in this case in like visual
studio,
even,
um,
which can sometimes be harrowing experience,
um,
to how do you draw a triangle,
you know,
shading the triangle.
And then it goes into a basic parts of a game engine and like,
you know,
shaders and scene managing and all these things and how they fit in.
Uh,
and I didn't go through the whole tutorial,
but the parts I clicked through, through seemed really interesting and on point.
And so if you're interested in it, check it out.
And like I said, it's probably most people
because I think a lot of people have this thing in the back of their head
that one day they're going to make some awesome video game
or OpenGL 3D thing.
Cool, man. Yeah, that's awesome.
Yeah, now there's like a a ton of these well we talked
about unity actually that's right yeah we did but uh but still like you know a lot of the if you
want to do something kind of really out there and like the coolest you know one man video games or
like you know indie video games are the ones that have some crazy kind of mechanic which is very
hard to get right with one
of these high level things like minecraft for example you can't write minecraft in unity you
have to do something kind of low level right and so uh it's really important to know open gl and
the fundamentals yeah for me it's more like to and it sounds i guess it's kind of weird maybe it's i
don't know what how you phrase that but uh the fact that, okay, you go to some tutorial,
like how to make an Android app,
but then they actually don't do any of the interesting parts.
It's just like you take some framework
and then you like edit some XML and then like,
okay, you have a Android app with a button.
Okay, but like, that's not what I wanted to learn.
Like I wanted to do something, you know,
like I want a framework to get me almost there,
but then I can do the interesting parts. So like for me, you know, like I want a framework to get me almost there, but then I can do the interesting part.
So like for me, you know, things like Unity, if you're going to actually try to make a game is really good.
But if you're just trying to like play around, sometimes it hides what maybe the parts that are interesting to you.
And in my case that, you know, that would be kind of the lower level stuff of, you know, actually rendering the graphics.
Yeah, yeah, that makes sense.
But maybe I'm a strange kind of weird person. yeah well yeah that's a given but given all of that the
other stuff you said makes sense yes time for book of the show book of the show my book of the show
is you can draw in 30 days the fun easy way to learn to draw in one month or less.
So I have to confess I haven't read this yet, but I have ordered it.
I love drawing, but I'm not great at it.
I'm good at doing, like, I'm good at being kind of a perfectionist in the sense of, like, making sure, like, you know, like, spending a lot of time on it until it kind of looks good.
But then like, I feel like the people
who are really good at drawing
are the ones who can like,
they have a certain tolerance for quality.
And then within that tolerance,
they can just generate a lot.
Like for example, it's the same as writing code, right?
Like the code that I write on a day-to-day basis like might not
be the cleanest code ever i mean i'm sure if i spent more time i could write better like cleaner
code but i can write a lot of it in a day like i have like sort of a well-oiled machine uh where
i just like can kind of churn out a bunch of code um and so that's what a good artist can do a good artist might not be
as perfect
as he wants or as he can be
but
he can get 90% of the way there
in one tenth of the time
that it takes me to get
to get there, to get done
so yeah
I'm trying to read through these books
especially the ones on doing things quickly and i'll let you guys know how this goes but uh
um but yeah i'm looking forward to getting in taking a look through so i'm a little up on you
i'm like seven days into this book uh really you actually have this book yes um so this was saying
i was going to talk about this later and you just had this like blank
sound and I was like okay
what are the odds that we both have the same
book
so
everything you're describing except for
the fact that I can't draw even if I take a long time
so I'm
just terrible at it so I got
the roundabout story is there's this thing
called urban sketching I don't know if you ever checked this out.
There's a website, Urban Sketchers, if you search it.
And they have like a very particular art style, which is exactly describing is exactly described by the words you were using, where the idea of urban sketching is you're out in the world like you're sitting on a bench.
You're in a Starbucks and you're drawing fast.
You're drawing just something that you're seeing and you can't take forever
you can't be a perfectionist you're not making a gallery piece you're making
something very loose but I'm just something so the style I've learned is
kind of call it the ink and wash style so you kind of like draw with a pen and
then they'd use some splatterings of color from watercolor and this is kind
of like a very specific style that they're they they tend to be very similar a
lot of them and this is cool that this is like got me into i wanted to do this i didn't know why but
like that style just stuck with me and like this quick loose drawing yeah it's fun uh and so i got
in a series of weird tangents uh so i now actually i i kind of gave up the drawing a little except
then i've come back to it because uh actually got into watercolor painting and so now i've been doing watercolor painting for about
uh two or three weeks now and uh um it's been really interesting and so i've learned to need
to draw again because you need to draw to be able to paint so blah blah blah so i'm back and and
working on drawing again and i hadn't painted since like elementary school so i don't know
however many years that is, many years.
And so I got stuff like just doing it.
And it was actually like, wow, this is really like relaxing.
I don't know what about so different than coding it is,
but I was really, really been enjoying it.
So like I never really thought to do watercolor.
Like I have pencil crayons and then I have, you know, like drafting pencils.
But like what made you think to do watercolor specifically the urban sketching stuff oh so these are all watercolor
you're saying so the color you see there is almost universally watercolor yeah oh and then they add
the they do pencil drawing on top of it no no well so there's two ways one is like you spill
some color across the page and then you just draw something on top of it for like effect but then others are where you draw a sketch uh in pencil or pen and then you kind of just like
loosely color parts of it in water oh i see got it and the reason watercolor there is because it
dries much faster than like a lot of the other kind of paints and it's much more portable because
you can have the dried pucks and a little you know cup of water and you can be able to paint
yeah yeah oh that's awesome yeah so now i've been doing like a little bit of watercolor stuff uh i
won't say i'm great but i'm doing better than i thought i would be able to i can paint things
that you can recognize wow that's awesome and so that's made me happy so and there's turns out
there's tons and tons of videos on youtube about how to do like any of this kind of stuff so and i find it easier than drawing with a pencil because i feel
like by nature the painting and specifically watercolor is very loose in nature so you can
paint precisely but it wants to kind of run all over the page and so it forces you to be more
interpretive which is something that i don't do by nature oh i see yeah that's that's my like
flaw too is like if if something doesn't look realistic like if it if it doesn't match and i
like have to fix it and so certain things like which are kind of there's certain things that
are just always kind of drawn comically like for example like the fur of a tiger, like the outside, like the border between a tiger and whatever is behind the tiger.
Like to actually draw that correctly is just insanely hard.
But, you know, so like to draw it the way that you would see it, like the iconic drawing of a tiger is like kind of more abstract.
And I think that's where I have the most trouble.
Yeah, to your point earlier,
I don't know if you guys check out,
anyone, guys or gals listening,
check out like this urban sketching.
To me, what you were saying earlier
about kind of psychological almost,
how that you can recognize something to be a person
when it's almost just like a couple loop squiggles
and like hashy lines and a little bit of paint
and you'll be like oh right like here there's a picture i'm looking right now like a picture of
a marching band and it's like i can tell this is like a marching band and like but like there's so
little detail here it's kind of crazy that i'm able to tell that that's what this is and then
i can actually tell this is almost looks like a saint patrick's day whatever like but i don't know why i'm able to tell that like yeah it's just mind-boggling so yeah yeah learn to draw yeah but i i did enjoy the book i kind
of put it back down because i started doing the watercoloring stuff but uh yeah i was enjoying
it so far so i'll recommend it cool but you have to stick with it it's practice people just think
like i'm gonna sit down and just draw but that't happen. Like it's just very hard for your,
even if you know in your head what you want to draw,
your hand won't be able to do it initially.
Yeah.
I see what you're saying.
So it takes more practice than I,
everybody just chalks it up to talent.
I did too.
And so,
yeah,
my book is completely unrelated.
It's a science fiction.
Go surprise. Patrick's recommending a science fiction book. Wow. I didn't it's a science fiction go surprise patrick's recommending
a science fiction book wow i didn't know you read science fiction i only talk about a science
fiction book or fantasy every single episode this one is a book that was released last fall
abyss beyond dreams this is uh peter f hamilton's newest entry in the commonwealth saga of which i believe there are five or six books now um and uh i guess
this would be like the seventh uh and i really enjoy his style i was really hoping this book
was gonna have uh so he writes about kind of crazy future science and it's i guess considered
hard sci-fi and a lot about how humans modify themselves in the future. And there is a good amount of it in here,
but not as much as I was hoping.
But it's still a really good story.
I really enjoyed it.
So I would recommend that, Abyss Beyond Dreams
or any of Peter F. Hamilton's Commonwealth Saga books.
I don't know that you really,
there's two books and then a trilogy
and now this one, which is set in between the previous.
So I wouldn't read any in the sets out of order, but i think you can read any of the sets in either in any order
cool that makes sense that was confusing anyways check it out it made sense
so on our oh go ahead oh no i was gonna say on a related note of books terry pratchett just passed away like a week ago um yeah and so he had uh alzheimer's
um and for for a while and so he was kind of fading but uh but yeah he passed away about a
week ago and uh yeah the world will miss terry pratchett disc world series uh we've had at least
one i know or maybe two um books that's books of the show which are books he wrote
among other stuff
there was this pretty epic image
that someone hand drew of him
shaking hands with death
I can't seem to find it though
yes which is one of the characters in his Discworld series
oh yeah that's right
he's shaking hands with one of his most famous characters
let me see if I can pull it up i think also his i believe this is i want to say his
daughter uh when she tweeted that he died also made a reference to his death character
oh really nice so um i was gonna say the secret to me being able to listen to this uh bis beyond
dreams is another uh quite long science fiction book,
as many of mine are,
because I have quite a long commute.
And the way I'm able to do that
is by listening to audiobooks.
And this week we have an announcement
that we now have Audible
as one of our sponsors of the show.
That's right.
So you can go to audibletrial.com
slash programming throwdown. And they have an offer where you can get to audibletrial.com slash programming throwdown.
And they have an offer where you can get a free month, which is Audible Works.
You can either just buy the audio books kind of like for a flat fee, or you can pay a subscription per month.
I believe it's $15.
And then you're able to download one book a month, essentially.
And they have plans that have more books a month.
And then you can keep them even if you cancel your subscription.
So what I do is I have a subscription for a little while,
get a couple books built up, and then I cancel my subscription.
And then when I make it through those books, I get it again
because the subscription works out to be cheaper
than just buying them directly off of their thing.
And they also run great sales.
As long as you're disciplined to get a book every month,
then you can just continue to build up a queue of books.
Oh, and you get a credit, and a credit is good for a book.
And the credits don't expire until you cancel.
So you can let them build up and then use them all at once and then cancel.
Oh, cool, cool, cool.
Yeah, yeah.
So they're pretty good about that.
I've actually been pleased.
And then I'm able to listen to it for however long, you know, after I've canceled.
And then while you have the subscription, they also run sales, which are even cheaper.
Or they also run deals where if you buy the Kindle version of the book and the Audible version of the book,
sometimes it's cheaper than just buying the Audible version of the book.
And so I do that sometimes so you can get a lot of good listening
material slash reading material um for a pretty decent price i feel like it's a good deal and so
i'm glad that we can uh now have them on our show yeah definitely so yeah if you uh if you use the
link that we'll provide in the blog then uh then that helps us out so we appreciate it about the
show and check it out and if if you're always saying, man,
I really wish I had more time to read, uh,
and you're in your car or in a long commute, you first,
you can listen to this podcast and then you can listen.
That's right. Oh man. Are we, are we, uh, encouraging our competition?
I listened to both podcasts and a fiction books so yeah yeah there's
definitely enough time for that i do the same thing i listen to uh i listen well i listen to
just podcasts but i have like a ton of podcast like five different podcasts only five of my
community more than five much longer than yours okay fair enough um cool so to the tools of the show my tool of the show is jacoco which is a java code
coverage library so what this means you integrate it into your test environment well specifically
integrate into your build system so if you're using you know maven or ant or Gradle or any of these things you integrate jacoco into one of those and
then whenever you run your tests this will actually tell you what lines of
code are covered in your unit tests and which ones aren't and so it's pretty
cool like it'll give you a high level overview,
like 6% or 70% of your project is unit tested.
Only 70%?
70% of the lines.
Boo.
Yeah.
But then you can drill in and say,
oh, I totally missed this class.
You can exclude some classes,
like if it's just like a main loop or
something like void main or whatever just in its own class you don't want to unit test it
so it has a bunch of options like that um it's pretty slick um i've been using it for not too
long just a week or so but uh but it's pretty cool and uh it really kind of helps you to reduce
the entropy like like if there's some code that's not unit tested,
maybe it doesn't need to be there, right?
And so it kind of can really help improve the code quality.
What do you have as your code coverage target?
I don't know yet.
So I ran this.
So basically what happened is we had this kind of i don't want
to use the word sprint because that reminds me of agile and all that those things that i kind of hate
but uh but we had just we had just sort of a rush where we had a deadline that we were rushing to
meet and we were able to meet the deadline but i mean we were here at the 11th hour just banging out a ton of code.
And so the code coverage is really bad.
Really, really bad.
In fact, we hadn't even started writing unit tests until this week.
So the code coverage was zero.
Nice.
So I have to, you know, I don't really have a set target, like a certain percent.
It's more just like I want us to write unit tests until, until things look good. You know, until like,
we're happy with it. And then I'll try to figure out, it's hard for me to have a target when I've never really done this before. No, that's fine. Just some, some teams have like a, you know,
like 90% is the desired goal or 100%, which can be very difficult.
Yeah, I mean, I'm assuming if your goal is 100%, then you're excluding like void main or whatever.
I mean, you could test it, but at that point, you're just kind of wasting time, right?
Yeah, I mean, but you could get to essentially 99.99999 percent yeah
right and then that doesn't even get into talking about branch coverage yeah yeah that's right which
is not just every line of code but each path so if there's multiple ways to get into a if statement
you exercise all the permutations yep yeah that's much much harder yeah that's
brutal man okay my tool of the show is relatively limited but i've been using a lot and thinking
about it anyways and that's think or swim so think or swim used to be a uh a stock platform
that was its own uh investment company but now it's part of a brokerage called
td ameritrade and it's one of the options for interfacing with it and so i have some stock
investments uh with td ameritrade and i've been using thinkorswim um but i really want to just
use an opportunity first of all say i actually do like the interface and i almost exclusively do it
from the phone so i don't do do tons of like really stock trading.
It's more just investing.
But I do it like exclusively from my phone and my tablet.
I don't go on the website except to create the account.
Like I manage everything from like on the go
whenever I have a, you know,
like some money gets auto deposited
and I want to invest it in a, you know,
indexed ETF or whatever.
I just handle it,
you know,
wherever I am.
And I just think it's kind of crazy to think that would have been me
phoning some guy sitting behind a desk to execute an order.
Not even what,
like five years ago.
And now I just do it from like a tablet or my mobile phone.
The trade prices are reasonable.
And there's ways to get even better deals than what they have posted.
Not me endorsing TD Ameritrade, but just saying.
So what are the fees?
It slips my mind now.
I think it's $5 for a stock trade.
Oh, that's better than E-Trade.
E-Trade's $10.
So I have like a special, like I said i said if you shop around there's like other ways
like referral links basically where gotcha you have to refer me hook me up so so yeah so like
i'm not specifically like far be it from me to uh give investment advice although i'll tell you my
opinions oh no we will never we will uh yeah let's not get in there yeah yeah so but um i'm just saying like
for me it's just about that this specific one think of someone i really like the way it's
designed and the way it operates and uh also i think it's just crazy that we can do this now
that like i don't have to even be on my laptop or yet much less the phone which i hate uh calling
people um and so instead instead this is amazing like you
can just oh you can just like take your phone out of your pocket and say oh look i think this looks
pretty interesting yeah i'm sitting here like you know waiting for a doctor's appointment or
something and you just have some time to uh study your financial situation yeah and it really takes
away like the like procrastination ability because it's like oh well this weekend
i'll get on and i'll oh but the market's closed i'll wait till i'll set up or you know whatever
blah blah you just do it uh so it's seven dollars is my rate for flat stock oh okay yeah you'll have
to add me under do it okay all right all right i like how they're uh they're one of their bullet points here is they add zing to my ding ding.
Oh, I think that's because it's the noise it makes when you execute a trade.
Oh, okay.
Okay.
Well, I mean, who doesn't want that?
Yeah.
Anyway, so the only thing you got to be careful with all these things is there's a incentive to
try to make you trade more and i'm a firm believer that i think trading more just gets you into more
trouble oh yeah i don't yeah yeah can you do like uh can you schedule things in advance
so you can set like a good to cancel order so yeah so like a good to cancel limit order like
i want to buy tesla at this amount or this etf at this amount and i want
it to be good until i cancel it well can you do like like say i want to buy tesla you know the
15th of every month oh i don't know kind of stuff i've i haven't tried doing that it's possible
there's a lot of really like crazy stuff in the program so okay uh so yeah more not an endorsement
to to trade or not you heard it from us by tesla don't
you don't do that but the amazing moving of also the other one a lot of people use what is that
called uh oh why is the name skip interactive brokers interactive brokers is another one people
recommend a lot that's i guess relatively low cost um and and they also have a mobile one that
i've used and i was gonna, Thinkorswim also,
even if you don't open an account,
they have like the paper trading one.
And if you're just into like stock trade,
like checking stock charts and stock prices,
I think it's 20 minute delayed
if you don't have an account.
But for most people, that shouldn't be a big problem.
I don't, anyways.
And so that just even using it to check stock prices
and stuff, I find it to be a useful application.
Cool. So it works on the phone or the iPad or both or i don't know if it's on android but for sure i
have it on my iphone and my ipad and they're both beautiful and nice and i like them very cool so
that was way too many caveats for a tool of the show moving on time for node.js. Node.js. So, yeah, so Node.js is pretty cool.
So we talked about Node.js very briefly when we covered JavaScript a long time ago.
I don't remember what episode that was.
But at the time, you know, to confess, neither of us had ever, you know,
written any, you know, big projects or anything like that in Node.
And since then, Node has come a long way.
We've come a long way in terms of what we code day to day.
And so we have a lot more to say about Node.js.
It's pretty cool.
The basic premise of Node.js is that JavaScript
is the language of the browser.
So if you want to do something interactive on the browser, you're almost certainly going to have to write it in JavaScript.
And Node.js is a JavaScript-based engine for desktops.
And so it's kind of nice because you can stay to just one language. And we'll talk about that more later
why that's convenient.
Yeah, so to give the
one-line summary, because sometimes it's frustrating to
figure out what something really does, this is basically
to allow you to run JavaScript not
in your browser.
That's right. Think of it as like a command
line JavaScript engine, right?
Yes. It took me a while to actually
figure out what it was
supposed to be nice not not for this episode but when i first heard about it yeah right right
um do you want to cover some of the history sure so uh in node.js like we said is a javascript uh
engine to run on a pc outside of a browser and uh the thing that led to its development was that in
2008 uh google released the v8 javascript engine which is what they use for executing javascript
inside of google chrome but they released it as a standalone so you could kind of compile
javascript and run it and in 2009 um ryan doll workingent, which is a cloud services company.
And so he released this thing called Node.js onto the scene, which was essentially kind of like a framework,
encapsulation of VA inside of it in a platform to allow you to even more easily run,
essentially, JavaScript programs as if they were almost native executables, as it were.
Yeah, like what Node.js does is it connects job because you know like javascript ran on the command line with the v8 but it didn't have access to the os like someone had to go in
and write the read a file function or the send a byte over the network you know well actually i
guess that one's in javascript but like like the read a file function or the send a byte over the network, you know, well, actually, I guess that one's in JavaScript,
but like the read a file function
or the control your mouse function
or the read from the keyboard function,
like these low level, you know,
C operating system functions,
someone had to connect them to the JavaScript engine.
And that's what Ryan Dahl did with Node.
Yeah, so some of the pros so one pretty cool thing about this is it's it's all JavaScript which is pretty cool
JavaScript is weakly typed if you remember from the episode so what that
means is the advantage of that is basically in JavaScript,
everything is either a dictionary or an array or a primitive, like a string or a number.
So everything's a bunch of dictionaries and arrays.
You have dictionaries of arrays, so on and so forth.
And then that maps very well to JSON, which is not a coincidence.
It's called JavaScript Object Notation.
And so JSON is a, you can think of it as like a serialized form of a JavaScript object.
So you can take some JavaScript object, maybe it's a dictionary, and it has a key called user, and the value is someone's name, and it has a key called friends, and the value is some list of friends' names.
And you can have this JavaScript object and say user.name, printuser.name, printuser.friends.
And then you can say, hey, take this object and turn it into a JSON string now once it's a string you can you know send it across
the network you can serialize it to disk you do whatever you want and then at any
point you can say JSON dot parse and it turns your string back into a JavaScript
object where you can like run functions on it and stuff like that.
So this is pretty cool, right?
Cause you see how this is going.
Like you could be on the browser writing
what's your JavaScript and you can say,
hey, take these objects and turn them into strings.
Then send them to the server.
The server's running node JS.
It says, hey, take these strings,
turn them back into objects and then just start accessing.
I'm just like like you know keep resume
where i left off um um doing the server side um this is especially useful for validation right
so right now a lot of people don't know this but if you go in your browser and like you try to log
into your bank or something and you don't put a password you just hit enter or you put
the wrong password like your bank like or if you put a if you put no password
it won't even let you log in like before you even go to click the login button
like the password box will turn red or maybe like right when you click
immediately it'll turn red and your browser will just tell you look dude you
didn't put a password this isn't gonna to work right um and so or you know if you if you try to sign up on a
website and it says put in your email address and you put a and you hit enter or even before you
hit enter it might say look that's not a is not an email address it's not going to work right
but that validation that's happening on the browser, it's impossible to enforce.
I could always go in and hack the JavaScript on any website I want on the browser side to let me make my email B and A.
But that's why you have to duplicate it.
So on the browser, on the client side, you check just to keep things easy and keep the flow going and make it convenient.
But then when you hit the server, you have to check again to make sure that someone isn't
trying to be malicious or have a broken browser or something.
And so if you're going to be checking twice, it'd be pretty cool if you could reuse the
same code that does the checking.
And so Node.js gives you that.
So you write the validation code in JavaScript once,
and then you can use it on the client and on the server. And you know it's going to work exactly
the same. Like, you're not going to type some email address that the browser thinks is okay,
but then the server doesn't think is okay. So, yes, especially for validation, but also for other
reasons, Node.js is pretty awesome, especially for a front-end.
It also has some great MVC frameworks.
That's Model View Controller frameworks.
I personally prefer Express.
I think Express is pretty awesome.
There's also a bunch of other ones.
But basically what these do is they just make your life easier.
If you want to get a website up and running quickly,
you need things like templating,
you need to compile your CSS,
you need to have a model, right?
So you need to connect it to a database
and express, you know, handle login authentication.
Express does all of these things for you
and it just makes it super easy.
Another pro is that um all the
blocking calls in node.js aren't really that would normally be blocking aren't really allowed to block
they are handled with a callback and so this keeps your code um able to scale a little bit better
um so normally you know what the way we work is like if you have a server and a request comes
in to initiate a connection, you
would spawn a thread to service that
connection during the life of that connection.
But this is fraught with all
sorts of resource problems
in the number of simultaneous requests you can
handle. Versus in Node,
Node.js, the concept is
that when that request comes in
and you do some work and then you're waiting, for instance, for.js, the concept is that when that request comes in and you do some work and then
you're waiting, for instance, for a response, instead of having a thread there, it goes and
does something else. And when the server itself, the Node.js framework understands that the response
has come in, it'll kind of call the callback you registered and then stuff can progress.
And that way it can juggle a lot more simultaneous things happening at once.
Mm-hmm. Yep.
So, yeah, some of the cons, it's weakly typed.
So you could push bad code, right?
I mean, unless you're doing your own sort of type checking with some kind of other library,
like unless you're using TypeScript or something like that,
which we talked about in another episode.
Some people would say this is a pro really i i mean this is a javascript thing right like a lot of people i don't say they really like it but i mean there's always this thing
that yeah i don't know yeah so to pat right, the whole, like, being able to go from the JSON string
to the object and back only exists because it's weakly typed,
and we called that a pro.
So, like, one of the pros that we even mentioned
wouldn't have been possible if it wasn't for this con, right?
But at the end of the day, like, you can get burned by this, right?
So it's like anything
there's no there's no silver bullet uh we wouldn't be on our 41th 41st episode 41 that's our second
mistake ever we wouldn't be on our 41st episode if uh if if there was just one language as a silver
bullet right but i mean it's free for something it's fine for something to be a pro and a con but yeah yeah right but being legally typed i've definitely
gotten burned by it um and one other thing about node.js in particular and i don't know why i think
actually you can configure it to be differently to be different but by default if if any of your web service requests crash, the entire server crashes and is just gone.
So in other words, if you have what's called a query of death, which means there is some particular use case that can cause your server to crash. Like for example, let's say you divide by the number of characters that someone put in an
input box and someone puts it empty and you don't check for empty. And so when they hit submit,
if they didn't fill in a box under those conditions, you divide by zero and bomb out,
right? In Node.js, if you do that, like if you have a million people hitting your website and one person does that,
it kills the website for everybody.
So it's kind of got this thing where it's weekly typed,
it's easy to get kind of runtime errors,
and when you do, they're totally catastrophic.
I do think there are ways to fix it,
such that if it bombs out, it's only for that session session that's kind of like how Java and some of these other
servers work but by default it doesn't do that and so that's one thing to be
aware of so we also said that a pro was the asynchronous nature and how that
sometimes can help performance but now we're gonna have two cons in a row that
talk about some of the possible problems with it and the first is that uh you can end up with just crazy amounts of callbacks nested
inside of each other because every time you want to try to do something that would be blocking
you need to come up with a callback and unless you're disciplined as a programmer
you can end up with just code that is a nightmare to read and follow and trace and see where problems are occurring.
And you have to be really diligent to avoid that.
Yeah, and I mean, in some languages, like Java, for example, like most things are synchronous,
but then you can do things asynchronously.
Like in Java, for example, you could have a class that implements runnable,
and you could just call
the dot run function and synchronously run that class or you could spin off a thread or assign it
to a thread pool and then it'll run asynchronously right but here it's fixed so that's why like if
you look at the node.js api there's read file read synchronous, you know, there's a bunch of these, like for almost
any function, there's a synchronous version of it. And that's because there's no way in the language
for you to handle both cases without duplicating all of your code. And so what ends up happening
is most people just write the asynchronous version of everything. and then you end up with just every single function has a callback and it gets pretty ugly yeah cuz you know
most of the time you can be really thin and so it ends up being oh man why is the
name escaping me anonymous callback which is also very difficult so it's
just kind of like right there in line yeah right right um another con is performance um it's so it's
interpreted you know as you guys know interpreted languages are naturally kind of slower so
you're not going to use this for doing some heavy image processing and things like that
um it does have a lot of great support for libraries, like ImageMagick and things like that. It has a lot of C and C++ libraries that it wraps
that you'd use for something like that.
But by default, you're not going to do anything
that does any signal processing or anything like that in Node.
It's also single-threaded, which is kind of wild, right?
You'd build a server where it only runs on one thread.
But as Patrick said, because of its asynchronous nature,
it's just that one thread is busy all the time.
Whereas in other languages,
that thread might be just blocked on disk IO
or it's blocked on waiting for a network packet
or something like that.
But in Node, everything is so asynchronous
that that thread is always doing something useful.
Like if you're reading from a file,
then there's some callback that gets fired when it's done.
And in the meantime, something else is happening.
So yeah, that's Node.js.
I'm a big fan.
I think it's awesome.
I think if you want to get a website up and running quickly this is the way to do it but it has a
lot of great frameworks and things like that too for building professional
professional stuff so I do think if you want to do something more sophisticated
like write some kind of game server or something you could still
use this but then this node.js would be kind of your front end it's like you'd have your browser
you'd have node.js that talks directly to the browser and then it would write information to
a database then you'd have some other program in java or something that's you know maybe pulling
that database and
then doing the more like heavy duty work right like i don't think you would want to write some
very complicated um you know project in this so this is mainly meant to be pretty lightweight
so although i think people do write complicated things like uh uber i believe uh writes their view that shows like where all the
uber cabs are in a given city they track out using node.js oh yeah that makes sense so for things like
if it's complicated in the sense like it's a lot of data and things like that node.js works well
but like for example like the routing like routing the cars i'm pretty sure that uber has something
in c++ i just remember hearing anecdotally one time talking about like large users of node.js
yeah right you can definitely scale node.js very well so i did talk about the single threaded but
of course you can have multiple processes right so you have, instead of one Node.js server per machine,
you could have 1,000 per machine,
or you could have the number of threads times two per machine,
and then you're maxing out, you know, that machine
just as you would with a single Java server, right?
So, yeah, you could definitely scale it up,
but with the weakly typed and other things, you know, you definitely wouldn scale it up. But with the weekly typed and other things,
you definitely wouldn't want to do machine learning
or something like that in Node.js.
It would kind of be a nightmare.
All right, well, I think that's a wrap for Node.js.
Yeah, check it out.
It's really awesome.
A lot of people say, how do I get started in programming?
And there's basically two pieces of
two paths you can go like one assembly brutal one is like most people want either make a game in
which case you could get started with you know all the things we talked about on the game engines
episode or make a website and if you're of the latter kind and you want to make a website
i definitely recommend
using this it's pretty slick html blink tags for the um oh god yeah and yeah everything should be
blinking everything everything the entire document always always um so yeah this is pretty cool so
well a couple things to mention one uh in the past like four or five months,
the bandwidth has doubled, which is pretty awesome.
It means that there's a lot of people following the podcast.
Oh, that's why we're concerned about net neutrality.
Yeah, that's right.
We're the beneficiary of net neutrality.
Yeah, we're using, I don't remember what the number is,
like three terabytes or something, like two and a half terabytes.
We're using like a ton of bandwidth per month, but it's great because it's a service that a lot of people are taking advantage of.
And so we appreciate you guys.
So there are a lot of new listeners out there, but they may be listening to old episodes.
But if you're listening to the new episodes, welcome.
That's right.
And you made it all the way through your first one.
By the time you hear this, you're already a veteran and it's wasted.
It's sort of like a paradox.
But if you are listening to the first time and you get to this episode
or you're going backwards or something,
we have the Facebook page for Programming Throwdown.
We have the Google Plus page.
Sorry, the Google Plus community. We're on Twitter.
We have the Neural Nets for Life Twitter handle. And so, you know, stay in touch with us,
communicate with us. We definitely, if we get some user mail, someone asked me about unit tests.
So my tool of the show, not coincidentally, was a unit test tool.
So if you have any feedback or anything like that, anything you want to ask,
don't hesitate to ping us on those forums or send us an email.
That was very well said.
You've done this 41 times.
You're a pro.
All right, until next time. Cool. See're a pro. All right.
Till next time.
Cool.
See you guys later.
The intro music is Axo by Binar Pilot.
Programming Throwdown is distributed under a Creative Commons Attribution Share Alike 2.0 license.
You're free to share, copy, distribute, transmit the work, to remix, adapt the work.
But you must provide attribution to Patrick and I and share alike in kind.