Should JavaScript Get More Respect?
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."
Java and Javascript? Why would anyone do that, since those two are not related other than the name. Sun developed Java, and Netscape developed Javascript. Totally independent of each other. I'm starting to get tired of people thinking that they have something to do with each other.
Posted by a Debian GNU/Linux user
Hey guys. I'm an online gamemaker, so 'toy' languages are right up my alley.
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.
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
If you don't risk failure you don't risk success.
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)
"The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
Sadly, when Javascript gets mentioned most people think of browser scripting. That's like thinking of MFC every time C++ gets mentioned... :(
What sorts of shells interpret JS? I know of Mozilla's js shell, 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?
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.
After writing javascript for the past 6 years on digital tv platforms, I can say I've seen EPG's, Games, Apps running on liberate based set-top boxes and various IPTV set-top boxes could be running apps of similar size at time too.
Granted you do try keep the sizes down but in some cases especially and EPG you do end up writing lots of code.
How about Mozilla firefox (or any of it's extensions).
Javascript is anything but dense. The most impressive part about the various flexible agents is that they are easily understandable programming patterns. That makes it very easy to make an assessment for which methodology you will employ.
"Progress comes from the intelligent use of experience."
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.
Doubting the existence of evolution is like doubting the existence of China: It just shows that you're uninformed.
Java 5 has vargargs.
for (i=25000;i=1;i--) {
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.
GETPKG - Package Management for Slackware
Beside the lack of a good way to debug your javascript code
Ahem.
FireBug.
...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.
For the grammar goons among us: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.
http://outcampaign.org/
It's not a "very minor" issue. It's fundamentally broken. Essentially, everytime you want to add numbers, you end up having to subtract a negative number instead, or use ParseInt() / ParseFloat() to force things to be numeric (concatenating strings seems to be the default behaviour of +). This just looks messy (and coming from someone who uses Perl, that's a damning indictment indeed).
.....
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
Je fume. Tu fumes. Nous fûmes!
Blargh. I should take a bit more time to think before posting. What I meant was:
class foo:
def __init__(self, n):
self.n = n
def __call__(self, i):
self.n += i
return self.n
How so?
one word check out the dojo toolkit www.dojotoolkit.org, then you can see which codesizes we are already dealing with. The dojo toolkit is not the only javascript codebase of significant size already outside in the wild, the more interactive the applications become the more you see toolkits of that size becoming the norm not the exception.
How about Dreamweaver? Have you ever looked at it's WYSIWYG code? All Javascript. In fact the entire UI is 90% Javascript.... you can customize the whole app by editing, you guessed it Javascript.
A fool throws a stone into a well and a thousand sages can not remove it.
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.
Python and Ruby may be "dynamic" in some sense, but in both of them string += int will cause an exception. They're strictly typed, just with dynamic binding. Javascript really is a bit odd in allowing += for both addition and concatenation, and giving no warnings if you mix types. That's the sort of fuzzy thing that you'd only expect in PHP.
I believe posters are recognized by their sig. So I made one.
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 :-
I'm sure you can see why confusion should arise over incorrect use of the term "applet".
In this world nothing is certain but death, taxes and flawed car analogies.
Scheme is a lisp dialect. Lispers and Schemers both agree on this. I'll take their word over your ranting.
The problem with developing Javascript code is that you are shooting at a moving target.
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.