54 points · by tosh · 12y ago · 41 comments
Naming everything ExampleX is very difficult to see what is being talked about in this particular function.
I'm lucky to know enough about Dart already, because this is a very bad representation of it, IMO.
var l = [];
Also, the example of looping over characters in a String using substring is very odd and expensive. Generally, if you want to iterate over a list of single-character Strings, you'd use String.split(): for (var c in str.split('')) {}
split('') is necessary to be unicode safe. There's also String.codeUnits and String.runes (an iterable of code-points).http://www.chromestatus.com/features/6682831673622528
So in a few months we will have Google's VbScript available in Chrome.
VBScript was IE only, because VBScript didn't compile to JavaScript. Dart compiles to JavaScript and runs on IE, Safari, Chrome, Firefox and Opera. VBScript didn't have a specification accepted by any standards organizations, Dart is ratified as ECMA 408. VBScript is not open source, Dart is.
The fact that Dart has been used in production years before any VM in a browser should show how different they are.
Not all language features can be represented in JavaScript.
Besides, all the languages that compile to JavaScript just add complexity layers to the already complex model of HTML/CSS/JavaScript.
And I bet there is a VbScript to JavaScript somewhere out there.
> Dart is ratified as ECMA 408. VBScript is not open source, Dart is.
Standards by themselves don't foster adoption.
Eiffel, Ada, Modula-2, Extended Pascal, Common Lisp, Smalltalk, ... have ISO/ANSI standards.
In the 60 - 90's being open source wasn't a requirement for multiple implementations for programming languages.
Including JavaScript.
Acceptance as a standard usually happens after someone implements it, makes it widely available, and proves its merit, not the other way around (and standards that happen the other way around tend to be dead on the vine.)
It occurred to me that HTML5 might have tightened up this rule, but it remains as before:
// Boolean expressions need to resolve to either true or false, as no
// implicit conversions are supported.
I'm sure they have good reason for this, does anyone know of the rationale? I think I'd miss patterns like `if (arr.length) { ... }`At least for this particular example, dart supports an 'isNotEmpty' property on all iterables[0], so it'd just be this:
if (arr.isNotEmpty) { ... }
The core libraries support a lot of useful properties like that.[0] https://api.dartlang.org/apidocs/channels/stable/dartdoc-vie...
With implicit coercion, the programmer must mentally keep track of how values get coerced (are negative numbers truthy? are empty strings? empty lists? empty objects?). Different languages have different answers for all of these things. As a result, I prefer to always be explicit.
If you've never seen the WAT?[1] talk, I suggest watching it. It has some great examples of type coercion gone wrong in Ruby and JS.
The Angular team, for instance, has defined toBool() (which they use in directives like ng-if) like this:
bool toBool(x) {
if (x is bool) return x;
if (x is num) return x != 0;
return false;
}
It treats true and non-zero numbers as true, and everything else (including null) as false. Boolean conversion maps any object o into a boolean. Boolean conversion is defined by the function application
(bool v){
assert(v != null);
return identical(v, true);
}(o)[1] http://blog.sethladd.com/2012/02/booleans-in-dart.html "The only value that is true is the boolean value true. [...] In a boolean context, everything that is not true is converted to false."
The reason it's defined this way is for efficient compilation to JavaScript. Control-flow constructs don't have to perform a type-check, just a null check (which can be left out in cases due to null propagation).
I rather like that you're forced to be explicit. Often, the (hidden) conversion is a source of bugs or confusion.