Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foreign, but very native Node.js development in other languages than JS, C/C++. #71

Open
eljefedelrodeodeljefe opened this issue Jun 29, 2015 · 0 comments

Comments

@eljefedelrodeodeljefe
Copy link

TL;DR

Write foreign code, e.g. Python, Java, Go, and run it with Node --- the node-way --- feels very natural.

var java = require("java");
java.callStaticMethod("com.nearinfinty.MyClass", "doSomething", 42, "test", function(err, results) {
  if(err) { console.error(err); return; }
  // results from doSomething
});
// https://github.com/joeferner/node-java

or

var py = require('cpython');
/** 
* # somepy.py
* import syy
* print sys.argv
* 
* for i in range(len(sys.argv)):
*     if i == 0:
*         print "Function name: %s" % sys.argv[0]
*     else:
*         print "%d. Argument: %s" % (i, sys.argv[i])
*/

var arg = ["name1","name2", "name3"]
py.run("somepy.py", arg, function(err, result) {
  // do something
});

Prose

Say, you want to...

npm search #enter name of cool natural language processing lib here

It doesn't come to any surprise, that the Node and npm multiverse isn't of too much help here. It's just not the domain of full-fleshed, scientific development - and likely never will be.
But here is how Node.js is different: You don't have to write your own NLTK in JS. Python is C software. C is what you are doing already - without even being bothered by it yet.

C and C++ are first class citizens in Node.js and so is everything written in it. And that includes other languages.

"Thinking of Node.js as a shell, and scripts as shell scripts provides a better explanation of what Node.js actually is." - Dave Banister

"...but better. IMHO" - me.

Ever since I began writing Node.js, I was aware of the constant "JS and performance" rant and did not bother too much. Where Node wins is it's programming model and it's time-to-market speedyfullness, not it's int factor of being slower than #your language here. C`s zen and speed however is unparalleled, it's great length to deal with user input as strings is exhausting and verbose, really. So I figured, there had to be a way to combine the two, since C/C++ are prominently advertised in the Node docs.

Since Node-core development is visibly happening a lot in C/C++, with great programming happening in v8 and libuv, it's C/C++ roots is nothing anyone wants to hide away or abstract from. Unlike e.g. Go or Java, Node's development seems to see more extensibility towards other languages in the future and therefore other programming domains, those languages shine in. This is a particularly good trait in a time of micro-services that allow polyglot environments.

This talk shall show the interested listener, what exactly is gained by (fully) integrating other languages outside of the command line or child_process.spawn(). Enter a vast world of foreign looking functions to write more domain specific applications, while exchanging native data. Be able to easily API encapsulate code instead of having it available just in process.

Find out about the perks and pitfalls - but ultimately feel empowered.

Along the way I will demonstrate how to call foreign code in JS already today. There are existing modules on npm enabling you to actually do a lot in Java, Python and Go and potentially there are more to come.

Bio / The reason why

The author is a young polyglot programmer, based and Berlin, Germany, who is seeking to contribute to Node's outstanding community. Seriously, reading Node / IO.js news and codebases is better than binge watching Netflix...

The motivation to write about such a topic in the first place, comes from an API and micro-services background and the realisation to choose the right tool before start crafting. While at the same time continuously expanding your tool belt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant