Richard Black wrote:
> I'm usually a lurker on here, but thought I'd through in my 2p on this
> one...
>
> Delphi (Object Pascal) has a similar feature, that I've had some
> experience of using, and I never liked it. Why? Because it only leads to
> confusion, mainly because the separation of object and method leaves you
> unsure of what is actually being called.
>
> Consider the following:
>
> function do()
> {
> echo "hello";
> }
>
> $class=new class;
>
> with($class)
> {
> do_something();
> do_more();
> do();
> }
>
> Now, within my with(), am I calling the class method do() or the
> function do()? Not clear at first glance.
It may not be clear to some people, but there are many things in the
every language that aren't necessarily obvious and I don't think that's
a reason not to implement something.
To me this is actually quite clear. When you use with() you are defining
a temporary local scope, so your call to do() would first check if the
with() object contains that method, and then check the global scope if not.
> And the whole thing gets even more complex if you can start nesting
> with() constructs.
Again this seems simple to me, you just need a stack of with() objects
which are walked up to resolve any references.
> I suspect this wouldn't be trivial to implement, and for me it doesn't
> add any value - only potential confusion.
I see great value in this - it makes for cleaner looking code. I need
more than 10 fingers and 10 toes to count how many source files I have
that contain long sections where each line contains multiple references
to the same object.
-Stut
--
http://stut.net/