4 ms·
One thing I love about javascript is the ability to quickly and easily assign/remove whatever fields I'd like: let a = {}; a.somename = "some val";
by wcarss 6y ago
One thing I love about javascript is the ability to quickly and easily assign/remove whatever fields I'd like:
let a = {};
a.somename = "some val";
a.newname = "some val";
a["a computed name"] = "some other val";
delete a.somename;
if (a.neverseenthisbefore) {
log("just doesn't log!");
}
Python dictionaries requiring the ["fieldname"] syntax or .get to avoid KeyErrors on undefined keys has always pained me when whipping something short together. Similarly, here in Wren it seems like Maps require substantial and strict syntax, and Classes are not meant to allow definition of arbitrary Fields at runtime.
That one small thing is a key piece of flexibility I want when experimenting. I shouldn't need to write a getter and a setter down in a distant file on the correct place in a class hierarchy just because I chose to latch a bit of temporary state onto an object while I do a bit of work.
In serious code for serious business, that kind of freedom and nonchalance can be quite dangerous. But when I'm having fun and just trying something, which is the only context where I'm really trying new languages out for the moment, the guard rails chafe!
(still, this looks like a pretty neat little language)
- shezi 6y agoSide note: You can use python classes for that. It's a common pattern for me to have something like this in my projects class Holder: pass Simply add any attributes at runtime. It's essentially a different interface for the built-in dict of the instances. Add a bit of getattr magic and you can read undefined attributes, too.