News for hackers. Stuff that matters.
Re:JavaScript is Web Assembly Language and that's OK. by tg3 on Friday May 24, 2013 @09:26AM (#5762532)
Javascript is not just a "quirky scripting language for minor workflow events." It is a powerful, expressive language, that has many benefits over contemporary languages, regardless of setting. Yes, it has quirks, and yes, there are some things that coming from another language are difficult to grasp, but it is not a Bad Language.

The fact that Node.js, Javascript on the server, is gaining so much popularity in the developer community means that it has benefits beyond its universality in the browser.

Asm.js is not a "hack on the top of the mess", it's a simplification of "the mess" down to it's simplest, most bytecode-esque parts. And it's performance is shockingly close to Native.

Javascript is not the perfect bytecode for the web. But it does work as a bytecode for the web, and with asm.js, it seems that it works decently well. I think efforts are better spent improving Javascript, asm.js, and languages that can target it rather than swimming upstream.

Re:JavaScript is Web Assembly Language and that's OK. by Herald_MJ on Friday May 24, 2013 @09:35AM (#5762603)
> Javascript is not just a "quirky scripting language for minor workflow events." It is a powerful, expressive language

I didn't say it was just for minor workflow events, I said it was created for minor workflow events - it's just good fortune that Brendan Eich was an experienced language designer and created something that was powerful and extendable enough to bring us to the situation Javascript is in today.

It's certainly powerful (particularly considering it's original intentions), I disagree that it's expressive in comparison to other modern languages.

Why anyone thinks server-side javascript is a good idea is beyond me.

Re:JavaScript is Web Assembly Language and that's OK. by marknutter on Friday May 24, 2013 @09:38AM (#5762623)
> Why anyone thinks server-side javascript is a good idea is beyond me.

That someone would want to use the same language to write both their client and server side code is beyond you?

Re:JavaScript is Web Assembly Language and that's OK. by jfb on Friday May 24, 2013 @09:58AM (#5762755)
Largely, yes. The problem domains are different. The usage patterns are different. The constraints are different. Why not be pragmatic and pick an appropriate technology for each use case?
Re:JavaScript is Web Assembly Language and that's OK. by mwcampbell on Friday May 24, 2013 @11:08AM (#5763263)
I can think of two ways to interpret this.

Perhaps you believe that in web applications, all of the real computation happens on the server, and JavaScript is just for providing a nice UI. Some people probably want it to be this way, so they can do most of the work in their preferred language and runtime environment, and only deal with JS for the minimum of client-side work. But to take this approach is to leave unused the embarrassment of riches that we have in computing power on the client side, even in smartphones. If we make full use of that client-side computing power, we can reduce server resource consumption and, more important from a user's perspective, the need to incur the cost of network round trips.

Or maybe you think that in modern web applications, most of the complex logic belongs on the client side, and the server is mainly for receiving, storing, and sending data. In that case, perhaps you think the most important attribute of a server-side language is performance. But it's probably quite rare for the server side of a real web application to be a dumb data store. So what happens if you wrote some non-trivial logic in JS, then discover that it needs to run server-side?

I think we're still figuring out what belongs on the client and what belongs on the server. Therefore, I think using the same language on both sides might have some benefit. Admittedly, I've never written a real application with Node.js, and the thought of callback spaghetti everywhere doesn't exactly appeal to me. But I might accept that in return for maximal code re-use.

Re:JavaScript is Web Assembly Language and that's OK. by kybernetikos on Friday May 24, 2013 @12:41PM (#5763943)
I don't think callback spaghetti is an absolute requirement of programming in Node.

I think this article says it quite well: Callback Hell is a Design Choice : http://blog.caplin.com/2013/03/13/callback-hell-is-a-design-...

Re:JavaScript is Web Assembly Language and that's OK. by WayneDB on Friday May 24, 2013 @04:22PM (#5765013)
One does not have to believe that "all of the real computation happens on the server" to not want to use Javascript if one doesn't have to.

Where are these mythical Node.js applications that share so much code with the client though? What functionality is shared and how much time did it save anyone?

Personally, I wouldn't trust one browser-land function or library in my server application without digging through every line of code to make sure it's not going to do some browser-specific hackery. Then what have I saved? I'd rather go get a separate module that was built specifically for Node.js.

