Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #88189 > unrolled thread

Re: Proposal for new minor syntax

Started byBen Finney <ben+python@benfinney.id.au>
First post2015-03-28 10:39 +1100
Last post2015-04-08 22:11 +0000
Articles 12 — 8 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Proposal for new minor syntax Ben Finney <ben+python@benfinney.id.au> - 2015-03-28 10:39 +1100
    Re: Proposal for new minor syntax Mario Figueiredo <marfig@gmail.com> - 2015-03-28 01:33 +0100
      Re: Proposal for new minor syntax Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-27 18:55 -0600
        Re: Proposal for new minor syntax Rustom Mody <rustompmody@gmail.com> - 2015-03-27 21:18 -0700
          VB/Pascal with statement [was Re: Proposal for new minor syntax] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-28 17:26 +1100
            Re: VB/Pascal with statement [was Re: Proposal for new minor syntax] Chris Angelico <rosuav@gmail.com> - 2015-03-28 17:40 +1100
            Re: VB/Pascal with statement [was Re: Proposal for new minor syntax] Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-28 12:26 +0000
              Re: VB/Pascal with statement [was Re: Proposal for new minor syntax] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-28 23:58 +1100
                Re: VB/Pascal with statement [was Re: Proposal for new minor syntax] Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-28 13:44 +0000
            Re: VB/Pascal with statement [was Re: Proposal for new minor syntax] Rustom Mody <rustompmody@gmail.com> - 2015-03-28 09:21 -0700
              Re: VB/Pascal with statement [was Re: Proposal for new minor syntax] Rustom Mody <rustompmody@gmail.com> - 2015-03-28 09:32 -0700
          Re: Proposal for new minor syntax Giorgos Tzampanakis <giorgos.tzampanakis@gmail.com> - 2015-04-08 22:11 +0000

#88189 — Re: Proposal for new minor syntax

FromBen Finney <ben+python@benfinney.id.au>
Date2015-03-28 10:39 +1100
SubjectRe: Proposal for new minor syntax
Message-ID<mailman.282.1427499534.10327.python-list@python.org>
Jamie Willis <jw14896.2014@my.bristol.ac.uk> writes:

> This could be written as:
>
> hello = "hello world              "
> hello .= strip()

−1, “.=” is visually too similar to “=”.

Syntax that is ambiguous at a glance is a cost when reading, and here I
think the cost is great.

> In this slightly contrived example, the programmer saved (a small amount
> of) time when writing the code.

Code is read much more often than it is written; we should optimise for
reading effort, not writing effort.

