While everyone is saying what they want in Python :)

Jay O'Connor joconnor at cybermesa.com
Tue Feb 6 16:44:06 CET 2001


"David C. Ullrich" wrote:
> 
> On Tue, 06 Feb 2001 01:35:02 GMT, "Don Tuttle" <tuttledon at hotmail.com>
> wrote:
> 
> >
> >"Jay O'Connor" <joconnor at cybermesa.com> wrote in message
> >news:3A7DB154.87E04245 at cybermesa.com...
> >> I'm not familiar with the 'with' keyword in Delphi.
> >
> >Here's a vbscript example.
> >With MyLabel
> >   .Height = 2000
> >   .Width = 2000
> >   .Caption = "This is MyLabel"
> >End With
> >Personally, I'd love to see Python include the 'with' keyword! It improves
> >readability and should execute a bit faster as well.
> 
> Delphi's "with" is more or less the same except without the
> dots at the start of the field names. For a long time I've
> seen Delphi people say that with is bad, the reason
> being it leads to bugs
> 
> with AnObject do
>   begin
>     OneThing
>     AnotherThing
>   end
> 


Eeewwww....that's ugly :)

Smalltalk cascading really isn't the same.  "with" seems to be
eastablishing a sort of local scope f reference.  Smalltalk cascading
just says "send this message to the same object you sent the last
message."

One point that may have gotten missed.  Smalltalk doesn't use ";" as a
delimiter between statements, it uses "." as a delimiter and a ";" to
indicate a cascade.  So the code

	anObject
		messageOne;
		messageTwo.

It's syntactically obvious that messageTwo is sent to anObject; there
can be no other confusion.

> when AnObject does not have a OneThing method
> but there _is_ a OneThing in the surrounding scope.

Oh, yes...I could see that being a big issue.  Smalltalk doesn't have
that problem because a) the syntax is explicit that you are cascading a
message send and b)  Smalltalk doesn't have the concept of functions not
bound to objects so you don't run into a problem of "this method doesn't
apply in this scope, let me try an outer scope".

> For years I thought this was just stupid - you should
> know what sort of object you're dealing with. The
> Python slogans about how explicit is better than
> implicit just about have me convinced that
> people are right, with is bad.

I agree.  Explicit is better than implicit (I still have Perl
nightmares...), and the Pascal 'with' statement seems wrought with
potential disaster.  Fortunately, the simularity between 'with' and
Smalltalk cascading is only superficial, at best.

Take care,

-- 
Jay O'Connor
joconnor at cybermesa.com
http://www.cybermesa.com/~joconnor

Python Language Discusssion Forum -
http://pub1.ezboard.com/fobjectorienteddevelopmentpython



More information about the Python-list mailing list