Actually a check like that is done in Environment
already, as documented in the help page. Alas, the check/warning is only active when you use setters. If you initialize the whole event/environment, you don’t get that check/warning.
NOTE: Be careful to avoid method names that are defined in any of the superclasses of environment (or event). Object prototyping works by trapping method selectors that are not already defined as class library methods. Using a generic method selector such as ‘stop’ or ‘reset’ will cause the corresponding class library method to respond, and the items in the environment will never be checked.
Assigning a value into an environment using a setter – name_() or .name = … – posts a warning message if the name is already defined in the class library.
e.reset = { "My reset function".postln };
// prints:
WARNING:
'reset' exists a method name, so you can't use it as pseudo-method.
// this does NOT execute the reset function above
// because Object:reset responds
e.reset;
I suspect it’s not hard to fix/improve the constructor of Environment
and make it iterate over the values and find those that are functions and issue a warning there too. But perhaps it’s undesirable in some ways (e.g. performance)… Also, I suspect there are other code paths on which that check isn’t done (putAll, putPairs etc.)
Also of some interest perhaps, you can still access such functions that conflict with method names, just not as methods.
(sum: { 42 })[\sum].value // 42
This is probably why the warning is not universally given, but only when you use setters. The constructor is arguably a debatable case whether to give that warning or not…
Of some interest, James’ Proto
inherits directly from Object so more stuff works overridden, including sum
, but not stuff defined in Object
like blend
a = Proto({~sum = 42})
a.sum // 42
a = Proto({~blend = 77})
a.blend // nil
Proto
actually has wrappers for a bunch of methods defined in Object… but not quite everything.