[Tutor] 'with foo' was Languages

dman dman@dman.ddts.net
Thu, 28 Mar 2002 18:43:08 -0600


On Thu, Mar 28, 2002 at 04:29:09PM -0800, Jeff Shannon wrote:
| > "Sean 'Shaleh' Perry" <shalehperry@attbi.com> wrote:
| >
| > > OK.  I just don't see why you miss them, given it seems
| > > you can do pretty much the same thing without them.
| >
| > when I say 'with foo' it is syntactically obvious what I am doing.  When I
| > assign 'o = my_long_...' it is not.  No big deal.
| 
| I disagree.  The lines following 'with foo' have unqualified names,
| which look to me like local variables rather than object attributes.
| When I see 'o.bar', I know I'm accessing an object, and it's not
| that hard to glance up and see what 'o' has been bound to.

I think this applies equally well to the magic "this" in C++ and Java.
After spending some time in python where instance members and methods
are explicitly qualified, I have more trouble following C++/Java that
relies on the automatic (unqualified) scoping of members.  Now my
C++/Java style is to always use 'this.' (or 'this->' for C++) when
accessing members.

(for those unfamiliar with "this", it is a keyword that serves the
same purpose as the "self" notation in python convention; another
difference is that methods don't declare it as an argument, it
automagically is present)

| Matter of taste and previous experience, I suppose.

Agreed.

-D

-- 

If Microsoft would build a car...
... Occasionally your car would die on the freeway for no reason. You
would have to pull over to the side of the road, close all of the car
windows, shut it off, restart it, and reopen the windows before you
could continue. For some reason you would simply accept this.