14 Jul 17:05 2004
Re: use special syntax for method pointers?
2004-07-14 15:05:55 GMT
2004-07-14 15:05:55 GMT
On 14 Jul 2004, at 12:58, Wilson, Greg wrote: > Hi James. I vote for solving the problem by requiring the > parentheses, even when there are no arguments (if for no > other reason than the Principle of Least Surprise). Whether we use mandatory or optional parenthesis isn't really the point of this thread :). I think I explained it badly, I'll try once more... e.g. imagine if we forced mandatory parenthesis on methods with no arguments (which we currently do)... foo.size() works but the user's working with properties and does foo.size now rather than getting null as there's no property called 'size', we get a size closure which when we call it, we get the actual size. But I think most of the time thats not what the user wanted - returning null would be less surprising. (In fact I think the least surprising thing to do is treat the size() method and size property as the same thing, but lets not go there in this thread). If a user does foo.bar and the bean property "bar" does not exist, there may be a method of the same name, in which case today they'd get a method pointer instead. I've seen this happen a few times with users and they tend to get confused, because the thing they get back is a closure which isn't the value of the property they thought they were gonna get & they end up scratching their heads. This is especially true if users do things like foo.whatnot.bar.something and they get some cryptic message about a closure not having a property 'something' etc. So I'm thinking, accessing bean properties & walking through object graphs using properties is really, really common. We do it all the time & its easy for us to make a typeo or use a bean property when something really happens to also be a method. its quite a rare thing to do to grab a method pointer, so why not make it slightly hard to get a method pointer to avoid confusing users in the common case - method pointers are useful, but they are an uncommon use case - so I wanted to try make the common use case simpler & more obvious & less surprising at the cost of a slightly more verbose syntax to get a method pointer. Does that help clear it up? Whether we use mandatory parenthesis on methods with no arguments or not, we still have this issue I think. The issue really is about confusion between method pointers and bean properties and making the syntax to 'create a reference to an objects method' should maybe be more explicit to avoid confusion? In C/C++ the & is used to create a pointer to something hence my thinking of object.&methodName though we could always have some new method object.newMethodClosure("methodName") James ------- http://radio.weblogs.com/0112098/