Live data from Hacker News

JavaScript: It’s Not Just for Browsers Any More

pragprog.com

61–70 of 93 posts

Re: JavaScript: It’s Not Just for Browsers Any More

#61
post #12

Earlier quoted context omitted.

For me it is about consistency. With javascript on the client and the server, it's easier to write code once and move it around. Compared to having to write perl, java, php, whatever on the server side and javascript on the front. It reduces the learning curve for new developers because they only have to learn javascript, not javascript plus something else.

I run into this all the time. The most common case is form validation. If you want to do some validation on the client side, why are you forced to repeat yourself by writing it once in Java/Ruby/Python/Perl/PHP on the server and then write it again on the client using Javascript/Underscore/JQuery/whatever? http://github.com/raganwald/homoiconic/blob/master/2010/02/d...

Could it be that your form validation example is merely a symptom of not working at a high enough level of abstraction?

In the rails world, for example, if you've done your validates_* declarations on an ActiveRecord model, it shouldn't be too difficult to generate the javascript required for client-side validation.

Actually found a project that goes a long way towards achieving just that: http://github.com/grimen/validatious-on-rails

But I guess you're referring to complex validations, expressed as code instead of validates_* declarations. It seems like you would prefer either an all-JS approach or an automated translation to JS, as per the blog post you linked. To me, it boils down to whether such a complicated validation is really appropriate for client-side validation and whether it blurs the lines between form validation and business logic to such an extent that it's better off just living on the server.

But I'd love to hear your further thoughts on the matter.

Re: JavaScript: It’s Not Just for Browsers Any More

#62
post #37

Earlier quoted context omitted.

It's a nice clean language that fits the event-driven paradigm better than most. When every function is an automatic closure, things are much easier.

I'm really at a loss as to how people seem to just swallow this claim without question. What's so special about Javascript's closure support vs Perl, Python, Ruby, PHP, Lua, C#, Lisp, Erlang, or ${all other functional languages}? What's Node.js got over Twisted, POE, EventMachine, or every single thing ever written in Erlang? Most languages used in web development have closures. A large number of them have event-base…

Python has no true anonymous functions.

Ruby is just a mess in this regard,even if you can arguably do anything you want in the end : http://innig.net/software/ruby/closures-in-ruby.rb

On the other hand, javascript has a simple, no bullshit syntax for functions. If you want a function to be anonymous, just don't give it a name.

Erlang and Lua obviously have true anonymous functions and closure support.

Re: JavaScript: It’s Not Just for Browsers Any More

#63

Earlier quoted context omitted.

I know that not a lot of people would agree with me on that one, but i'd argue that JavaScript is a better designed language than Python or Ruby on a lots of points. It's simpler than both regarding the core language features, and is also the only one of the three to have real anonymous functions. I'm not fond of C syntax, but i can live with it

> is also the only one of the three to have real anonymous functions What are you talking about?

I'm talking about that :

http://news.ycombinator.com/item?id=1171471

Arguably i took a bold step regarding Ruby, which has them, but is confusing in this regard since blocks are not anonymous functions, and are the idiomatic and preferred construct in ruby. The problem is deeper than that , but Paul Canter does a much better job than me explaining why

Re: JavaScript: It’s Not Just for Browsers Any More

#64
post #39

Earlier quoted context omitted.

Well Python's lambda's kinna suck for one. As far as I know, Python, Ruby, and PHP all suffer from the fact that all functions are not first class. Also Javascript's prototypal inheritance is pretty neat. I'm not saying js is a "great" language, it's not with out it's crufty bits, but it's a nicer language than most people give it credit for.

"Well Python's lambda's kinna suck for one." Not really relevant in this context, as naming things isn't that big a deal. Lambdas are only needed for one-liners and they serve that purpose fine. "As far as I know, Python, Ruby, and PHP all suffer from the fact that all functions are not first class." Definitely false for Python, Ruby actually has multiple kinds of first-class functions (for better or for worse, I am…

Can someone explain to me why the answer is five? Appreciated.

Re: JavaScript: It’s Not Just for Browsers Any More

#65

Earlier quoted context omitted.

> is also the only one of the three to have real anonymous functions What are you talking about?

I'm talking about that : http://news.ycombinator.com/item?id=1171471 Arguably i took a bold step regarding Ruby, which has them, but is confusing in this regard since blocks are not anonymous functions, and are the idiomatic and preferred construct in ruby. The problem is deeper than that , but Paul Canter does a much better job than me explaining why

I actually like the approach in Ruby, because the syntax for passing a single anonymous block (which corresponds to 90% of all cases) is really light and people have used it practically for adding syntax to Ruby.

What differentiates Ruby from Javascript (or Python for that matter) is that when defining a function using regular syntax, its name is not a variable referring that function in the scope it was declared ... what Python and Javascript are doing. And that's a trade-off that some people like it, because in Ruby you can call a function without parens and it doesn't really get in your way when wanting to do crazy shit with already declared functions.

