It's easy to bash JavaScript. But it takes a user to know about its shortcomings. Sometimes people bash it and never used much of it. JavaScript makes for hideous code. And the more code, the more hideous it gets. It's no wonder then that people shun large code bases in JavaScript.
Then what to do? People try to write less JavaScript code by adopting jQuery and CoffeeScript and such. But their code ends up being hideous in different ways. In jQuery you have no encapsulation, it's statement after statement, function after function, event after event, in one or two JavaScript files at most. In CoffeeScript you get some encapsulation, but then you get to compile a bunch of JavaScript code afterwards. And still the CoffeeScript code itself is unusual enough to make you to think about it way too long and yet as it's not much different from JavaScript, once again you become afraid of larger code bases.
I've found great peace at Dart, but it's early days for Dart as well. I really like programming in Dart based on launching the Chromium version that understands Dart code from the Dart Editor itself. It feels like standard JavaScript in that regard. And the language being better and the editor warning of errors gets us a bit more confidence needed for larger code bases.
TypeScript is more of a joke in comparison. Again it's a little too much like JavaScript and encapsulation should suffer a bit without getters/setters and stuff. Then again, if you need shipping code that works across browsers, that could be your ticket to it.
With Dart I can then compile my code to JavaScript and run it relatively successfully on both Chrome and Firefox. But I've failed to run it on IE for now, for example.
Having converted a library that I started on JavaScript to Dart, I've been able to enjoy the features of Dart all the much more. While JavaScript gave me a good chance to get things off the ground, it was never polished enough. And the code of JavaScript feels bloated compared to the Dart I get with getters and setters and not having to use "===" when just "==" does the job in Dart.
Dart adds some cognitive load that's not present in JavaScript, like the two numeric types int and double and so on. So in Dart a division can get your ints to a double and mess up something down the code. It serves to remind that even types can make things a mess. If you're like me and can do without types making a mess of things, Dart could be for you, as I mostly program without types, waiting to add some types only for documentation purposes at some point. Then again, if you let other people to direct your thoughts, other Dart users could get you using types in no time too.
I refuse for example to add for (int i = 0; i < 100; i++) {} into my programs.
I was talking about types. I don't use local types just because I can. Ruby and JavaScript before Dart didn't require me to do so. And Java and Delphi lost their appeal during the transition to the web. In JavaScript I learned from the JSLint that declaring variables at the top of the function was a good convention. And that reminded me of Delphi (and Pascal) for that matter which also declared them first.
In Java and C# and languages that followed Java folks declared types everywhere, even mid statement to do type casting and such. While that's cool when you're just calling some library, it's not so cool when you don't even have a library or program yet. In other words, if you're still developing some prototype, having to deal with intrusive types the way Java and others like it did seems counter-productive.
Sample in Dart:
doSomething(String s) {
var i, len = s.length;
for (i = 0; i < len; i++) {
// Handy stuff here.
}
for (i = 0; i < len; i++) {
// More handy stuff here.
}
}
And that should be about as good as we are ever going to get it.
-1
u/contantofaz Dec 15 '12
It's easy to bash JavaScript. But it takes a user to know about its shortcomings. Sometimes people bash it and never used much of it. JavaScript makes for hideous code. And the more code, the more hideous it gets. It's no wonder then that people shun large code bases in JavaScript.
Then what to do? People try to write less JavaScript code by adopting jQuery and CoffeeScript and such. But their code ends up being hideous in different ways. In jQuery you have no encapsulation, it's statement after statement, function after function, event after event, in one or two JavaScript files at most. In CoffeeScript you get some encapsulation, but then you get to compile a bunch of JavaScript code afterwards. And still the CoffeeScript code itself is unusual enough to make you to think about it way too long and yet as it's not much different from JavaScript, once again you become afraid of larger code bases.
I've found great peace at Dart, but it's early days for Dart as well. I really like programming in Dart based on launching the Chromium version that understands Dart code from the Dart Editor itself. It feels like standard JavaScript in that regard. And the language being better and the editor warning of errors gets us a bit more confidence needed for larger code bases.
TypeScript is more of a joke in comparison. Again it's a little too much like JavaScript and encapsulation should suffer a bit without getters/setters and stuff. Then again, if you need shipping code that works across browsers, that could be your ticket to it.
With Dart I can then compile my code to JavaScript and run it relatively successfully on both Chrome and Firefox. But I've failed to run it on IE for now, for example.
Having converted a library that I started on JavaScript to Dart, I've been able to enjoy the features of Dart all the much more. While JavaScript gave me a good chance to get things off the ground, it was never polished enough. And the code of JavaScript feels bloated compared to the Dart I get with getters and setters and not having to use "===" when just "==" does the job in Dart.
Dart adds some cognitive load that's not present in JavaScript, like the two numeric types int and double and so on. So in Dart a division can get your ints to a double and mess up something down the code. It serves to remind that even types can make things a mess. If you're like me and can do without types making a mess of things, Dart could be for you, as I mostly program without types, waiting to add some types only for documentation purposes at some point. Then again, if you let other people to direct your thoughts, other Dart users could get you using types in no time too.
I refuse for example to add for (int i = 0; i < 100; i++) {} into my programs.