Then there's the time I'd save sharing my own code between Node.js and browser - which would be next to nothing because any time I save would be spent having to think about platform differences anyway.

Re:JavaScript is Web Assembly Language and that's OK. by mambodog on Friday May 24, 2013 @10:44AM (#5763086)
I'd argue that many applications have plenty of concerns for which sharing code between the server and client is clearly pragmatic: http://nerds.airbnb.com/wp-content/uploads/2012/10/shared-js...
Re:JavaScript is Web Assembly Language and that's OK. by marknutter on Friday May 24, 2013 @10:18AM (#5762903)
> Why not be pragmatic and pick an appropriate technology for each use case

I suppose you know what's appropriate.

Re:JavaScript is Web Assembly Language and that's OK. by jfb on Friday May 24, 2013 @10:35AM (#5763026)
Defensive much? All I was saying is that I don't find the "uses the same language" argument dispositive.
Re:JavaScript is Web Assembly Language and that's OK. by marknutter on Friday May 24, 2013 @11:03AM (#5763224)
I don't mean to be defensive, I personally don't use JS on the server side, but I don't see any problems with other people doing it. No more than I would have problems with people using, say, Ruby.
Re:JavaScript is Web Assembly Language and that's OK. by WayneDB on Friday May 24, 2013 @04:33PM (#5765061)
You responded to someone who said "I disagree that it's expressive in comparison to other modern languages."

Why would a person of that opinion value a small amount of code sharing over language expressiveness? So, there's your answer as to what they're imagining.

Regarding code sharing - maybe you can answer another post in this thread which I ask, "Where are these mythical Node.js applications that share so much code with the client...?"

Re:JavaScript is Web Assembly Language and that's OK. by Herald_MJ on Friday May 24, 2013 @09:39AM (#5762627)
When that language is javascript, yes.
Re:JavaScript is Web Assembly Language and that's OK. by mwcampbell on Friday May 24, 2013 @10:23AM (#5762939)
Have you ever worked on a non-trivial JavaScript application? I'll define that as 10,000 lines or more. I ask because I suspect that this comment is simply a visceral reaction to some flaw in JS, and I want to know if that reaction is based on experience.
Re:JavaScript is Web Assembly Language and that's OK. by Herald_MJ on Friday May 24, 2013 @10:37AM (#5763043)
I have worked on what I would call non-trivial Javascript applications, but only front-end javascript (no server-side js, apart from a few MongoDB map-reduce queries).

My feelings towards js are are informed by that experience, and my (happier) experiences with other languages - which are primarily Python, Java and Objective-C, if you're interested.

Re:JavaScript is Web Assembly Language and that's OK. by jiggy2011 on Friday May 24, 2013 @10:54AM (#5763159)
Code reuse is an advantage I guess. For example you want fast responsive validations as the user enters data, but for security reasons you need to do final validations on the server.

You have objects on the client that you want to persist to the server but you don't want to have to write two models.

Re:JavaScript is Web Assembly Language and that's OK. by smrtinsert on Friday May 24, 2013 @11:29AM (#5763417)
I agree, its a mess with regard to expression - isn't that why this thread exists? The language is fun to write but eye-gouging to maintain. Of course you could apply strict conventions to make it maintainable, but at that point you might as well be in a statically typed language working at full speed in an ide.

After coding JS by hand for years (while doing other languages) I'm done with it. I'm ready to go preprocessor full time, either static language based but also interested in lisp variants, because if I have to go typeless, might as well do it in style.

I tried CoffeeScript for a while, but the philosophy is too similar to JS to keep my interest. It did reduce the code dramatically though, on avg about 70%.

Re:JavaScript is Web Assembly Language and that's OK. by kybernetikos on Friday May 24, 2013 @12:44PM (#5763959)
> Of course you could apply strict conventions to make it maintainable, but at that point you might as well be in a statically typed language working at full speed in an ide.

Not really. We do the strict conventions thing and have had a lot of success with it. Being able to run in a browser is a huge, huge advantage. If I had a nice statically typed language that gave me that advantage as well as javascript does, I'd probably switch to it, because by inclination I prefer the compiler to do more work for me, but there's no way I want to leave behind having my code work for anything with a browser and f5 to see my code in action.

