[Python-ideas] Dart-like method cascading operator in Python
Stephen J. Turnbull
stephen at xemacs.org
Fri Nov 22 10:32:48 CET 2013
Haoyi Li writes:
>> Is it really that hard to name a plot "p"? Is typing "p.",
>> or reading it, more work than ".."?
> Yes, reading `..` can be *considerably* less work than reading `p.`.
Unless you're Tim Peters, in which case ".." looks like grit on your
screen. Surely we wouldn't want *that*!
Seriously, as far as I can see it's also possible that reading ".." could
be much /more? work than reading "p.", especially if ".." can be nested.
You may need to parse backward all the way to the beginning of the
expression (suite?) to figure out what it refers to.
> - You also better make sure you didn't have a variable somewhere else
> called `p` for Pressure in one of your equations which you just
> stomped over, or `p` for Momentum, or Price, or Probability. It's not
> inconceivable that you'd want to plot these things!
Well, that's *really* bad style. Such programmers can't be helped.
They'll find a way to abuse "..", too.
For example, people often recommend reserving something like "_" (or
perhaps all single letter identifiers) only in this kind of context where
it's used repeatedly in each of a suite of contiguous lines. With such a
convention (especially once it becomes habit), the kind of problem you
describe is just not going to arise.
> Generally, having fewer things in the local namespace is good hygiene,
> and helps prevent name collisions.
True, but that is easy enough to get by defining a function.
Steve
More information about the Python-ideas
mailing list