Live data from Hacker News

Fogus: Node.js should become its own language

blog.fogus.me

51–60 of 79 posts

Re: Fogus: Node.js should become its own language

#51
post #10
post #9

Earlier quoted context omitted.

Except that Javascript has lexical scope. Use the var keyword to define local variables. foo = function(){ var bar=0 return function(){ bar=bar+1 return bar } } baz=foo() baz() // => 1 baz() // => 2 baz() // => 3 bar; // => ERROR: bar is not defined

They're "hoisted" and only local to the function, though. I'd (personally) prefer it if it worked like C, and a variable was defined from the "var" statement until the next closing brace. Then you could have a variable local to one branch of an if statement, etc, without faking scopes by abusing closures (eg (function() { })(); ). And nested loops that both use "i" would work.

"I'd (personally) prefer it if it worked like C, and a variable was defined from the "var" statement until the next closing brace."

It does work like C. The scoping you're talking about was introduced in C99.

Re: Fogus: Node.js should become its own language

#52

Earlier quoted context omitted.

" The "faults" of javascript are primarily inexperience with event looped architectures that use callbacks " Maybe for a lot of people this is true, but for me the faults of javascript are ingrained language "features". Actually, I'm not the only one who thinks so, because theres a website dedicated to it[1]. [1] http://wtfjs.com/

The latest example on that blog (from Feb. 5th) examines the unexpected effects of type coercion when using double-equals for comparison. That's fine, as far as it goes, but, like most of these examples, it's a WTF that experienced JavaScript developers know how to mitigate (triple-equals) and not that big of a problem in practice. I'm trying to think of a time that JavaScript's wacky coercion rules actually bit me a…

Well, the wacky coercion rules are just one of many Javascript gotchas. I agree that most of them won't affect an experienced javascript programmer, but that doesn't mean its not a language fault. For example, in C, most programmers will know to check bounds or to use strncpy instead of strcpy, but a lot of C code that has buffer overruns still slips through.

My point is that any language fault can be memorized and worked around, but that doesn't make it go away. Also, I've noticed a lot of non-experts using javascript, so if the obvious solution isn't the correct one (using == vs using === for example), then that does cause real problems.

Note that I'm not saying Javascript is an especially bad language, just that it has, in my opinion, some severe faults.

Re: Fogus: Node.js should become its own language

#53
post #37

Earlier quoted context omitted.

Javascript itself has very few faults. We disagree. Signed, Douglas Crockford, Jeremy Ashkenas, and Brendan Eich

Could you elaborate?

Crockford wrote a book titled "JavaScript: The Good Parts", which more or less implies there are bad parts as well.

Re: Fogus: Node.js should become its own language

#54
post #49

How about Node.as? Flash doesn't get much love these days but I've always thought ActionScript 3 would make a great server side language. It's more like other OOP languages, has an event model like JavaScript (sync or async), and doesn't have many of JS's idiosyncrasies. Edit: http://haxe.org/ is based on AS3

I agree. I had to go back from AS3 to AS2 for a project and it felt like a step backwards, and AS2 is more like Javascript. Adobe has also open sourced the AS3 runtime. But of course the practicality is that we have Javascript in browsers, and there's a big get-the-job-done benefit to using a common language.

Re: Fogus: Node.js should become its own language

#55
post #9

Earlier quoted context omitted.

Except that Javascript has lexical scope. Use the var keyword to define local variables. foo = function(){ var bar=0 return function(){ bar=bar+1 return bar } } baz=foo() baz() // => 1 baz() // => 2 baz() // => 3 bar; // => ERROR: bar is not defined

Try this: for ( var i = 1; i You might expect it to alert 1..2..3..etc. It actually alerts 10..10..10..etc.

Python does this as well.

Personally, I would like to be able to choose the capture method, but having value capture the default. Most of my code simply wants the value, but occasionally, capturing the variable is needed.

Re: Fogus: Node.js should become its own language

#56
Take a look at this, I am sure it has been posted on HN before: http://beamjs.org/

This allows you to trade off all the cool speed of V8, but running node.js singlethreaded, for running on an alpha port of V8 for the Beam VM. If you want to sidestep the problems with Node.js, but keep the good parts, this might be a way forward. Additionally, JS on the Beam VM can seamlessly interact with any other Erlang code, so you get all kinds of other benefits that are erlangy.

Re: Fogus: Node.js should become its own language

#57
post #43
post #26

Earlier quoted context omitted.

> It's not deceptive if you have a preemptively multitasking runtime that you trust That may be so, but since Javascript is inherently single threaded _and_ this is about javascript I agree with Cushman that it is indeed deceptive.

But we aren't talking about Javascript. It's about a theoretical replacement language. Also, the reason you care about the "synchronicity" in the first place is because your environment forces you to care! When it all Just Works (TM), you don't care whether it's "synchronous" or not. That's a deficiency in your language, not a feature. I'm not theorizing. I program in this sort of language all the time. You worry muc…

[deleted]

Re: Fogus: Node.js should become its own language

#58
post #8

Earlier quoted context omitted.

My most common annoyance about Javascript is the lack of bound methods like in Python Ruby etc. When you specify callbacks, you always have to provide the value of 'this' as well. If you forget, it's basically random and you're in for some heavy debugging.

'this' is evil in Javascript. The very first line in any constructor function that I write is: var that = this; From then on, I use 'that' instead of 'this', relying on closure magic to make things work. You never have to worry about how the function is bound thereafter.

Thanks. I think I like that solution, as it's extremely simple. Are there any drawbacks?

CoffeeScript is cool, as it is basically "Python in JS" but I have some resistance against languages that convert to other languages. I'm not so sure why.

Re: Fogus: Node.js should become its own language

#59
post #11

I prefer coffee-script. It also works in the browser. http://jashkenas.github.com/coffee-script/

Seriously, CoffeeScript is amazing. I've been working on a large client-side project in CoffeeScript for the past few weeks and every time I look at the resulting JS output I can't imagine having written it by hand; it's been a massive boon to my productivity. I wrote JavaScript for years before this and hated it at times, and now I can't ever imagine going back if given the choice.

CoffeeScript is much easier to read than javascript, that alone is a blessing. Admittedly I haven't used coffeescript much yet, I just cranked it up with nodemon a couple of weekends ago. I need a good starter coffeescript project that works on the backend with node, and the client side.

Re: Fogus: Node.js should become its own language

#60
post #48

Since fogus is responding here: Other than hitching your wagon onto the fantastic hype storm that Node.js has generated, which I must say is a good move overall, reading your target description, why not start with Haskell or Erlang? You could start from there and mutate out but actually have a library base to start from. Or one of the languages sitting on top of Erlang like Reia. (Or discover that you don't need to m…

I will upvote you if you explain what you mean by the last part about "this style of programming" previously being on its (it's? anyone) way out. Do you mean an asynchronous style using callbacks?
Post reply on HN