VB/Pascal with statement [was Re: Proposal for new minor syntax]

Rustom Mody rustompmody at gmail.com
Sat Mar 28 12:21:03 EDT 2015


On Saturday, March 28, 2015 at 11:56:39 AM UTC+5:30, Steven D'Aprano wrote:
> On Sat, 28 Mar 2015 03:18 pm, Rustom Mody wrote:
> 
> > One thing that is a bit laborious in python are object initializers:
> > 
> > self.attr1 = field1
> > self.attr2 = field2
> > 
> > In VB one can do:
> > 
> > with self
> > .attr1 = field1
> > .attr2 = field2
> > 
> > (or something like that -- dont exactly remember the syntax)
> 
> 
> Pascal is another language with a construct like that, and there's a FAQ for
> it:
> 
> https://docs.python.org/2/faq/design.html#why-doesn-t-python-have-a-with-statement-for-attribute-assignments

This is not my baby so I am not going to pursue this argument beyond here.
However that FAQ addresses Object Pascal, Delphi, C++ and their respective
static type disciplines.

The VB syntax OTOH does not exploit any typing info
https://msdn.microsoft.com/en-us/library/wc500chb.aspx
because attributes are prefixed with a dot --
unlike Pascal and unlike the examples in the FAQ.

So if the VB model is followed, it is purely a syntactic (ie not type-related)
question whether an identifier is an adorned variable or an attribute of
something else.  The preceding dot is the disambiguator.

Anyways... As I said, this feature is not v important to me one way or other...



More information about the Python-list mailing list