I'm a fan of Javascript. It has proper lambdas, true lexical scope, will soon have TCO, and is a really flexable language.
But it's not without its warts, and this is one of the worst. Although it's sometimes fun to mess with, nonetheless.
To see this taken to one of its logical extremes, check out If Hemmingway Wrote Javascript's entry for Douglas Adams:
// Here I am, brain the size of a planet, and they ask me to write JavaScript...
function kevinTheNumberMentioner(_){
l=[]
/* mostly harmless --> */ with(l) {
// sorry about all this, my babel fish has a headache today...
for (ll=!+[]+!![];ll<_+(+!![]);ll++) {
lll=+!![];
while(ll%++lll);
// I've got this terrible pain in all the semicolons down my right hand side
(ll==lll)&&push(ll);
}
forEach(alert);
}
// you're really not going to like this...
return [!+[]+!+[]+!+[]+!+[]]+[!+[]+!+[]];
}
Lexical scope with async closures makes it very easy to write async code for example events in a gui or handling multiple clients in a server. Its a big deal.
The title is incorrect; you need "!" and the only reason why I clicked on the article was that doing it without "!" would be a BIG deal. The title of the original article is "A Javascript journey with only six characters" and the topic has been posted/reposted and explained more times than I can count on HN
This is an extreme demonstration of the validity of a delightfully snarky blog post by Robert Harper on how dynamic typing is actually static typing using a unitype:
A string is a Boolean is a number is a function, and braindead conversions can happen without anyone noticing. How does one keep their sanity using a language like that?
What the OP takes to the extreme is a property of weak typing, not dynamic typing.
These properties are separate issues. A language is either statically typed or dynamically typed, and it is also either strongly typed or weakly typed.
In a statically typed language, types are attached to variables. In a dynamically typed language, types are attached to values. Do note that many languages don't fit 100% into either category. (Note that the blog post you linked to calls types attached to values classes, but that distinction often isn't made so clearly.)
A weakly typed language performs implicit type conversions as it deems necessary, while a strongly typed language does no implicit type conversions. Most languages don't fit 100% into either category. Usually languages that are considered to be strongly typed still allow you to add integers to floating point numbers, for example.
It is possible for a dynamically typed language to be so strongly typed that it won't do any implicit type conversion, ever. Such a language would not allow you to, say, add an integer and a floating point number without explicitly converting one to the other.
It is also possible for a statically typed language to be so weakly typed that it implicitly converts types everywhere. Such a language might do the exact same things the OP uses, like converting a function to a string of its source code when adding it to a string.
Keep it straight in your head, and use strict comparison.
Hey, at least when JS implicitly converts your types, it actually does type conversion, rather than merely casting them, so you often get what you want (looking at you, C).
Does anyone know a good sandboxing technology to execute user written javascript in a safe way? (like, on other user machines or on the server)? I have some ideas like "learn programming" that would benefit from this immensely.
I knew about these languages but I've never understood how they were made. This is a fun, fantastic article! These articles make me excited about technology. Even bad ones.
If you don't like JavaScript's type coercion rules, fair enough. But if you're criticizing the fact that you can write JavaScript programs with nothing but punctuation characters, remember that no-one ever does so except as a joke, and that you can do ridiculous stuff in most languages. (Try Googling "obfuscated $YOUR_FAVORITE_LANGUAGE".)
[+] [-] qwertyuiop924|9 years ago|reply
But it's not without its warts, and this is one of the worst. Although it's sometimes fun to mess with, nonetheless.
To see this taken to one of its logical extremes, check out If Hemmingway Wrote Javascript's entry for Douglas Adams:
[+] [-] digi_owl|9 years ago|reply
[+] [-] djsumdog|9 years ago|reply
[+] [-] z3t4|9 years ago|reply
[+] [-] madflame991|9 years ago|reply
[+] [-] Jazcash|9 years ago|reply
[+] [-] kukx|9 years ago|reply
[+] [-] thehesiod|9 years ago|reply
[+] [-] tempodox|9 years ago|reply
https://existentialtype.wordpress.com/2011/03/19/dynamic-lan...
A string is a Boolean is a number is a function, and braindead conversions can happen without anyone noticing. How does one keep their sanity using a language like that?
[+] [-] jorams|9 years ago|reply
These properties are separate issues. A language is either statically typed or dynamically typed, and it is also either strongly typed or weakly typed.
In a statically typed language, types are attached to variables. In a dynamically typed language, types are attached to values. Do note that many languages don't fit 100% into either category. (Note that the blog post you linked to calls types attached to values classes, but that distinction often isn't made so clearly.)
A weakly typed language performs implicit type conversions as it deems necessary, while a strongly typed language does no implicit type conversions. Most languages don't fit 100% into either category. Usually languages that are considered to be strongly typed still allow you to add integers to floating point numbers, for example.
It is possible for a dynamically typed language to be so strongly typed that it won't do any implicit type conversion, ever. Such a language would not allow you to, say, add an integer and a floating point number without explicitly converting one to the other.
It is also possible for a statically typed language to be so weakly typed that it implicitly converts types everywhere. Such a language might do the exact same things the OP uses, like converting a function to a string of its source code when adding it to a string.
[+] [-] qwertyuiop924|9 years ago|reply
Hey, at least when JS implicitly converts your types, it actually does type conversion, rather than merely casting them, so you often get what you want (looking at you, C).
[+] [-] gloriousduke|9 years ago|reply
[+] [-] shp0ngle|9 years ago|reply
[+] [-] colejohnson66|9 years ago|reply
[+] [-] JohnDotAwesome|9 years ago|reply
[+] [-] Centime|9 years ago|reply
http://centime.org/jsfsck/
[+] [-] JelteF|9 years ago|reply
[+] [-] kukx|9 years ago|reply
[+] [-] Jazcash|9 years ago|reply
[+] [-] fibo|9 years ago|reply
I remember similar strange and interesting stuff in Perl, like the spaceship operator.
[+] [-] lell|9 years ago|reply
[+] [-] novaleaf|9 years ago|reply
[+] [-] techplex|9 years ago|reply
[+] [-] dougk16|9 years ago|reply
Used it a few years ago. It was a little finnicky to get working right but I was impressed at the time. No idea where the project is at nowadays.
[+] [-] wyager|9 years ago|reply
[+] [-] SomeHacker44|9 years ago|reply
[+] [-] sjclemmy|9 years ago|reply
[+] [-] joshschreuder|9 years ago|reply
https://www.youtube.com/watch?v=LG-ozmTnhdI
[+] [-] unknown|9 years ago|reply
[deleted]
[+] [-] keyle|9 years ago|reply
[+] [-] pvdebbe|9 years ago|reply
[+] [-] CiPHPerCoder|9 years ago|reply
Wondeful! A typo six words in.
[+] [-] omnimus|9 years ago|reply
[+] [-] amelius|9 years ago|reply
[+] [-] a_c|9 years ago|reply
[+] [-] arundelo|9 years ago|reply
[+] [-] atemerev|9 years ago|reply
And Perl codebase is huge. Perl is used quite heavily at Amazon, Booking.com and Yahoo, among others.
Say what you want about Perl, but it is fun and hacker-friendly. I enjoyed it for many years.
[+] [-] kqr|9 years ago|reply
[+] [-] unknown|9 years ago|reply
[deleted]
[+] [-] tofupup|9 years ago|reply
[deleted]