-- 
 \      “The history of Western science confirms the aphorism that the |
  `\     great menace to progress is not ignorance but the illusion of |
_o__)            knowledge.” —Daniel J. Boorstin, historian, 1914–2004 |
Ben Finney

[toc] | [next] | [standalone]


#88193

FromMario Figueiredo <marfig@gmail.com>
Date2015-03-28 01:33 +0100
Message-ID<ptrbha1f8b7rgjoo3idtflpg3fsrtmvs9t@4ax.com>
In reply to#88189
On Sat, 28 Mar 2015 10:39:04 +1100, Ben Finney
<ben+python@benfinney.id.au> wrote:

>Jamie Willis <jw14896.2014@my.bristol.ac.uk> writes:
>
>> This could be written as:
>>
>> hello = "hello world              "
>> hello .= strip()
>
>?1, “.=” is visually too similar to “=”.

can't be much worse than

    hello = "hello world    ",

I think the dot next to the equal sign makes it very distinctive. The
equal sign is something we are so visually used to that any small
deviation gets immediately recognized by our brain. I may be wrong on
this assumption...

>
>Syntax that is ambiguous at a glance is a cost when reading, and here I
>think the cost is great.

I think the bigger issue here is consistency. And I like my
programming languages to sport consistent syntax and semantics. Or at
least to remain onsistent unless there is a good reason not to.

In Python the dot sign isn't an operator. It is a delimiter. So it
feels odd for me to see it treated as an operator. More precisely, in
Python, delimiters that form an augmented assignment operator consist
of an operator followed by the equal sign delimiter. This proposal
would be the only exception.

I'm personally not very found of that.

[toc] | [prev] | [next] | [standalone]


#88194

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-03-27 18:55 -0600
Message-ID<mailman.283.1427504164.10327.python-list@python.org>
In reply to#88193
On Fri, Mar 27, 2015 at 6:33 PM, Mario Figueiredo <marfig@gmail.com> wrote:
> On Sat, 28 Mar 2015 10:39:04 +1100, Ben Finney
> <ben+python@benfinney.id.au> wrote:
>
>>Jamie Willis <jw14896.2014@my.bristol.ac.uk> writes:
>>
>>> This could be written as:
>>>
>>> hello = "hello world              "
>>> hello .= strip()
>>
>>?1, “.=” is visually too similar to “=”.
>
> can't be much worse than
>
>     hello = "hello world    ",
>
> I think the dot next to the equal sign makes it very distinctive. The
> equal sign is something we are so visually used to that any small
> deviation gets immediately recognized by our brain. I may be wrong on
> this assumption...

It depends somewhat on context. In the variable-width font that I'm
reading my email in, the dot looks like a single pixel and doesn't
create much visual spacing either. It would be very easy to miss. In a
terminal window with Courier New on the other hand, it does look
distinctive enough to be noticeable.  We should keep in mind though
that our code isn't always going to be read in Courier New.

[toc] | [prev] | [next] | [standalone]


#88201

FromRustom Mody <rustompmody@gmail.com>
Date2015-03-27 21:18 -0700
Message-ID<9c9703b6-cfa6-4e91-900e-3a401562cb9e@googlegroups.com>
In reply to#88194
On Saturday, March 28, 2015 at 6:26:26 AM UTC+5:30, Ian wrote:
> On Fri, Mar 27, 2015 at 6:33 PM, Mario Figueiredo  wrote:
> > On Sat, 28 Mar 2015 10:39:04 +1100, Ben Finney wrote:
> >
> >>Jamie Willis writes:
> >>
> >>> This could be written as:
> >>>
> >>> hello = "hello world              "
> >>> hello .= strip()
> >>
> >>?1, ".=" is visually too similar to "=".
> >
> > can't be much worse than
> >
> >     hello = "hello world    ",
> >
> > I think the dot next to the equal sign makes it very distinctive. The
> > equal sign is something we are so visually used to that any small
> > deviation gets immediately recognized by our brain. I may be wrong on
> > this assumption...
> 
> It depends somewhat on context. In the variable-width font that I'm
> reading my email in, the dot looks like a single pixel and doesn't
> create much visual spacing either. It would be very easy to miss. In a
> terminal window with Courier New on the other hand, it does look
> distinctive enough to be noticeable.  We should keep in mind though
> that our code isn't always going to be read in Courier New.

Dunno if related...
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)

[toc] | [prev] | [next] | [standalone]


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

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-03-28 17:26 +1100
SubjectVB/Pascal with statement [was Re: Proposal for new minor syntax]
Message-ID<5516498e$0$13014$c3e8da3$5496439d@news.astraweb.com>
In reply to#88201
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



-- 
Steven

[toc] | [prev] | [next] | [standalone]


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

FromChris Angelico <rosuav@gmail.com>
Date2015-03-28 17:40 +1100
SubjectRe: VB/Pascal with statement [was Re: Proposal for new minor syntax]
Message-ID<mailman.285.1427524804.10327.python-list@python.org>
In reply to#88202
On Sat, Mar 28, 2015 at 5:26 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> 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

While I don't advocate the proposal, it does have an important
difference from the one cited in the FAQ - albeit a Tim-grit
difference: the Pascal version has implicit attribute notation, where
the proposed has a leading dot. This eliminates the ambiguity, though
without majorly improving readability.

ChrisA

[toc] | [prev] | [next] | [standalone]


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

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-03-28 12:26 +0000
SubjectRe: VB/Pascal with statement [was Re: Proposal for new minor syntax]
Message-ID<mailman.292.1427545673.10327.python-list@python.org>
In reply to#88202
On 28/03/2015 06:26, 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
>

c:\cpython\PCbuild>python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> help(FAQ)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
NameError: name 'FAQ' is not defined
 >>> help('FAQ')
no Python documentation found for 'FAQ'

Less than useless, now what?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


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

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-03-28 23:58 +1100
SubjectRe: VB/Pascal with statement [was Re: Proposal for new minor syntax]
Message-ID<5516a58a$0$12987$c3e8da3$5496439d@news.astraweb.com>
In reply to#88223
On Sat, 28 Mar 2015 11:26 pm, Mark Lawrence wrote:

> On 28/03/2015 06:26, Steven D'Aprano wrote:

>>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



>  >>> help('FAQ')
> no Python documentation found for 'FAQ'
> 
> Less than useless, now what?


Did you try googling?

help("google")

Or you could read the URL I gave earlier.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


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

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-03-28 13:44 +0000
SubjectRe: VB/Pascal with statement [was Re: Proposal for new minor syntax]
Message-ID<mailman.293.1427550302.10327.python-list@python.org>
In reply to#88224
On 28/03/2015 12:58, Steven D'Aprano wrote:
> On Sat, 28 Mar 2015 11:26 pm, Mark Lawrence wrote:
>
>> On 28/03/2015 06:26, Steven D'Aprano wrote:
>
>>> 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
>
>
>
>>   >>> help('FAQ')
>> no Python documentation found for 'FAQ'
>>
>> Less than useless, now what?
>
>
> Did you try googling?
>
> help("google")

Fails in just the same way.  Do I raise a bug report on the issue tracker?

>
> Or you could read the URL I gave earlier.
>

I don't want to read URLs, I prefer the interactive help.  Besides which 
you could be trying to lure me to a site where I'd catch a cold, or 
virus, or whatever it's called.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


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

FromRustom Mody <rustompmody@gmail.com>
Date2015-03-28 09:21 -0700
SubjectRe: VB/Pascal with statement [was Re: Proposal for new minor syntax]
Message-ID<45207400-5060-44cf-8720-fca428b03b81@googlegroups.com>
In reply to#88202
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...

[toc] | [prev] | [next] | [standalone]


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

FromRustom Mody <rustompmody@gmail.com>
Date2015-03-28 09:32 -0700
SubjectRe: VB/Pascal with statement [was Re: Proposal for new minor syntax]
Message-ID<acf4edee-2e09-4c06-9863-b870f5998e32@googlegroups.com>
In reply to#88230
On Saturday, March 28, 2015 at 9:51:50 PM UTC+5:30, Rustom Mody wrote:
> 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.

Uh... UN-adorned is what I meant

[toc] | [prev] | [next] | [standalone]


#88690

FromGiorgos Tzampanakis <giorgos.tzampanakis@gmail.com>
Date2015-04-08 22:11 +0000
Message-ID<mg492m$dn6$1@dont-email.me>
In reply to#88201
On 2015-03-28, Rustom Mody wrote:

> Dunno if related...
> One thing that is a bit laborious in python are object initializers:
>
>   self.attr1 = field1
>   self.attr2 = field2

Vim's "visual block" feature is your friend in such cases... Pretty sure
that other editors have something equivalent, too. But why would you use
other editors when you can use Vim :-) .

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web