While everyone is saying what they want in Python :)

Steven D. Majewski sdm7g at virginia.edu
Wed Feb 7 00:48:40 CET 2001

On Tue, 6 Feb 2001, Daniel wrote:

> The part where I find the 'with' command interesting is for
> readability.  Consider : 
> MySpecialButton := TSpecialButton;
> MySpecialButton.caption := 'Busy';
> MySpecialButton.method2;
> MySpecialButton.caption := "Ok";
> or
> MySpecialButton := TSpecialButton;
> with MySpecialButton do
> begin
>    caption := 'Busy';
>    method2;
>    caption := 'Done';
> end;
> Which code would you prefer?

Having had to maintain Pascal code that used the 'with' construct,
I would always choose the former. 'With' is less readable because
it reduces locality of the code. You have to look at the data
type definition of TSpecialButton to understand what's going on
in that code. Try reading and maintaining code that has nested
withs 3 or more deep, with 20-60 fields for each struct, and 
I think you'll change your mind about it. 

It saves some typing but it reduces context, locality and readability. 

-- Steve Majewski

"Ontology recapitulates philology" -- W.V.Quine

More information about the Python-list mailing list