var/Unsigned32/int = new
// Stores the value '123456' (whatever "stores" should be
// taken to mean for the object in question) instead of
// the int variable having that value.
int <- 123456
// or
int := 123456
world << ((int == 123456) ? "True" : "False") // "False"
world << ((int ~= 123456) ? "True" : "False") // "True"
ID:2534755
Jan 3 2020, 7:51 pm
|
|||||||
Resolved
| |||||||
Obviously we can't overload the standard = assignment operator because it would be a horrendous mess and probably the assumption of assignment actually changing the value stored in a variable instead of modifying an object stored in that variable is a deeply-embedded assumption in the code. As an alternative, could we get some sort of additional operation that takes on this role, something like := or <- or something like that? Then we could do something like
|
Yeah, I'm aware. I'm more interested in making the object behaving as a "pseudo-variable" more transparent, even though it is very much just syntactic sugar.
|
What about a property-like syntactic sugar? (Slightly different purpose, I'm aware, but similar in use I think.)
// Better syntax TBD. |
In response to Hiead
|
|
Hiead wrote:
What about a property-like syntactic sugar? (Slightly different purpose, I'm aware, but similar in use I think.) That would be insanely useful. |
In response to Hiead
|
|
Properties have been something I've wanted for years. They're incredibly helpful.
|
I design systems where reassignment of variables directly have consequences. This means I need to train anyone who uses my code how the library or snippet works at a deep level, and field lots of questions as to why my code breaks when you use it in a way the documentation explicitly tells you not to.
This would make Ter a happy bear, able to hibernate in his cave with less disturbances. |
This is implemented for BYOND 514. The issue will be closed when the first beta is released.
|
In response to Lummox JR
|
|
What exactly is implemented here?
|
In response to Kaiochao
|
|
There's a new overloadable := operator, which has overload procs defined for some of the built-in datums but for others you'll have to define it yourself. This is called the "assign into" operator.
|
I suppose adding an operator for this purpose might be possible, but it's basically no more than syntactic sugar for a proc call. It'd end up being equivalent to object.AssignSomething() since it'd just be looking up the appropriate operator proc and executing that.