On Thu, Aug 29, 2019 at 05:30:39AM -0700, Andrew Barnert wrote:
> On Aug 29, 2019, at 04:58, Steven D'Aprano <[email protected]> wrote:
> >
> > - quote marks are also used for function calls, but only a limited
> > subset of function calls (those which take a single string literal
> > argument).
>
> This is a disingenuous argument.
>
> When you read spam.eggs, of course you know that that means to call
> the __getattr__('eggs') method on spam. But do you actually read it as
> a special method calling syntax that’s restricted to taking a single
> string that must be an identifier as an argument
You make a good point about abstractions, but you are missing the
critical point that spam.eggs *doesn't look like a string*. Things that
look similar should be similar; things which are different should not
look similar.
I acknowledge your point (and the OP's) that many things in Python are
ultimately implemented as function calls. But none of those things look
like strings:
- The argument to the import statement looks like an identifier
(since it is an identifier, not an arbitrary string);
- The argument to __getattr__ etc looks like an identifier
(since it is an identifier, not an arbitrary string);
- The argument to __getitem__ is an arbitrary expression, not just
a string.
All three are well understood to involve runtime lookups: modules must
be searched for and potentially compiled, object superclass inheritance
hierarchies must be searched; items or keys in a list or dict must be
looked up. None of them suggest a constant literal in the same way that
"" string delimiters do.
The large majority of languages follow similar principles, allowing for
usually minor syntactic differences. Some syntactic conventions are very
weak, and languages can and do differ greatly. But some are very, very
strong, e.g.:
123.4567 is nearly always a numeric float of some kind, rather
than ((say) multiplying two ints;
' and/or " are nearly always used for delimiting strings.
Even languages like Forth, which have radically different syntax to
mainstream languages, sort-of follows that convention of associating
quote marks with strings.
." outputs the following character string, terminating at
the next " character.
i.e. ." foo" in Forth would be more or less equivalent to print("foo")
in Python.
Let me suggest some design principles that should hold for languages
with more-or-less "conventional" syntax. Languages like APL or Forth
excluded.
- anything using ' or " quotation marks as delimiters (with or without
affixes) ought to return a string, and nothing but a string;
- as a strong preference, anything using quotation marks as delimiters
ought to be processed at compile-time (f-strings are a conspicuous
exception to that principle);
- using affixes for numeric types seems like a fine idea, and languages
like Julia that offer a wide-range of builtin numeric types show
that this works fine; in Python2 we used to have native ints and
longints that took a L suffix so there's precedent there.
[...]
> And the same goes for regex"a.*b" or 1.23f as well. Of course you’ll
> know that under the covers that means something like calling
> __whatever_registry__['regex'] with the argument "a.*b", but you’re
> going to think of it as a regex object
No I'm not. I'm going to think of it as a *string*, because it looks
like a string.
Particularly given the OP's preference for single-letter prefixes.
1.23f doesn't look like a string, it looks like a number. I have no
objection to that in principle, although of course there is a question
whether float32 is important enough to justify either builtin syntax or
custom, user-defined syntax.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/RQQFV5AJCVJHYSYUVM2UQ2HQOLU6KBMV/
Code of Conduct: http://python.org/psf/codeofconduct/