News for hackers. Stuff that matters.
Re:Node.js: Some quick optimization advice by tambourine_man on Monday October 12, 2015 @12:25PM (#10375527)
Posted that yesterday, didn't get much traction.

Whenever I begin to convince myself that JS and Node are actually fine languages / environments to code on, some weird edge case like this pops up.

Not entirely sure if it's just its popularity, which is bound to expose its rough corners, or if it's fundamentally bad designed (written in 10 days in the late 90's, etc)

Re:Node.js: Some quick optimization advice by nostrademons on Monday October 12, 2015 @04:57PM (#10376919)
Pretty much every language that gets rapidly adopted has a lot of weird edge cases. You want to see weird edge cases, take a look at C++. Java got plenty of criticism too for things like the primitive/Object distinction, or that when they tried to fix it with autoboxing, it now meant that ordinary addition could throw an exception. And don't get me started on Perl or PHP.

The one possible exception may be Python, but this is because the PEP process requires that you very rigorously lay out interactions with existing language features, and Guido is pretty conservative at accepting them. This means Python evolves slower than many other languages, and the last attempt to fix many of the awkward rough corners (Python 3) led to a multi-year transition that adversely hurt Python's popularity for a long time.

As Bjarne Stroustrop said, "There are two kinds of languages: those that nobody likes, and those that nobody uses."

Re:Node.js: Some quick optimization advice by spion on Monday October 12, 2015 @01:36PM (#10375947)
I've had the same experience with node, but normally there aren't that many problems with V8 or the language itself. Most of the rough corners seem to be in node's core libraries.

IMO this is what we need:

* a better designed standard library. Maybe more like Dart's[1] - we already have Bluebird as the de-facto replacement for callbacks - all we need now are something like Dart's streams to fix the built in quirky streams.

* built from the ground up with optional types i.e. TypeScript or Flow (eliminates most of JS's type-related quirks while preserving most of the dynamism and duck typing and being very helpful when the time comes to refactor)

Now that typescript has support for type definitions inside node_modules[2] there are no barriers remaining to do this. node + V8 + typescript can provide a development experience that matches Dart (exceeds it in some cases, e.g. REPL) without throwing away the entire existing JS ecosystem in the process.

[1]: https://api.dartlang.org/1.12.1/dart-async/dart-async-librar...

[2]: https://github.com/DefinitelyTyped/tsd/issues/208

p.s. [2] can actually detect some situations in which there would be problems when multiple library versions coexist together (e.g. when you pass instances that come from library v3 to a function of library v2, explained in detail at https://news.ycombinator.com/item?id=8213273). However if the interfaces are structurally satisfied, the compiler will not complain. As a result I'm pretty sure that its possible to write a tool that detects semver violation based on .d.ts files (similar to what Elm does) or suggest the exact amount of version number increment by comparing the definition files

Re:Node.js: Some quick optimization advice by diggan on Monday October 12, 2015 @12:57PM (#10375737)
Well, to be fair. Node is not a language and this hack is not a "feature" or whatever of the language, rather it's a hack to get V8 to inline functions. JavaScript as an language is all right, but as always, making this language work and perform in multiple environments is tricky sometimes.
Re:Node.js: Some quick optimization advice by draperp on Monday October 12, 2015 @05:03PM (#10376948)
Sure. And CPython isn't a language. It's the canonical Python implementation that is used 99% of the time.

When it comes to non-browser production code (e.g. servers), it's NodeJS or nothing.

Re:Node.js: Some quick optimization advice by to3m on Monday October 12, 2015 @02:34PM (#10376238)
I don't think it's fair to blame something like this on Javascript per se, but that doesn't mean it isn't fundamentally badly designed ;) However, people actually appear to have started to notice this, and the latest result, ECMAScript 6, looks actually like it might be OK. At last, when people tell you JS isn't that bad, you can actually believe them - though if they told you that before, maybe do your own research too.

With the latest version, you have block scope, you have a shorthand function syntax, the "this" nonsense is teeny bit less awful, there's help at hand for the inevitable callback chains, and strict mode is still there. There's also a new class syntax (though actually - aside from "this"! - I thought the old-style classes were the least of its problems).

I won't apologise for rolling my eyes a bit at how it's taken until ver 6 to get block scope, but better late than never.

Re:Node.js: Some quick optimization advice by xlm1717 on Monday October 12, 2015 @12:37PM (#10375606)
>written in 10 days in the late 90's

Netscape browser has not been used in a long time, and JS has been standardized as ECMAScript since the late 90's.

Re:Node.js: Some quick optimization advice by nikolay on Monday October 12, 2015 @02:37PM (#10376253)
"Standardized" does not equate "good" though. ECMAScript is a very confused language that keeps borrowing from other languages and turns itself into a mess. Not to mention that "Universal JavaScript" is an oxymoron as most real-world JavaScript (well, ECMAScript) is not supported by major browsers and developers need to use things like Babel and the likes. And I don't see an end to it.
Re:Node.js: Some quick optimization advice by abritinthebay on Monday October 12, 2015 @03:22PM (#10376481)
> a very confused language that keeps borrowing from other languages and turns itself into a mess

I could describe almost any language that builds on previous language idioms like this. C++, most of the later Lisps, Java for sure, C# especially, Objective-C certainly... etc.

You're assuming your conclusion then trying to prove it with personal opinion.

Re:Node.js: Some quick optimization advice by nikolay on Monday October 12, 2015 @04:52PM (#10376899)
Well, JavaScript became popular, because it was omnipresent and was simple (so that even Web Designers without a Computer Science degree could use it). Now, there are vast differences between browsers and the toolchain has grown huge.

We need to revisit the scripting in browsers. Instead of twisting arms to use "JavaScript", because of it "universality", we should focus on WebAssembly and the likes. Have a safe scripting VM in the browser, use any language that compiles to it - no need for Babel and the likes.

Re:Node.js: Some quick optimization advice by abritinthebay on Monday October 12, 2015 @07:16PM (#10377441)
> we should [...]

No, again, you're reforming "I would like..." into "we should". There's no should about it.

JavaScript is nowadays quite a nice language. ES2015 and the way forward gives us a language that could happily go for another 20 years with few issues.

WebAssembly doesn't solve the problem btw - most of the things people hate on JS about (that aren't just dumb "I don't like loose typing or understand prototypical inheritance" complaints anyhow) are to do with how it integrates with the key web feature: the DOM.

DOM is where everything goes to hell on the web and it's going to be just as much of a mess in C/Rust/Haskell/Clojure/brainfuck as it is in JavaScript.

Also your comment about Babel is just strange. The reason to use Babel is to support older parsers that only understand ES5 syntax. That's never going to go away. We'll be dealing with older parsers for 10 years after WebAssembly launches - so guess what? Now your toolchain got longer, more complex, and you still have to output JavaScript anyhow.

Yaaaaaay.

Or, you know, you could learn JavaScript properly and realize that it's a completely useful and great language that is just as good as whatever your pet favorite is when applied to the tasks at hand.

Re:Node.js: Some quick optimization advice by mwfunk on Monday October 12, 2015 @05:42PM (#10377110)
People have been revisiting scripting in browsers for 15+ years. The hard part isn't getting everyone to revisit scripting in browsers. That's the easy part. If Google couldn't make it happen despite their efforts with Dart, I don't who else could. :( The push wouldn't come from the W3C either. I suspect that in 5-10 years, we will have a safe scripting VM in the browser, but it's still going to be JavaScript.