mikeal / fif

Accessible, portable, programming lanuage.
6 stars 0 forks source link

Allow very limited use of `this` and `new` #6

Open Raynos opened 10 years ago

Raynos commented 10 years ago

I agree that new and this is really complicated.

However for reasons of performance and for compatibility with host environments we might want to keep new.

For example new Buffer() or new Float64Array()

Either we decide that all constructors are part of the standard library and you dont get to create your own constructors so we can get rid of this completely.

Or we limit the usage of this and allow people to write their own constructors.

We could have a limited constructor that looks like

function MyThing(a, b, c) {
  this.a = a;
  this.b = b;
  this.c = c;
}

The only usage of this that is valid is inside a constructor function. The only thing valid to do is to assign properties to this.x = prop.

This has the advantage of working with the rigid shape optimizations build into todays javascript.

Raynos commented 10 years ago

Personally I think banning constructor functions and this is a good idea.

Banning new is probably impossible because that's just how you create new binary data structures in javascript.

mikeal commented 10 years ago

why not just support clone(Buffer) and clone(Float64Array)? we can just add some fanciness to the compiler to treat it differently for builtins.

Raynos commented 10 years ago

@mikeal

I don't want to use a compiler to write javascript. I could import the fif-clone module and it could support that use case I guess.

mikeal commented 10 years ago

in order to inject standard methods, and enforce the language, it's going to have to run through a compiler. however, it could be as simple as $ fif program.fif and that could default to compiling for node and running it.