010 JSJ Node.js

Download MP3





CHUCK: Caaaan yooouuu heeeaaar meee noooow? JAMISON: Chuck, I think you had a Skype noise while you said that. CHUCK: Nice. So it’s, like, Caaan yooOouU heEaAr MeEe? I love it when Skype does that. AJ: Okay, are we still goofing off, I'm guessing? CHUCK: Yes. JAMISON: Yeah. CHUCK: Hey everybody and welcome to the JavaScript Jabber podcast. This is your ,host Charles Max Wood, and this week on our panel we have AJ O’Neal. AJ: How’s it going? I'm still here. CHUCK: And Jamison Dance. JAMISON: Hello! CHUCK:  And like I said, I'm Charles Max Wood from teachmetocode.com. We are having some scheduling and other logistical things going on so, it’s just the three of us this week. We're still hoping to bring you the same great content, but if you have any suggestions then by all means, go to the website, click on the feedback link and let us know what we can do for you. Because we really do wanna make sure that we are providing the best content for you. This week we are going to be talking about Node.js. I don’t know if we’ve neglected it so much, it’s just that we've had opportunities to bring guests on that were more expert in other related and not so related topics that have more to do with web development. So we thought this week we'll jump in and talk about Node, talk about some of the ecosystem that’s there and see what we can get. One other thing is, if you do have specific questions or suggestions for us, we also have a Twitter account @jsjabber and if you have questions about Node or questions about anything else that is related to this topic, that also helps us get a direction and really be able to provide what you need. I’ll quit rambling though and we’ll start talking about Node. So we know from our talk from Lars and Casper that it is basically the V8 JavaScript Engine on the server and I don’t completely understand how that was done. Do you have any more enlightment on that, guys? JAMISON: So let me say that Node is basically a thin C++ wrapper and then a bunch of JavaScript on top of that around V8 so that it can interface with servers side, like system calls basically, networking, file system all that stuff so you can interact with your system in JavaScript which is pretty awesome. So it’s all event-driven because its JavaScript, it is all very async. You make your networking calls asynchronously and on the callback you interact with the file system asynchronously so it all runs inside one process and you don’t have to deal with threading or dead locks or any of the painful synchronization stuff which is really hard to get right. I think the idea of an event driven model for doing server side application is easier to reason about in general and it's harder to make crippling errors that will result in your codes just exploding and dead locking if you are doing stuff with threads. CHUCK:  So does it not use threads then? JAMISON: No. No. It’s all in one process. You can use sub processes so you can like spawn off other processes from Node. AJ: I am going to contest there. First of all, I would not say that it’s not necessarily EASIER depending on what direction you are coming at it and yes, there are threads, but it’s a ThreadPool-type system. So you don’t see the threads, you don’t write JavaScript threads (I think there is a web workers implementation which is  more like a literal thread) but it’s basically in the C code, they spawn a thread or put something on the ThreadPool to do. That's why if you ps and ps aux grep Node, you’ll see there are four Node processes running at a time because your primary process and you just got a couple of threads going. JAMISON: So you said the word “processes,” but is it processes or threads? AJ: Threads. But in your process list, the thing how your process list managers like htop or whatever, maybe in ps you only see one; but in htop you see four. Anyway, there are multiple threads. CHUCK: So basically what it does is, it says, I have a four threads and so when I trigger another event, if there is a free thread to pick it up then that will be the one that handles it. Is that kind of how it works? AJ:  Yeah. So, like, let’s think about this in terms synchronous code because down at the core . . . so this is called the “Reactor Pattern”. There’s a couple of good TED talks and stuff you can find online. Douglas Crockford’s “Loopage” really talks about it well. So say I wanna copy a file and I might wanna do something else as well that doesn’t have to wait. I put the file copy into a thread and then when that thread is finished, it’s going to just mark a flag in the event system that says, “Hey, I am ready to tell you what my result is.” The even loop comes back around and it looks on its queue and it says, “Oh look, here’s some finished tasks. I’ll go ahead and return the results for these tasks and then if those tasks have anything else they’ll need to do, then I’ll put them in the queue.” Makes sense? CHUCK: Yeah, makes sense. JAMISON: So I have a question related to that. Is the queue just a straight up queue? Is there any kind of priority? I mean, will events get serviced in the order that they trigger? AJ: That is kind of a trick question. I don’t specifically know how it is right now. Me and one of my co-workers, we just had this fun project where we were implementing Node API in C and so we used libev just like Node does and we kind of got familiar with it. You can kind of prioritize things with that library. Now they are transitioning over to a new library which they built with the help of Microsoft which is more cross platform. JAMISON: Which feels so weird to say, doesn’t it? AJ: Yeah, especially because the libev guy will probably shoot you for saying cross platform. [laughter] That guy is pretty opinionated actually. JAMISON: Its Libuv right? AJ: That's the new one. JAMISON: That is what I am saying. Yeah. AJ: Yeah. That's the new one that they’ve partnered with Microsoft for. CHUCK: So one thing that comes to mind when we talk about Node is that the canonical, (I don’t wanna say “canonical”) but the specification for JavaScript, ECMAScript (I think it’s just that ECMAScript standard). So Node does some things that JavaScript in the browser just doesn’t do like file access and things like that. So, did they have to kind of add-on to the standard in order to make it work? AJ: Yeah. So I think it’s important to consider the history of JavaScript server side. So let’s step back to that for a minute. CHUCK: I thought the history started and ended with Node. AJ: No. At the same time that JavaScript was created for the browser, it’s also created for the server and the Netscape’s server or whatever that was, actually was JavaScript. Then Microsoft, if you put a .js file on your desktop and you double click on it, it will ask you if you would like to run it with the VBScript Editor if you have that installed. So there is some sort of like Visual Basic plugin that runs JavaScript. I think it’s been there since Windows 95. So if you create like an Active-X object or whatever they call it (I've never actually done it, but I've seen some of the codes) so it’s got some sort of special module type system where you can create a file handler but it’s all synchronous. Then Rhino came out. Rhino has been used for some server side projects. JAMISON: Can you explain a little bit more about what Rhino is? CHUCK: (It’s a big animal.) AJ: So Rhino is just like ---- but it’s synchronous. JAMISON: Isn’t it a Mozilla thing? AJ: Yeah I think it comes from SpiderMonkey, I'm not real clear on that but it’s part of Netscape Mozilla. JAMISON: Very closely related animals; the Rhino and the SpiderMonkey. CHUCK: Yeah. They both have the same big horn right? AJ: Yeah, exactly. And so a little bit later on, have you heard about “Jaxer” or “Aptana”? They have this IDE I think it’s, like, Eclipse based CHUCK: Yeah. JAMISON: Yeah. AJ: Okay, so Aptana was doing a lot of cool stuff in a lot of press for a while and they came up with this idea like, “Hey, we’ll implement JavaScript client-side, server-side and I was actually on a project where we were deciding what to go with transferring a project that was done in Zuul, which is the Firefox XML plugin language. So that's one of the things that we considered, we never went with Flash which is probably a bad bet because well, it’s dying now. CHUCK: It just occurred to me, there's a fellow out here, he’s a flash developer and he’s trying to pick up canvas in HTML but he has a really interesting take on the transitions that are happening in that world and why people are moving away from Flash. And it’s really interesting how much of it and how little of it has to do with Adobe. That might be an interesting thing to talk about just in the sense that people are making the transition now to HTML5 and Canvas and stuff. JAMISON: I don’t know who you are talking about. AJ:   I think his name is Brett. Anyway, so then there was Jaxer. So there is a lot of interest in this idea, it’s kind of a seed that's planted in a lot of people’s minds. And when Node.js hit, I was going to the Ruby group and some people are talking about it and at first I thought they were saying “Node.js” I didn't know what it was and people kept on bringing it up. And so I thought, “Okay, I’ll take a look at this”. I think someone did a presentation on it and I was hooked and then two of us kind of simultaneously started up the JavaScript Utah group and all that. Anyway, there was Window.js (I think) was the name of another platform. At the time that Node.js are really starting to form together, there was three, maybe four competing products that were doing the same thing, and I think a lot of it has to do with the jQuery made JavaScript fun because people hated it for a long time. If you hadn’t got a good education on it, you have the right to hate it because it’s just as terrible as PHP if you don’t have the discipline to help make it better or use it properly. CHUCK: Right. You have to have a pretty good understanding of how the different constructs in the language work. Not only that, but a lot of them have some implications as to the way that you interact and the way that they work. So if you don’t have a good handle on that, we'll talk about some functions and closures and things like that. Objects and the way objects behave in prototypal inheritance. AJ: Not even to start with differences between browsers. CHUCK: Right. You got the whole different VMs between the browser and it’s not necessarily even language’s design, it’s just that the ecosystem is so different than anything else that you’re dealing with. You have in Python, in Ruby in a lot of these other languages sure you have other implementations on other VMs but ultimately, there's like one canonical version that the main guy behind it has built. So everybody else more or less just copies the API that this guy comes up with. With JavaScript, it’s not necessarily that way because each of the browser vendors has their own little agenda going on and they care about some features than others. So you really wind up with this really interesting eco system with it for better or worse, it can get you into trouble. AJ: So Common.js which is the whole “require” system, that started more with like the Rhino group but then like the Window people and the other people kind of picked it up and common.js is, like, well, how do we, instead of every time you include the file that everything is global, actually give things scope and. . . CHUCK: Mouthwash. AJ: Exactly. Cleaning it up, getting it fresh. CHUCK: It’s kind of funny, but it’s actually pretty apt when you put it that way. Anyway-- AJ: So Node.js deviates from Common.js a little bit, but in way that really makes sense because I think there is some short-sightedness in Common.js because for whatever insane reason, the Common.js people never thought in their head like, “Hey, we might wanna create something that could be used in a browser as well.” So there are key features that were not really done right. And Node.js did deviate from the Common.js standard in order to implement it correctly. The main thing there that they fixed being that's you have access to the module so you can export a function and the commonJS standard you can’t export a function. It has to be an object. So Node is built on V8. It implements everything that V8 implements, but then it has all of these asynchronous APIs outstanding. But another kicker is from version 0.1 Node has had excellent documentation. And that's one of the things where a project either flies or dies based on how pretty that doc’s page is. JAMISON: Well, it’s not just documentation. I feel like the Node community has swam up very firm almost, like it’s really young but it feels very mature at the same time. You have a lot of really smart people who seem to have lots of things figure out things pretty well (which is cool). It doesn’t feel like the feeling around as much as trying to find out the best way to do lots of things. It feels like there's a lot of shared knowledge on best practices and stuff. CHUCK: Well, there is best practices and (that’s a topic for another show I think) but, you know, JavaScript especially with Node.js, it’s this interesting ecosystem that we wind up with because there are  communities out there that have been using JavaScript for 20 or 30 years and so they just really moved a lot of that  interest in and so there was a lot of mature knowledge about the language even if there wasn’t as much mature knowledge about the platform or whatever you wanna call Node.js itself. AJ: And you got to consider that largely, people that have adopted Node.js (as far as I can tell) have not necessarily been the people that were using JavaScript, but the people that were using Ruby. CHUCK: Yeah, there is a bit of movement that way. AJ: Before .03 when they were just getting into the second vision, they already had version control figured out. Like NPM, basically took everything that Gem has, improved upon the weak points and then bam! It’s there. And there is also like an RVM type thing for Node as well but with the API moving so fast, up until 0.4, there want much change between 0.4 and 0.6 and it looks like 0.8 will stay about the same. CHUCK: Are they using Semantic Versioning? JAMISON: It’s kind of a style and stapling. You remember stable? AJ:  Yeah, and then the point where these are bug fixes. CHUCK:  So you are not allowed to API on the bug fixed releases which are the 3rd number if you are going point, point ,you know, 0.6, 0.4, 0.7 0.anything. AJ: T he rule to follow is that it’s not considered to be stable until they hit 1.0. So they are keeping the 0 number there you know people are using it in production, they are keeping the zero number there so that it’s kind of a disclaimer but from what I can see it looks like things have gotten more stable and you might say 1.0. CHUCK: I've heard some pretty awesome stuff about 0.6 and just the stability and reliability, not just in the VM doesn’t crash, but in the ability of the API and we really don’t expect major changes here in the future. AJ: There's a couple of obvious bugs as you use the API, like shouldn't this go there and then there's just a few little places that just let it in and sorted out so it’s really stabilizing for sure. CHUCK:  Let’s talk about NPM for a minute because I'm a little curious there. Some people may or may have not the background from Ruby we they are talking about RubyGems or I think Perl has CPAN or is that Python? Python has eggs. JAMISON: I think the PiP is there, probably people will tell me I'm stupid. I think PiP is the canonical package manager. CHUCK : So if you’ve work with a language like that, you should be pretty familiar with what it does. Why we don’t just go over it really quickly? JAMISON: So NPM stands for nothing. I was about to say it stands for Node Package Manager but it specifically says it doesn’t --- anything. AJ: Oh, that's a lie. This is one of those things where they are like ------. JAMISON: Anyways, it’s a program that lets you install Node packages by either specifying basically or putting them at package.json file, which is basically you list your dependencies and then  there is a dependency resolution stuff so find the dependencies of your dependencies and do all that good stuff. It lets you publish packages to the NPM repository as well. I know I should explain it to people who are not familiar, but it’s kind of RubyGem and bundler kind switched together. When you have your dependencies getting this package.json file, you just type npm install, npm will search through that, pull out all the dependencies and packages into a Node modules folder, inside the folder that you called npm install from. So it installs these drivers locally and then you can specify to install them globally across your home machine but by default it automatically kind of which has been in the past so you can tell that was a problem somebody though about and solved. CHUCK: Yeah, it was a problem with Ruby Gems for a long time before we have bundler which effectively does that, it does a local install of your Gems, which are your libraries. JAMISON: I mean, it feels like those problems are really related, the problem of installing stuff and figuring out local or global versus dependencies and stuff, so it’s really nice that it’s all in one tool. AJ: The latest version does not allow globals. The only way you can do a global is if you are doing an executable, so if you wanna install a systems script with NPM, you can do that but you cannot require global anywhere (which is great I guess). JAMISON: But you can still install. AJ: But you can’t use it. JAMISON: Yeah. So you can’t require some global thing that I installed, is that what you are saying? AJ: Yeah. I mean, like it’s useless to install a module globally unless it’s packaged with an executable. For example less the CSS compiler or CoffeScript compiler where it has an executable CHUCK: Ok so then how can you make use of these packages or whatever you might call them. Are they packages? Are they libraries? AJ: Whatever you wanna call it. CHUCK: We’ll call them code flex. So how do you use some flex of code in your golden application? AJ: The way you go about it is, (I'm going to put this link in the show notes) but I got a really simple how to get started at NPM as a developer. I got, like, a hundred bajillion 50 line snippets in NPM just because I like to use my code. All you got to do is, in RC file, you set your name, your email, your blog, or whatever the web contact point. You then NPM-ADDUSER, you add yourself to the system and set a password then you just cd into your project directory where the package.json is that has the dependencies listed and all that. You do NPM publish. and then you go somewhere else and you go NPM install <name of package> and that's it. It’s really simple, super, super easy to contribute to NPM. Anybody can do it. JAMISON: And then were you asking about actually using these libraries that you can --- in the code, Chuck? CHUCK: Yeah. JAMISON: So that is the “require” function. You call require and then you pass on the string that's the name of the library and that will return (if it’s written right) it will return some function or object or whatever. So everything that the library provides to you is kind of name spaced inside that. It’s kind of like the Python model where require import or something. So again you can kind of tell that someone looked at Ruby the way that you call require something and then it just cut it up here, and it’s like, that could be done better. It’s really nice that you know that stuff isn’t going to magically change. You are not going to have objects or crazy things that are just appearing on global scope. AJ: So there are some very important notes there. When you npm install, it recursively installs. Let’s say that you have a module that’s used by two packages. So you got module “foo” and “bar” and both foo and bar depend on “baz”. What you are going to get is you are going to get two separate copies of baz; one is going to be in the sub tree of foo and the other is going to be at the sub tree of bar. So depending on what you want, it may be best to include foo, bar and baz all on the same level, so that any internal voodoo that happens with baz will be a shared state that both foo and bar have. For example “instanceof”. Let’s say you are passing an object around and you wanna use instanceof (which is probably an anti-pattern more than a pattern just because it’s so unreliable and I find out this the hard way) but if you pass an object somehow from foo to bar, a baz object and you say is instanceof baz, when it gets to from one module to the other, it will return “false”. Because the way they require works is that every file is required exactly once. The file is not executed until it has been required, but if there are two files of the same exact module, you have two different instances entirely of that object. CHUCK: You are not my baz you are the other baz. AJ: Exactly CHUCK: Oh, that could be real fun to debug I'm sure. AJ: There’s a few cases where what is actually common is with “mime module”. If you are using the mime module in any of your sub modules or anything depends on mime, go ahead and include it at the top level. Because with mime, the common things you wanna do is define a mime type so you are going to get it this extension and this mime type. I think they include HTML5 app extension by default now, but they didn't use to. That’s where it can bite you. It’s like, “I required mime, I set the mime type. Why isn’t it working?” because you are doing it too low. CHUCK: So I wanna get into where or how people use Node, but I really wanna answer another question really quickly and that is just how do people get started with Node.js? What’s the best way to get going? Do you just go download it somewhere? I'm asking this question having already done it, but I know you can explain it better than I can. AJ: Now it’s super easy. You go to Nodejs.org, you click the download button they got, they got the pkg for Mac, they got exe for Windows and with, Linux if you are using Arstd or something, you might have in your repository otherwise you probably wanna compile from source because I don’t think that Ubuntu has a good version of Node and you should be using 0.6. CHUCK: Okay. The other question that I have is, how do you find the modules that you need with NPM? Is that a search function in there? JAMISON: Just search. It’s super slow though. You can do it in NPM.org, too, I think they use some back-end so its host there, but are you saying like discover modules? So like I need use an HTTP module, like which one should I use? CHUCK: So let’s say that I am super new to Node.js and I've never heard of “socket.io” and somebody is telling me, “You need Node.js so that you can do web sockets”. So how do I go about finding that library just to an NPM search socket? Web socket? AJ: I would suggest first Google it, because most of the time you are going to get, like, 3 results and those results may not be entirely accurate because Google’s new algorithms do not maybe go to the old ones. CHUCK: It has to come up somewhere, right? We’re not always happy with what they did. Anyway, keep going. Sorry. AJ: So if you look at the top 5 results on Google, one of those is going to probably not going to be it. The best way to decide is probably, because we are all going to be listed on GitHub, so you check the number of forks, the last commit and the number of watchers. And the one that has the highest numbers of watchers may not actually be the current maintained version because often one person starts a library, another person picks it up to maintain it. So if you click on the fork, you will see like, “Oh look, this fork stop two years ago (I don’t know how it’s possible but I'm pretty sure I save it.) And then you will see another line of fork that doesn’t have as many watchers but it’s got like 60 commits on it and it pulls in from all the other branches, that's the current one you should be using. JAMISON: So as far as just discovering, if you have no idea, the node --- feature on freeNode is really good too (there’s tons of friendly people too). CHUCK: Is that #node on freeNode? JAMISON: I think its #Node.js. Let me check. Yeah, if you hop in there, just say, “Hey, I want to do X in Node. I want to send pictures of cats across the internet,” and they’ll tell you, “Oh, use Node cat.” Actually, isn’t there a module for that? One of those artificial intelligence spam bot type thing. JAMISON: Maybe there will be. AJ: I think there was one that will send links to pictures of cats in chat rooms. JAMISON: Oh yeah, I think that's Hubot. That's just GitHub thing, the little bot, it was a friendly fellow. CHUCK: Yeah, they actually use Hubot in their campfire chat as well and they use them to control all kinds of chat. I actually had an interview with Tom Preston-Werner for the Teach Me to Code podcast. He talked about Hubot. I was falling out of my chair laughing with some of the stuff they programmed it to do, but yeah, interesting. There are Ruby Gems, too, that their sole purpose is to draw certain shapes or images on your screen. JAMISON:  And those are the best gems. Stuff like that? CHUCK: Some of them aren’t PG-rated so. . . JAMISON: Oh. So it’s “#Node.js” on freeNode. AJ: On my screen when I searched Node.js rrc, first hit “no longer maintained.” So maybe those algorithms can be tweaked given the size of this thing. [laughter] CHUCK: I think you are supposed to download it or something. AJ: You can’t do that anymore. When they were introducing Google+ they get rid of that. CHUCK: Oh, that's right, you can only +1 one of them. Yeah, I think that's the other thing that is interesting. JAMISON: That is your implicit need -1 in the entire rest of the world that you don’t +1. AJ: This is how you do it. Just open Internet Explorer 6, download the Google toolbar and then hit the search rank thumbs down button. That button will do it for you. CHUCK: Do those still work? AJ:  Last time I saw Google toolbar, it’s still hot, but that is probably a year ago. CHUCK:  So let’s get in to what people are using Node.js for. And this is really interesting for me because there’s been a bunch of back and forth with former Rubyists using Node and current Rubyists who have tried it out and saying, “It worked well for this, but necessarily for that”. So what are the strengths and weaknesses, and I guess I'm probably aiming at specific modules within Node that provides like a web server and things like that? JAMISON: So I think one immediate strength that it’s really good at is real-time stuff, so push stuff, you can do that in other languages, I know, but with node it just feels natural. So socket.io server for doing web socket communication, which lets you push stuff back and forth between the browser and the server. CHUCK: Yeah, you can think of it kind of like as using the phone instead of IM, so you are not waiting for the message to get there, get processed and sent back. You actually have an open line where you can get the message both ways (at least that is my understanding). JAMISON: Yeah, it’s really similar to TCP sockets, very similar. Good, good basic idea is kind of similar, when you open a connection both sides that read and write to, it’s just over HTTP. AJ: I think it has to be UTF-8. CHUCK: I understand that some other website sockets stuff and web socket kind of covers a couple of other technologies, but I guess there are transparent proxies on the web that have messed up some of that stuff depending on what you are using. AJ: That's been fixed. CHUCK: Yay! That makes me happy. AJ: I'm pretty sure that's been fixed. It's back in Firefox, I may be mistaken on this, but Firefox was committed to take out web sockets until that was addressed and now there is, like, web socket  version 13 or something. I just saw an HTTP header go by earlier today that had WSV13 or something like that in it. CHUCK: Oh nice.  Yeah, I was kind of hoping that they would solve the problem instead of just saying, “Well there is nothing we can do. We got to work around it.” But that's really cool. So one area that I've heard good things about is the way that they handle sockets. One other thing when you are talking about real time stuff, the event model makes a lot of sense to me when we are talking about things like a chat room or something, where you get something in and you effectively want to generate events to manage it going back out. So things like that make a lot of sense to me. JAMISON: Yeah, it’s simple to do that. AJ: If want a prototype network code of any kind, you need TCP HTTP you cannot get something that is easier and faster to set up than Node (compile time excluded, depending on your system). It could be situations like specifically I really have a hard time getting it on ARM board for this media box project that I'm doing. CHUCK: An ARM board? AJ: Yeah, I personally feel that Node is ready for ARM right now. If you are looking for something like ARM, you should probably go with a different language, maybe Python. Golang looks like it may have a better support than ARM with my initial test it’s more stable. Node.js is not as stable at ARM as it is on a x86 for sure. JAMISON: So, another thing about Node is I know that benchmarks are blah, blah. Node really is the fastest. CHUCK: It really IS the fastest. JAMISON: It’s really competitive speed-wise among all the interpreted languages and you can find different benchmarks to go. Everyone who points you to them will probably show different things, but it’s pretty fast. AJ: That's another point. JavaScript with Node became interesting because all the other implementations as I understand it, were script interpretation. Node.js is not interpreting their script. You are compiling it down to machine code. It does it every time it runs so start up time is maybe a little bigger but as far as I know Python really don’t compile it onto machine code. CHUCK: No. So basically what you are saying is, every time I change my program I have to restart my Node vm? AJ: Yes JAMISON: Yeah. I have something that does magic for you but. . . CHUCK: So you can’t say, “Oh here’s new code.” Because that is one of the nice things about Ruby in particular or Python is that it’s like, “Okay I've got new code. Here it is, interpret it.” and it just go on as many way. AJ: There is a trick that I've read about that relies on some undocumented black magic where you go in and you delete the module from the module cache and then require again with the different string somehow. CHUCK: Interesting. JAMISON: So there’s also a module called “Node Supervisor” by Isaac Schlueter chief guru of Node right now and it’s just a watcher so every time you change the code and save it, it will reload it. CHUCK: That's cool. Some of the other paradigms on the web mainly where I'm basically just making one call in and it’s going to go fetch something out on the database and come back and say, “Here it is!” and give me HTML. Is there really that big of a difference use something like Node over something else like Rails or Django or what have you? JAMISON:   That might be way cooler than the other people. AJ: That's true and here is the classical counter question to that; you have a list of 100 items which solving algorithm should you use to sort them? Whichever one you can code fastest! It doesn’t matter right? I mean, it can only do one thing, but who cares if Node is the fastest? You are not going to notice. It’s fun to program in and it’s the expressiveness that it has is nice, maybe not quite as nice as Ruby depending on your point of view or your favour but it’s fun I think that's one of the advantages of it. CHUCK: So that's something else that Jamison kind of said. I think it’s an important point to bring out and that is he basically said it's competitive with other languages. I think that is really valid point is that when you come down to the benchmarks, you started to look at, okay, this one is faster and this one is faster than that one. But if they are all bellow that line of “fast enough,” then your advantage of wanting that language really comes down to how quickly or enjoyable you can code it up is what AJ is saying. And I think that really is a valid point. So whether it isn’t something like Node.js or in Ruby or in Python or in .NET or in java whatever, if that is your cup of tea, that’s what really gets it done for you, then yeah what difference does it really make? But when you have this other instances where the paradigm and the language really matches up with paradigm with the I really like the idea of having something that is like, yeah, you just triggered these events and it goes and does this thing and it’s done. AJ: So I’d like to bring up the case where I don’t think Node is appropriate. CHUCK: Thank you! AJ: But I like to do it anyway. CHUCK: Okay. AJ: Node is not appropriate for system scripts and I feel like a gun pointed at the back of my head I'm looking around makes you think if the people of Node are hearing me. If you can do a really small stuff and it doesn’t matter, then it really doesn’t matter right? But there are some downsides to Node. Start-up time is perhaps longer than you want. So personally the start-up time, again I have this personal hobby project on the ARM and so to me, I wanted to be faster. When you are using x86 then it’s probably pretty fast enough and a lot of stuff we do at work, we do some web applications for office stuff and whatever and it’s not a problem with any other situations. But I was writing a script to transfer basically a terabyte data almost from one hard drive to another and indexing it as I go and I written that with Node.js and the performance is terrible because all the call backs end up hitting the CPU and it’s just asynchronous works against you in that case. That would be much better off to do it in Python. CHUCK: That's more or less asynchronous process anyway right? AJ: Yea, but, I mean, the thing is I know Node a lot better than anything else right now and so when I wanna solve problems it’s, like, do I wanna do this in something else or do I just go ahead and do this right now in Node? JAMISON: It looks like the problem is solved by Node; is that what you are saying? AJ: Yeah, and I like JSON. I like how it’s a perfect match and most languages are pretty perfect match with JSON these days and they are all kind of get together, but I just noticed that it’s not good for the application if that type of performance is important to you because if you are doing a lot of asynchronous calls but you are doing it in something that could be done synchronous, you just lose efficiency in it, takes maybe longer. JAMISON: So to summarize, you said that Node is awesome for low level networking stuff, right? AJ: Oh my goodness. JAMISON: For,like, push real time stuff specially web sockets and for writing shell scripts. AJ: Another problem with the system scripts is the way that integers work in Node is absolutely horrendous and that's not Node its JavaScript, I mean, that's the spec. but the spec is normally all numbers. [laugher] CHUCK: is that in Wikipedia? AJ: I'm pretty sure. JAMISON: I wanna talk about the part that comes up when people talk about the benefits of Node, which is the use of code between the browser and the server. How do you guys feel about that? CHUCK: We kind of had this discussion a little bit before. I think that there are definitely instances where that can occur but I also think that it’s not a complete panacea. It’s not something that will always work all the time with all code. So if you can make that work, if you can’t, I think it’s still a little bit of a pipe-dream. I think Yehuda kind of patch that out but I'm kind of siding with them at this point. I would really love to see it happen, but I don’t think that it’s something that happens all the time under all circumstances and I don’t know if you necessarily wanted to so... JAMISON: AJ is a big proponent of this, so. . . CHUCK: Yeah. AJ: This is my thing; first of all, people need to use the mvc pattern or whatever you wanna call it, whatever the hipsters are saying in these days. I mean it’s all the same thing we rehash it and call it different names, mvc is what I will call it right now. Quit putting your on dead on logic and your interface to the data in the same package. Get a function there, passing the data, do your stuff, get the data out.  Because everybody is still in this mentality of running 12,000-line long JavaScript files which some of those an NPM (not 12,000 but maybe I don’t know). Stop doing it. Cut it down in chunks, because then you have stuff that’s actually modulate that you can publish. I think if you can’t separate your code and do something that can work in a browser, then you are doing it wrong and same thing vice versa. If your browser code, you can’t run your core modules in Node, you are doing it wrong. You need to stop using Window; you need to stop using this as a global, you need to stop making these expectations of ignoring the difference between your algorithms is or your process, your business process and where your data is coming from. They need to be separate. If you separate them, it will work just fine. CHUCK: I think that's also an interesting point, separation of concerns and then you really can design pieces to work together that way. JAMISON: it can sometimes feel like it’s more work. Lots of times it feels like it’s for convenience like I don’t wanna type two different things if I'm doing something that's maybe similar on the browser and the server, but you do different things lots of times Some of the code out of the box but I'm really suspicious of these frameworks that are trying to be full stack like Node frameworks that also have shared codes with the browsers so your model on the servers are exactly the same as your models in the browser. AJ: Well I'm suspicious of the Frameworks that don’t do it. CHUCK: Well, I tend to side a little more with Jamison. I honestly think that there are definitely going to be some areas that you can have that overlap, but at the same time, I really feel like the paradigm on the browser and the paradigm on the server, you’re solving different problems. AJ: Are you? JAMISON: If you abstract it enough, I guess. Me and Chuck has the same problem. CHUCK: Right, but where is the line where it’s actually worth it? And then I guess that's really where we are having the discussion, right? AJ: This is what I am saying. In the browser, your interface is. . . JAMISON: You are talking about, like, strict mode stuff basically, right? Like, don’t do stupid stuff that won’t run in strict mode. AJ: Well, yeah if you do strict mode, and a lot of people have the misconception. I recently found out that a lot of people think that strict mode and JSLint go together; they don’t. Your code doesn’t have to have to pass JSLint to run strict mode. You don’t have to do all those crazy things. So, like, what people say, I can’t use strict mode because I have to do this and my code won’t pass JSLint when I do that, so I don’t use JSLint and they are not related.  So I just wanna throw that out there. Yes, there are lots of things that strict mode will not allow you to do, dumb things like use this as the global. So then if you are using strict mode, then you do get the added benefit of your code just automatically works between the browser and Node. CHUCK: What we are going to do is maybe next week we can get in and maybe we can all do some homework on this and see what's out there, maybe have a little bit of discussion on the mailing list. Next week, let’s just talk about this. Let’s just really go in to, okay, do we really think that it’s feasible and that it makes sense to have code that runs in both places and how much and let's really do it. Let’s hash it out let’s have a fight and exercise the listener, if you have an opinion on this, we really wanna hear it. So leave a comment in the blog javascriptjabber.com or just email and just let us know. Or you can pick a fight with us on Twitter, but I have a funny feeling that having just 140 characters isn’t going to do it justice. JAMISON: I think that 140 characters are enough to make a fool of myself. That is what I found out whenever I have complex discussions. Just enough that everyone thinks I'm stupid. Can’t say anymore. CHUCK: I've started enough fights on Twitter to where, yeah, you get into it. By the time you are done, you realize that depending on how you read the different tweets, you pretty much just talked your way in a circle because you couldn’t complete one thought between 4 tweets. But we need to get into the picks. AJ: Just one last thing. One last thing. I would say that we are nearing the tipping port because there are at least four different packet managers that manage packages through NPM with the browser and Node just one through another so maybe we are not there yet, but I think it’s a good one. CHUCK: Could be. Very well could be. I think it is a really interesting place to go because don’t think there are any other languages that run in both places. So really, really fascinating thing. I mean, you might be able to make the case for Dart or something, but that is only something for Dart Chromium or Chromium Dart or whatever the heck Dartmium, I think it’s called. That may be another interesting discussion to have with those guys another time. I mean, it’s kind of, like, a uniquely positioned language that has this interesting interplay that we may be able to take advantage of. Anyway, with that, we'll get into the picks. Jamison, what are your picks? JAMISON: I have a few picks. It was my birthday last week, so I’ve got some sweet presents that I really enjoyed. CHUCK: Are you going to make us feel old or are you going to not tell us how old you are? JAMISON: I'm not going to tell you. I got a really cool pair of socks and they are from this place called happysocks.com and they are very colorful but manly colorful (kind of). Not flamboyant, just, like, expressive but in a way that doesn’t threaten my sense of manliness. I really like my socks. My next pick is a TV show. We talked about TV shows last time when we have Joe on and it reminded me because this is the only TV show that I actually have ever in my life watched as it is come up. It's called “Justified.” It’s on FX and it’s kind of, like, a modern day cowboy show. It’s got Timothy Olyphant, he’s the guy, I think he's from Deadwood that HBO put on and a couple of other things, but it’s really cool. He's kind of like Clint Eastwood but Clint Eastwood is the man. So it’s just kind of reminded me of that. That super cool cowboy type thing. So and my other pick is the Kindle from my birthday and I love them. I was skeptical of them from a while but Chuck and I were talking about it, it’s pretty amazing how much of a difference the specialized screen makes for reading outside and just for reading. It’s a lot more comfortable than reading on a computer screen. I've read a lot more when I got them which make me happy because I love books. I love to read. CHUCK: One interesting thing about it is you don’t have to prop it open like you do on regular paper book. Because I've been reading some books that I actually own in hardcopy and the more I get into it, the more I wish I just have this on my Kindle because it’s so convenient and light. I used to read books on my iPad (I mentioned this on the preshow) but I used to  read books on my iPad and I didn't realize what difference it made from having iPad backlit and having the Kindle not, but its way easy on your eyes to read but the other thing is, the iPad was at least three times as much as Kindle and so propped it up was just a pain. Now one thing that I do wanna point out about Kindle is that is a little issue that I found, is that I have people send me their eBooks in PDF and if you are trying to read a PDF on your Kindle, it’s an image so you can only scale it. You can scale everything, you can’t just scale the text which is something that you can do with the Kindle formatted books so if you are reading a pdf, you may wind up reading on your computer or reading on your iPad. But just about anything else and if they put it out in a mobi format, which is an open source format on the Kindle can read or anything else, it’s so nice. JAMISON: I'm pretty sure that the Kindle format is a modified. CHUCK: Yes, their official version is not open source than abc or something. But it’s, like, a specialized encrypted compressed version of the mobi but I don’t know how that works. JAMISON: Oh. I have one last pick I forgot. I got these awesome headphones. They are called “Grado SR60 Headphones.” I'm not much of an audio buff, but I asked a friend who was what are some good headphones high quality for not a crazy amount of money, because headphones can get pretty insanely expensive when you get people think that you need, like, gold plated cables or, I don’t know, you can spend a lot of money on headphones. These were, like, $70 and they are amazing. They are so nice. It's SR60, so if you want nice headphones, they are open so other people can hear what you are listening to. If that is a problem, then probably not for you, but if your music is so awesome that you just wanna blast it on anyone like people who huge stereos in their cars and, like, crank it really loud, you can do that with these headphones to share how cool you are with the whole world. So those are my picks. CHUCK: Yeah I love all those people. They have it so loud you can hear the windows. . . JAMISON: It can be, like, oh I love this song, and I can’t feel my face because it’s so loud. This is nice. CHUCK: You hear the window rattling and that's about it. That is awesome music if I could tell what it was. JAMISON: Yeah, it’s like a robot exploding, what it sounds like. CHUCK: But then you also have these people that go to these contests and try and max out their sound systems to get the most decibels out of it. I think those are kind of cool actually because it’s like engineering feat but not practical for day to day use. JAMISON: But these headphones are, because they are. CHUCK: AJ, what are your picks? AJ: I have some pretty nice headphones, but this week I'm going to pick Nintendo because they make games that are mostly family friendly and just fun to play with people. So I got a Wii kind of out of whim, not to kind of exactly out of whim last week. CHUCK: That's old technology man. AJ:  That's all right, it was cheap. CHUCK: I think one might be causal to the other. AJ: So it came with the games that I wanted. It came with Mario Kart and Smash Bros and Super Mario, which are basically the only games that you need to enjoy the Wii or any games you buy then over and over again. I used to have Top Gear in there too, but they screwed it up on the 64 and then it never became popular again. Anyway, so it came with those games and it’s just been really fun. I played it with people and believe it or not, video games help me became more social because that means I'm not programming. CHUCK: Yay for social! AJ: Yeah, I told somebody that I was getting Wii so that I’d be more social and I get this weird look. JAMISON: No, the Wii is total the most social of the consoles. I don’t know, it’s not a ton of fun all by yourself but it’s so much with fun with people. AJ: I have to get the Game Cube controllers for it because playing Smash Bros on the Wii is not possible because they multiplex so many of the buttons. Like my favorite move, I cannot figure out how to do it because it requires, like, pressing 2 buttons and over and then on the other controller, like, the A button all at, like, the perfect synchronicity whereas on the Game Cube controller it’s just, like, Z over an A it works every time, so I'm losing because I can fight. [laughter] CHUCK: Anything else?  I got about 4 games to list here. Anyway, so my picks are kind of going to be all over the place. One thing that I just discovered here for some of the stuff that it is a program called “Things.” You can get it on the mac app store, you fortunate people who got a Mac. Basically, it’s a to-do list except at its hyped up. It has all those other extra stuff in it that just makes my life better. Did I pick it the last time? I don’t think I have. I was looking at the list. Nope, I didn't. I did pick it on Ruby Rogues; that might be what I'm thinking of. But yeah, I don’t know, I never can tell how much crossover I should do with my picks, but I have to say that I'm really loving it. Lets you set up different tasks you can sandbox, not sandbox, but you can categorize them and you can also put them under a specific life role or area of responsibility. So then you can kind of break things down however you need to mark stuff off and really be, like, okay, I need this get done today, I need this get done this week and just really, really handy. One other that I have been using for a while and I've just found their Mac app, is Harvest and this is related more to freelancing, but it's more. I use to track all my hours and invoice my clients. I also have my subcontractors use it to track their hours so I can invoice my clients for their work. And it’s worked really well and I just love it I really love it. One last pick that I have, and I kind of hesitate to pick this because it’s sort of it's called “The Podcast Mastermind,” you can find it on thepodcastmastermind.com. Basically (how do I explain it), so it’s a group of podcasters that it was put together by Cliff Ravenscraft over at podcastanswerman.com, which I highly recommend,especially when you are thinking about starting a podcast. Anyway, so he decided that he wanted to create this mindshare about podcasting and it goes well beyond that. We talk about life, weight loss and family and all these other things and it really is a true mastermind in the sense that you get from whichever book invented the term mastermind. I don’t remember what book it was. It was the Millionaire Mind or Think and Grow Rich or one of those. Anyway ,it’s just a place and time where we can get together and talk about what is going on and give each other feedback, explain, okay, this is what I got going on and I get a lot of positive feedback for that and it’s just been an incredible resource not just in the realm of podcasting but personally for me, I've made some friends and really have gotten some valuable feedbacks from them. So if you are looking at getting to podcasting and you are willing to spend the monthly fee to be involved, then go check it out at the podcastingmastermind.com, but what I would recommend first is go listen to podcastasnwerman.com, go listen to the podcast there and really kind of get a feel for what is going on. Try and start a podcast and just really get a good handle on what you are working on there. So anyway, those are my picks and that's about all I have. I do want to let everybody know that we are working hard to get this TV show out as soon as we can. My goal is we record this on Tuesday and we are going to set time to record this on Tuesdays so hopefully you'll get them by Thursday or Friday on the very latest, but my goal is to get the podcast for the week out by Friday. So look for it then and if you listen to this weekend or something, it’s there. If you pick it up you can listen to it the next week through your or anything then that should work for you too. Anyway, if you have feedback as far as when you want it to come out or anything like that, let us know. You can email me at chuck@teachmetocode.com and I'm pretty open to getting those emails and answering them as I get them. You know I definitely aloe your feedbacks and things. I'm also working on few other things with my podcast in general and so keep an ear out for that because I’d probably bring it up next week. Other than that, we are also talking about doing a book club, so if you have a book recommendation for us then you can email us and let us know or tweet it to @jsjabber on Twitter and with that, we are on iTunes check us out leave us a review and thanks for listening. JAMISON: See you. AJ: Good night! Thank you for coming. JAMISON: There you go. All of our listeners, we are coming from India.

Sign up for the Newsletter

Join our newsletter and get updates in your inbox. We won’t spam you and we respect your privacy.