javascript - reinventing the wheels: Node.JS/Event-driven programming v.s. Functional Programming? -
All promotions are currently about an event-driven framework using Java's callback. For my limited understanding, its primary advantage seems to be that you do not have to wait sequentially (for example, you get the SQL result, while calling Can do other work too)
So my question is: how is it different or better than functional languages like CL, Haskell, Closer etc? If not better, then why are not people just working languages (instead of changing the wheel with javascript )?
Please note that I do not have any experience in the node, neither Js nor functional programming, then some basic explanations can be useful.
Reading through the node. Js docs (and good), I think the other answers here do not remember talking about: node JS is based on the idea that the style of writing those programs where we expect them to be blocked at I / O, and instead we should start I / O (such as reading a database or reading socket) And pass with the function to handle the results of I / O with the request.
Instead of doing this:
var results = db.query ("select .."); // Blocking // Usage Results
node. JS is based on the idea of doing this:
db.query ("select ..", work (results) {// use result});
The authors of the author (node.js) say that this method of programming is very strange in many systems because languages are closed or unknown, and the library is mainly I / O . However, javascript supplies first (and programmers are used to find out how JS is used in any kind of event in the browser), and node JS fills later: event-driven I / O library absolutely without a blocking call
How is it related to functional programming? All functional programming languages make the nodes very powerful to complete. What JS is trying to do with Javascript makes it even easier for code, because passing is fundamental to language normally.
For the Hoskel using Mondad, this kind of thing can be very easy to build. For example:
doQuery :: DBConnection - & gt; IO () doQuery db = do rows & lt; - query db "select ..." some rows to make some lines
These very sequential, compulsory rows of code are actually a sequence of closing in control IO
Monad looks like you wrote in javascript:
db.query ("select ...", function (lines) {something (lines, functions) {doSomethingElse ( Rows, functions) {/ * Done * /}}}}}
In short, when in a functional language Mona While writing the dyke code, you are already typing in the form of nodes. J. S. Author wants us to write: Where each phase of sequential calculation has been passed as a pre-term, however, how good code looks in Haskell!
In addition, you can easily access concurrent Haskell features to achieve this non-blocking operation:
forkQuery :: DBCction - & gt; ; IO ThreadId forkQuery db = forkIO $ $ rows & lt; - Query dB "Select ..." some lines do some conflicts
Do not confuse the code forkIO
with the expensive process fork which you use Do, or even OS process threads. It is basically the only light weight thread to execute which is using node.JS (only to some extent with rich words). You can have 1,000s like nodes. To do for JS. So, in a nutshell - I think that Node.JS is building on the facility present in Javascript, but it is more natural functional languages apart, I think all the elements which are in the node are in. JS already exists in Haskell and its package, and then some. For me, I only use Haskell!
Comments
Post a Comment