Should JavaScript Get More Respect? 439
An anonymous reader points out an article in IBM's Crossing Borders series about the language features of JavaScript, surely the Rodney Dangerfield of scripting languages. But with increasing use in such technologies as Ajax, Apache Cocoon, ActionScript, and Rhino, some industry leaders are taking a fresh look at the language. From the article: "Nearly every Web developer has cursed JavaScript at one time or another. Until recently, many developers had all but written off JavaScript as a necessary evil at best or a toy at worst... But JavaScript is becoming increasingly important, and it remains the most broadly available scripting language for Web development."
Re:Why the pressure ? (Score:4, Informative)
Security is a problem (Score:2, Informative)
The main problem with writing games with some of the most applicable web tools out there (Javascript, Flash) is that once it hits the web anyone with access to the View Source command can steal your work and throw it on their own site as theirs. This is highly discouraging.
Nowadays I do use Javascript and Flash extensively, but the most significant part of any game machinery is always on the backend somewhere, usually in PHP.
Re:Yes, but Javascript is a bad language. (Score:4, Informative)
I love the autopointerage & hate the scope iss (Score:5, Informative)
allow me to elaborate, suppose you want to know if the version of the language on your platform supports an intrinsic array push function, and if not, attatch your own: firstly the reference to
sticking with arrays you can grow and shrink them with little to zero fuss: magically the array is one index longer. you can just set arr.length and it will append or delete indexes for you.
you can also use this to assign functions to other object's handlers, most notibly events But this has brought up the thing that really really needs fixing, suppose i want that onclick function to pass some info to myFunction when i call it i have to do this so instead i've created a function inline to hold my custom function, firstly it's not immediatley obvious to what object the "this" applies. if i'm running this code in a class does the this mean the class or someObject, one hopes it means the someObject.
next is the scope issue i've talked about suppose i'm dynamically creating objects on the fly and want the callback to reflect the id thus every single object will pass the value of 10 to myFunction, because after the function has finished the instance of i in memory that was used is still sat there and every myFunction has been given a pointer to it, not the value it was when it was initialised!
so some oversights still exist, if only there were ways you could explicitly state "pointer to" or "value of" like in, oh, every other language including visual basic
Re:Yes, but Javascript is a bad language. (Score:5, Informative)
Because Javascript has no ways of dispatching: all functions (remember that Javascript methods are exactly like functions) use varags, and the arguments you ask for are but pointers to vararg cells.
Example:
It's not that JS functions "behave" like objects, JS function are objects, period. Callable objects maybe, but objects nonetheless, they're no different from strings, integers or lists in that aspect.
And this is one of the nicest features of the language (along with lexical scoping and complete closures)
What interpreters are available? (Score:2, Informative)
What sorts of shells interpret JS? I know of Mozilla's js shell [mozilla.org], and they also have a xpcshell (which adds XPCOM things to make it fully Mozilla-y). Sadly js shell has no built-in file access (it's a compile-time option you have to jump through hoops to enable, and buggy), and xpcshell has lots of XPCOM baggage.
Are there any others using different engines? Anything from Adobe (ActionScript) maybe?
Re:I love the autopointerage & hate the scope (Score:5, Informative)
That isn't really an oversight, it's the way closures work. Most functional languages let you create closures explicitly so the problem doesn't arise. Javascript does it automatically, and usually when you don't expect it. In Javascript, you can do:
That creates a closure for each handler, with its own copy of i, so they will all get the values you want. I have no doubt there are other ways to do it, but this works for me.
Re:I love the autopointerage & hate the scope (Score:1, Informative)
Re:JS (Score:4, Informative)
Granted you do try keep the sizes down but in some cases especially and EPG you do end up writing lots of code.
Re:JS (Score:5, Informative)
Re:Dense != Good ==Wrong: It's not dense (Score:2, Informative)
Re:Dense != Good (Score:3, Informative)
In my experience, Ruby is about twice as dense as Perl *in direct translation* (I have taken Perl libraries and translated directly to Ruby). It is even more dense when the code is idiomatic Ruby - that might be up to 10x. Idiomatic Common Lisp is about as dense as Ruby.
Yet, Perl comes out at 15 and Common Lisp comes out at 5 in that "programming languages comparison", and Java comes out above Common Lisp at 6. These results are completely ridicilous. They probably have some statistical correlation with reality for some kinds of programming with some kind of developers - they're just far from exact enough to be useful for specific language comparison, like you do above. (They're also a decade out of date.)
Eivind.
Re:Yes, but Javascript is a bad language. (Score:1, Informative)
Re:JS (Score:2, Informative)
document.write((i + ' bottles of beer on the wall,' + i + ' bottles of beer. Take one down and pass it around ' + (i-1) + ' bottles of beer on the wall\n');
}
I only had 3 lines.
A great Javascript debugger... (Score:1, Informative)
Ahem.
FireBug [joehewitt.com].
Re:JS (Score:2, Informative)
...as opposed to what? JS that isn't integrated...?
Perhaps I chose my phrasing poorly. The JavaScript interpreter is integrated into the browser, and has direct access to the web page's content. As opposed to Java applets, which are mostly isolated from the browser and the surrounding page content.
applet ['aplit ] noun - Computing A very small application, esp. a utility program performing one or a few simple functions.
I don't get my computing vocabulary from some unnamed dictionary. I get it from usage, and I've never heard anyone who isn't confused use "applet" in reference to JavaScript code. You wouldn't use it either, if you actually cared to communicate your thoughts clearly.
Re:Needs a Concatenation Operator (Score:3, Informative)
Your strcat() example is nice, but it can only ever concatenate two strings -- a limitation of the language. (JavaScript insists for every function to have an exact number of parameters; Perl functions can take as many or as few parameters as you like). So it soon gets unwieldy; you need separate functions to concatenate three or four strings. Or, more likely, to add different numbers of numbers:
function sum2(n1, n2) { return (n1 - (-n2)); }
function sum3(n1, n2, n3) { return (n1 - (-n2-n3)); }
and so forth.
I think awk has the best syntax for string concatenation
Re:Dear god no. (Score:2, Informative)
class foo:
def __init__(self, n):
self.n = n
def __call__(self, i):
self.n += i
return self.n
Re:Too Hard to unit test (Score:3, Informative)
Re:Dense != Good (Score:3, Informative)
Re:JS (Score:5, Informative)
Re:simplicity and power (Score:3, Informative)
The thing that makes it messy in C is C's strong typing, you would have to pass and return everything as strings, but this is to be expected since the problem is contrived to demonstrate the brevity possible with weak-typing. The trade off is that you don't know exactly what your dealing with. In well written scripts that's no big deal, in a system with thousands of source files written by dozens of programmers it will quickly turn your brain to mush.
It used to be that weak typing in a language was a BadThing(TM), now it's a "feature".
You're confusing weak typing with dynamic typing. C is not strongly typed; it has static weak typing. Languages like Java have static strong typing, Python and Ruby have dynamic strong typing, and PHP and Javascript have dynamic weak typing.
Re:Needs a Concatenation Operator (Score:3, Informative)
Re:JS (Score:3, Informative)
Of course everyone should know that Sun didn't invent the term "applet", no one is disputing that. However, when you start talking about applets in the context of web pages and web development, it's only logical to assume you're talking about Java applets, and certainly not bits of JavaScript. You don't use the term "applet" to describe bits of JavaScript unless you're very confused. To quote wikipedia [wikipedia.org] :-
I'm sure you can see why confusion should arise over incorrect use of the term "applet".
Re:Why the pressure ? (Score:1, Informative)
developing for a moving target (Score:3, Informative)
Unless the use is restricted to a highly controlled intranet setting it will be executed on an indeterminate set of runtime environments. Different browser vendors, different versions, different sub-builds... where does the madness end?
Unless you are doing something trivial you can wind up with several times the code necessary to get the job done on any one Javascript runtime. And bug testing? Well that takes far longer than it should for exactly the same reason.
I don't have a problem with the language itself. Or any one interpretation of the language to be more precise. But give me some solid footing.
Beef #2 - is your Javascript accessible to disabled users? Standard response: "F*** the disabled; they're a minority and we all know minorities deserve to be shot and pissed on." As I lack the Satanic vitriol necessary to punish people for unfortunate circumstances I find myself at odds with the Web 2.0 community.