Open MatheusRich opened 3 years ago
How would the default constructor be named?
I think if it's a class with no fields, wouldn't it be better to use static methods instead?
class A {
static test() {
System.print("Called with 0 args")
}
static test(a) {
System.print("Called with 1 arg: '%(a)'")
}
}
A.test()
A.test("yay")
// can also assign variable `o` to the class itself as well
var o = A
o.test()
o.test("yay")
@CrazyInfin8 Yeah, that's what I thought. I was just playing with classes and started creating dumb methods. I was expecting it to "just work" since it would in Ruby (my main language). Anyway, I didn't know if it was worth adding this feature, so I asked here.
There is a crucial difference between Ruby and Wren in this aspect: Ruby defines only one constructor, with the reserved word new
. In Wren, constructors are just methods (special kind of them), and there can be multiple of them, possibly with different names.
@ChayimFriedman2 oh, I didn't know that. I was just expecting construct new() {}
to already be there. Feel free to close this, if it's not useful!
Hi everyone! First I'd like to thank y'all for this language!
I was playing with Wren in the browser and noticed that Classes requires a constructor, even if it does nothing. Here's what I was creating:
That seemed unnecessary verbosiness for a scripting language IMHO. On the other hand, I see that this can be intentional, since "a class with no state should be just a module".
So I opened this just to clarify if it is a language design choice.