3 ms·
Another options besides comment-based annotations is property based annotations. Basically provide a library that contains all the possible primitive types tha
by malandrew 12y ago
Another options besides comment-based annotations is property based annotations.
Basically provide a library that contains all the possible primitive types that can be checked and functions for composing higher order types.
Then in the code do something like so:
var types = require('types');
function foo(bar, baz) {
var qux = '';
/* do something */
return qux;
}
foo.types = {
args: [types.Array, types.Object],
return: [ types.String ] // array to support ES6 destructuring assignment
}
This interface makes it trivially easy to define the types, parse the types, strip the types out on minification, etc.
This approach also makes it trivially easy to compose higher order types in a separate modules and require them.
my-geometry-types.js:
var types = require('types');
var point = [types.Float, types.Float];
module.exports.point = point;
module.exports.rectangle = [point, point];
Then in another file, you can require these type modules and use them to set the type signature of a function;
Anyways, my point is that building a tool like this is awesome, but a null contribution if it requires me to throw out all my existing tooling, especially for something that could have been implemented in a way that is composable. It may even be a net negative contribution if it gets traction and causes an unnecessary schism (e.g. JSX) in the community that reduces code sharing, interop and the ability for developers to stand on each others shoulders.
The beauty and strength of the NodeJS ecosystem is not the language it is based on (JavaScript) or its runtime (v8/libuv), but that it nailed a lot of details related to common conventions among developers and allowing modules to remain small and composable.
The modules created by people like prominent module contributors like Substack, Raynos, Izs and Dominic Tarr are usually stellar examples of publishing small, reusable module components. All of these guys have hundreds of small modules published that are very composable, easy test and easy/fast to replace if they don't meet your needs.
The tooling behind AtScript would be a huge contribution if it were made in a way where the components that make up the tooling could be mixed and matched for use in novel ways.
- dragonwriter 12y ago> Another options besides comment-based annotations is property based annotations. You mean, exactly like what the generated JavaScript from AtScript has in the samples shown in TFA? > The tooling behind AtScript would be a huge contribution if it were made in a way where the components that make up the tooling could be mixed and matched for use in novel ways. As detailed in TFA, there are two main components that exist right now -- the Traceur transpiler and the RTTS (runtime type system) library, the latter of which provides the kind of functionality you discuss in much of your post. Clearly RTTS can be used independently of AtScript proper. There are future plans (also detailed in TFA), which include at least one other standalone tool. So the "components which can be mixed and matched in novel ways" seems to be exactly the plan. If you had spent as much time reading what they actually have done and are doing as you spent writing about what they should and shouldn't do, you may have realized that you were basically asking for exactly what they are doing.
- gcanti 12y ago> Another options besides comment-based annotations is property based annotations. Basically provide a library that contains all the possible primitive types that can be checked and functions for composing higher order types. Shameless plug: I wrote a similar library based on set theory (I'm a mathematician) https://github.com/gcanti/tcomb https://github.com/gcanti/tcomb EDIT: and here an article explaining the rationale behind the library https://gcanti.github.io/2014/09/29/javascript-types-and-sets.html https://gcanti.github.io/2014/09/29/javascript-types-and-set...