It seems that structs are missing constructors now.
Any intent to add them?
No, just like in Go, structs can be constructed with functions, like new_foo().
I mean what if some background work should be done on initialization? Assigning unique hash to _id field, for example:
struct Mystruct {
_id int
value string
}
fn (m mut Mystruct) __constructor() {
m._id = unique_hash_id()
}
mut my := Mystruct{value: "value"}
Yes, you can use a function for that:
fn new_mystruct(value string) MyStruct{
return MyStruct{
value: value
_id: unique_hash_id()
}
}
mut my := new_mystruct(value)
V is a simple language. Besides, structs are not classes, there's no OOP in V.
Most helpful comment
Yes, you can use a function for that:
V is a simple language. Besides, structs are not classes, there's no OOP in V.