Re:Imba – A new programming language for the web
by judofyr on Thursday August 20, 2015 @09:39AM
(#10091694)
Imba was actually forked from CoffeeScript three years ago. After the fork there's been a bunch changes, both in terms of adding tags, but also when it comes to the object model and variable scope.
- Implicit calling: `foo.bar` calls `foo.bar()` and `foo.bar = 123` calls `foo.setBar(123)`
- Objects have instance variables that's separate from the methods. Well, technically the instance variable `@bar` is just stored as a property with name `_bar` on the object.
- Variables must be declared with `var` and they correctly shadow previously defined variables.
- `do` provides a syntax sugar for the pattern "function as the last argument"
- Optional arguments work together with block parameters
def timeout(amount = 0, &cb)
cb(amount)
Compiles to: function timeout(amount,cb)
if(cb==undefined && typeof amount == 'function') cb = amount,amount = 0;
return cb(amount);
};
- `self` is a keyword which is a saner `this`, and instance variables are automatically looked up using `self`: def end
@client.on("end") do
@server.end
Compiles to: function end(){
var self=this;
return this._client.on("end",function() {
return self._server.end();
});
};
Re:Imba – A new programming language for the web
by simplify on Thursday August 20, 2015 @12:43PM
(#10092996)
Re implicit calling: what would you write if you wanted to access `foo.bar` as a function instead of calling it?
Re:Imba – A new programming language for the web
by nawitus on Thursday August 20, 2015 @05:31PM
(#10094799)
I'm also wondering this. It looks like a huge design error.
Re:Imba – A new programming language for the web
by mbrock on Thursday August 20, 2015 @11:20PM
(#10095811)
foo:bar is property access.
Re:Imba – A new programming language for the web
by untog on Thursday August 20, 2015 @09:57AM
(#10091810)
- Implicit calling: `foo.bar` calls `foo.bar()` and `foo.bar = 123` calls `foo.setBar(123)`
Wuhh. Why wouldn't you use JS defineProperty here?
Re:Imba – A new programming language for the web
by judofyr on Thursday August 20, 2015 @10:35AM
(#10092077)
There's one historic reason (it wasn't widely available when Imba was started). Another reason is performance: the last time we benchmarked this `defineProperty` was slower than regular function calls. Maybe it's improved now.
Semantically the biggest difference is that you don't need to do anything special for marking a method as a property:
class List
def length
# …
In this case `list.length` just works. The disadvantage of this is that if you want to get the function itself, there's a separate syntax (`list:length`). Other than that, this is mostly about taste/style.
Let me guess!... CoffeeScript?