[Tutor] With
Alan Gauld
alan.gauld@blueyonder.co.uk
Tue Jun 10 04:14:02 2003
Hi Sean,
> > >What exactly would a 'with' do that an 'it' doesn't?
> To those of us who learned it early in our programmer
> career 'with' just seems so much more elegant
I started on Pascal which has a with and I still use Delphi which
idiomatically uses with regularly. However I don't miss it in Python
because its easy to use a short variable...
> In C++ I can do:
>
> blah* i = this_long_thing;
> i->foo = 2;
> i->bar = 'bat';
Yes, but the reason C++ could use a 'with' and that its useful
in Pascal is because they are strictly typed, so you need a
pre-declared variable of the right type for every 'with' equivalent.
Because Python allows me to use one name 'it' for every shortcut
I don't get any such hassle so am quite happy. I honestly don't miss
'with' at all in Python, and in fact until Bob posted his
message I'd never even considered it!
Alan g.