News for hackers. Stuff that matters.
Re:The melting pot of JavaScript (2017) by sonnyblarney on Tuesday January 08, 2019 @12:42AM (#18853507)
Sympathies to your valid concerns ...

Though Java was 'designed', it was not 'designed' to be an http/web server.

JS, particularly Node.js has really adapted itself to that well.

And one small but massive difference: JSON is how data is passed and it fits seamlessly into Javascript, and doing JSON in Java is an ugly, ugly thing.

As soon as you compare not JS/Java, but Java/Tomcat vs. JS/NodeJS - then you get a different comparison.

I quite like using Typescript on Node.js over Java - development speed is faster, and this is a really important thing.

Re:The melting pot of JavaScript (2017) by adrianN on Tuesday January 08, 2019 @12:48AM (#18853531)
JSON is how some data is passed today. It's certainly not the best way and might go out of style just like XML did a while ago.
Re:The melting pot of JavaScript (2017) by pjmlp on Tuesday January 08, 2019 @03:14AM (#18854109)
It is already on its way out, thanks to gRPC and need for performance instead of parsing text all the time.

It is only a matter of browsers getting native support for gRPC.

Re:The melting pot of JavaScript (2017) by sonnyblarney on Tuesday January 08, 2019 @11:44PM (#18862340)
It's available now! Yay! [1]

With gPRC there's still a lot of binding code, and you need to map all of that in Java, but you do get some validation etc. out of it. It does make the 'data transfer' comparison a little less harsh.

[1] https://github.com/grpc/grpc-web

Re:The melting pot of JavaScript (2017) by pjmlp on Wednesday January 09, 2019 @01:58AM (#18862853)
Not really, I meant as browser builtin API, implemented in native code.
Re:The melting pot of JavaScript (2017) by sonnyblarney on Wednesday January 09, 2019 @08:38AM (#18864556)
No, that's not on the roadmap and I doubt it ever will be.

It's a very specific technology, and as long as it can be implemented fairly efficiently 'up the stack' in JS, then it mostly belongs there. Aside from HTTP2 (which is a roadblock now, but not soon) it'll be fine in JS.

Re:The melting pot of JavaScript (2017) by gwillz on Tuesday January 08, 2019 @01:12AM (#18853649)
I was reading something on HN recently and I ended up on this wiki article.

https://en.wikipedia.org/wiki/Billion_laughs_attack

It got me thinking about it. JSON is annoyingly simple at times, yes. But that also protects it from some pretty gnarly stuff seen in XML and YAML. I suspect it's a considerable contributor as to why it's the choice transport format.

I wouldn't toss it in with XML just yet.

Re:The melting pot of JavaScript (2017) by Traubenfuchs on Tuesday January 08, 2019 @04:46AM (#18854462)
> doing JSON in Java is an ugly, ugly thing

Why do you think so? Jackson and Gson work very well. Serialising and deserialising from/to POJO/JSON is trivial with them.

Re:The melting pot of JavaScript (2017) by sonnyblarney on Tuesday January 08, 2019 @12:59PM (#18857707)
JSON and Javascript data objects are essentially directly interchangeable.

In Java, you have to abstract the document and write a lot of code to access, add, remove things etc. - or - because there is no such thing as an untyped POJO in java, you have to set up a ton of things if you want to use real objects.

Re:The melting pot of JavaScript (2017) by Traubenfuchs on Wednesday January 09, 2019 @03:04AM (#18863119)
Instead of using a typed POJO you can deserialize/serialize a Map<String, Object>.

You could also use a POJO for the fields you know and put a map inside for the fields you don't know.

If that's not enough you can use JsonNode, or ObjectNode where you can freely add and remove json values.

Re:The melting pot of JavaScript (2017) by sonnyblarney on Wednesday January 09, 2019 @08:39AM (#18864559)
Ok, touché, good point.
Re:The melting pot of JavaScript (2017) by spricket on Tuesday January 08, 2019 @02:53AM (#18854018)
I actually like gRPC better than JSON these days so it saves me from that pain, code just gets generated for you.

But yeah json is much nicer in JS generally