On Python, it may not have anonymous functions, but it has true first-class functions and true closures. It's only a problem for async code because you want to have the declaration of a closure after you see the call-site that's using that closure, not before it. But in practice that's not so awful ... and if you really really want multi-line anonymous blocks there are hacks you can do with the "with" block.

In this regard Javascript is cleaner, but it is messier in other places. I don't like that its a loosly-typed language for instance (haven't we had enough of that?).

I don't like that it doesn't provide class-based OOP ... and while you can build it on top of prototypes, it's a PITA not having a standard. And class-based OOP is mapped better to the way we think, having a bad reputation only because a couple of popular languages have plagued us with bad implementations ... but people should really take a look at Smalltalk before throwing the baby out with the bathwater.

Re: JavaScript: It’s Not Just for Browsers Any More

#66

Earlier quoted context omitted.

When was "C-Like Syntax" ever a good reason? I want something I can read naturally, like Ruby or Python.

He means that there's a critical mass of developers who will take one look at a syntax and move on if it doesn't have curly braces and semicolons. It's not that they're enamored with having a needlessly awkward syntax for function pointers, it's just that a syntax that isn't 95% of the way to Java just looks freaky weird to them, end of story. I don't disagree that syntax matters, but C's is hardly a shining example.…

Sigh. You're right and I hate it. :(

Re: JavaScript: It’s Not Just for Browsers Any More

#67
post #45

Earlier quoted context omitted.

JS has three epic wins going for it, that cannot be matched together by another language: * A shitton of people are already using it on the daily * All of the existing code written in it is event-driven * It's got prototypical inheritance, and some people actually use it instead of bludgeoning in classicism

Your second and third points have been matched by Erlang, and for longer too.

Yeah, but it is the first point that matters, and when matched with two and three the real power comes.

Re: JavaScript: It’s Not Just for Browsers Any More

#68

Earlier quoted context omitted.

I'm talking about that : http://news.ycombinator.com/item?id=1171471 Arguably i took a bold step regarding Ruby, which has them, but is confusing in this regard since blocks are not anonymous functions, and are the idiomatic and preferred construct in ruby. The problem is deeper than that , but Paul Canter does a much better job than me explaining why

I actually like the approach in Ruby, because the syntax for passing a single anonymous block (which corresponds to 90% of all cases) is really light and people have used it practically for adding syntax to Ruby. What differentiates Ruby from Javascript (or Python for that matter) is that when defining a function using regular syntax, its name is not a variable referring that function in the scope it was declared ...…

> it doesn't really get in your way when wanting to do crazy shit with already declared functions

That's something i don't like about ruby. You can do crazy shit but it leads to code wich is opaque for somebody that doesn't truly know ruby inside out. The language is full of tricks. But i don't want a full of tricks language. I want a simple language that doesn't get in my way, and doesn't provide 7 ways and 3 different mechanisms to do closure like constructs (numbers are not made up)

> On Python [...] if you really really want multiline anonymous blocks, there are hacks you can do with [...]

Well yeah i really really want them, and no i don't want to resort on hacks to use them.

I really have trouble understanding the rationale behind all those half baked constructs. The way Lua/Javascript/Scheme does it is the way to go IMHO : provide one mechanism that is simple and works well. You may loose some convenience or conciseness in the process (compared to ruby blocks for example), but what you gain is one consistent way to do things.

About javascript OO, i admit that it doesn't bother me as much as it seems to bother you, and that it may be linked to the uses i have had for javascript yet, but i have to say i indeed had more pleasure working with python/ruby object models than with javascript at the moment. I can't say if that is due to a superior mechanism or to familiarity with class based models though.

Re: JavaScript: It’s Not Just for Browsers Any More

#69
post #39

Earlier quoted context omitted.

"Well Python's lambda's kinna suck for one." Not really relevant in this context, as naming things isn't that big a deal. Lambdas are only needed for one-liners and they serve that purpose fine. "As far as I know, Python, Ruby, and PHP all suffer from the fact that all functions are not first class." Definitely false for Python, Ruby actually has multiple kinds of first-class functions (for better or for worse, I am…

Can someone explain to me why the answer is five? Appreciated.

i is a mutable variable declared in the enclosing scope. The for loop mutates it, and each anonymous function closes over i. After the loop is finished (when func[3]() is called, i is equal to 5.

I'm not sure what makes this a "quirk" since this is exactly what closures should do: they maintain a reference to the variable from the enclosing scope. This is also the behavior of a fairly classical example of closures in scheme.

Re: JavaScript: It’s Not Just for Browsers Any More

#70

Earlier quoted context omitted.

Your second and third points have been matched by Erlang, and for longer too.

Yeah, but it is the first point that matters, and when matched with two and three the real power comes.

1. People are forced to use javascript.

2. There are a lot of people who use erlang.

Post reply on HN