Re:JavaScript is Web Assembly Language and that's OK. by mwcampbell on Friday May 24, 2013 @11:54AM (#5763636)
I see your point, but JavaScript is much more popular than any of the other languages designed to compile to it. Thus, even if one works in a restricted and somewhat tedious subset of JS (such as the one encouraged by the Google Closure Compiler and used by the Closure Library), wouldn't it still be easier to find already-qualified developers than if one uses Haxe or ClojureScript or Dart?
Re:JavaScript is Web Assembly Language and that's OK. by tg3 on Friday May 24, 2013 @10:01AM (#5762770)
Server-side Javascript, in particular Node, is much better suited to event-driven applications (e.g. web servers) than a lot of other languages out there, including Ruby (and dare I say Python?).
Re:JavaScript is Web Assembly Language and that's OK. by mwcampbell on Friday May 24, 2013 @11:23AM (#5763363)
This time I'll argue the other side.

A lot of web applications routinely do many I/O operations per request handler. For example, do a DB query, then do something with that data, then conditionally do another DB query based on the results of the first, then do something with that data, then query a REST Web service, and so on. Blocking APIs make this very natural; add high-level abstractions such as an ORM, and you don't even think about the fact that you're doing I/O. With something like Node, application code of this sort degenerates into callback spaghetti, unless you use something like the fiber module, or a compiler that transforms the natural, straight-line code into continuation passing style. Though I've previously argued for the potential advantages of using the same language for both the client and the server, I fail to understand why something like the fiber module isn't standard in Node, or why the kind of compiler I described isn't more popular. Perhaps that's just dogmatism or a cargo-cult mentality.

An event-driven system might be good for "real-time" applications where many clients connect and wait to have things pushed to them. Even then, I think coroutines or lightweight threads would be fine, as long as they're the norm for a runtime environment and its standard library (e.g. Go, and Haskell IIUC) and not bolted on (e.g. Python's eventlet and gevent).

Re:JavaScript is Web Assembly Language and that's OK. by tg3 on Friday May 24, 2013 @04:20PM (#5765001)
The fact that most web applications do many I/O operations per request handler and the Blocking API's make it very natural so that "you don't even think about the fact that you're doing I/O" is precisely the problem. I/O is an eternity compared to computing cycles, and to have the entire thread blocked while waiting for I/O to complete means that you can have exactly one concurrent client.

Node can easily degenerate into callback spaghetti, that's true. But I think that has more to do with the paradigm being new to a lot of developers. Using promises and similar constructs are a very natural way to deal with callbacks, and reduce the spaghetti significantly. Unfortunately, they won't be baked into Node's core.

Even for a standard CRUD app, you can get way more performance out of Node than you can out of, say, Rails, precisely because it is highly concurrent.

Re:JavaScript is Web Assembly Language and that's OK. by wslh on Friday May 24, 2013 @10:06AM (#5762804)
> I said it was created for minor workflow events

I remember those times when Javascript was only used for changing button images in the mouse over event! It was a powerful extra to designers to have this knowledge.

Re:JavaScript is Web Assembly Language and that's OK. by mbesto on Friday May 24, 2013 @09:45AM (#5762659)
The fact that Node.js, Javascript on the server, is gaining so much popularity in the developer community means that it has benefits beyond its universality in the browser.

The fact that Node.js is becoming popular is simply a symptom of having a ridiculously large ecosystem of developers, and not much else.

Re:JavaScript is Web Assembly Language and that's OK. by mwcampbell on Friday May 24, 2013 @09:53AM (#5762713)
A ridiculously large ecosystem of developers is a huge feature that we ignore at our peril. I think a mature developer should overlook aesthetic quibbles with a language, framework, or any other tool, and make decisions based solely on what's most practical.
Re:JavaScript is Web Assembly Language and that's OK. by mbesto on Friday May 24, 2013 @11:18AM (#5763323)
we ignore at our peril.

Yup, developers do. But clients and users don't. Just make it work!

Re:JavaScript is Web Assembly Language and that's OK. by lttlrck on Friday May 24, 2013 @12:47PM (#5763985)
Who just so happen to be creating a lot of great libraries in a popular domain.
Re:JavaScript is Web Assembly Language and that's OK. by bradleyjg on Friday May 24, 2013 @09:52AM (#5762701)
tg3 circa 2002:

The fact that PHP is gaining so much popularity in the developer community means that it has benefits beyond its universality in shared hosting environments.