[Review] SE-0144: Allow Single Dollar Sign as a Valid Identifier

I'm actually vaguely surprised that the other currency symbols are
considered valid identifiers, since they're not alphanumeric symbols.
As for turning them into operators, it's a cute idea, but it doesn't
work for any symbol that's used by multiple countries. For example,
would $3.50 be USD, AUD, CAD, or any of the other dozens of countries
that use dollars?

-Kevin Ballard

···

On Tue, Oct 18, 2016, at 09:39 AM, Nevin Brackett-Rozinsky via swift-evolution wrote:

It seems natural to me that currency symbols should be operators. This
would allow, for example, prefix and postfix operators that take a
number and return a “Currency” instance:

let inMyPocket = $20
let lochNess = £3.50
let twoBits = 25¢

if (inMyPocket - lochNess) > twoBits { … }

Of course, the unnamed closure parameter identifiers would conflict
with that use of the dollar sign. However, I think Anton has the right
idea. We already use the number sign for compiler magic, so it would
make sense to call the closure parameters #0, #1, etc. In my view
those even read better than what we have now.

Nevin

On Tue, Oct 18, 2016 at 12:19 PM, Dave Abrahams via swift-evolution > <swift-evolution@swift.org> wrote:

on Mon Oct 17 2016, Jean-Denis Muys <swift- >> evolution@swift.org> wrote:

> While I already tersely supported this proposal, following all the
> negative reactions, I feel compelled to revisit my position. The
> main reason is that it strikes me that most points of view so far,
> including mine, were really culturally short sighted, and far too
> much US-centric.
>
> I totally agree that '$' being use by one (or even several) piece
> of code is not reason enough to change the language. But I also
> think that it being used by only one piece of code is no reason to
> reject the change.
>
> Most of us, including me, have been blinded by two things:
>
> 1- the use of the $ sign in other programming languages 2- the use
> of the $ sign in Swift as a prefix for implicitly declared closure
> parameters
>
> I think this second use is not Swifty at all. It clearly (to me)
> would fail the litmus test "if it wasn't there, would you add it
> to the language?". Of course, it has been blessed by time, and it
> has *become* Swifty, by usage because it's a useful feature,
> despite the choice of its syntax being so ugly (to my non-american
> eyes).

I don't think it's un-swifty by any measure. It's not particularly
beautiful, I agree, but what would make a better, extremely
terse, way
to refer to a posiitional parameter of a closure? Unless we
can think
of something that's obviously better, then it is thoroughly
swifty: a
pragmatic solution for an important problem. Unless we can think
of something that's obviously better, then it certainly *is* what we
would have added to the language.

> Similarly, I believe the use of the $ in other language should not
> be a guide in the decision here, either positively, nor
> negatively. We may pay some mild attention to the concern that we
> should perhaps avoid some confusion. I haven't seen much of that.
>
> Now for the elephant in the room: '$' is a currency symbol. As
> such it should be handled like any other currency symbol. Thinking
> otherwise would be very culturally offensive.

<snip>

>
> In conclusion, I believe this proposal must be accepted, and
> actually expanded to include ¥, ¢, £, and also to make it explicit
> that currency symbols can be used in variable names as first and
> only character, as first of many characters, and at any position.
>
> This would make $0, $1, $2… legal variable names. I believe this
> is OK.
>
> What would happen to implicitly declared closure parameters then?
> Nothing. They would continue to be implicitly declared in the
> context of closures that do not declare their parameters
> explicitly, similarly to `self` being implicitly declared in the
> context of a class. A user willing to use $0 there would be facing
> a name collision, which is OK.
>
> Note that such a change is purely additive: no legal source code
> today would fail with this change.

That is actually a relatively un-swifty answer in some ways.
It means
there are magic identifiers that are usable in all contexts
but given
special meaning in some contexts. I think making the lexical
roles of
various currency symbols more consistent is a worthy goal, but
I'm not
sure this is the way to do it.

> I hope that at the very least, I opened a new perspective on this
> proposal, and I hope we can find a way to be less culturally
> biased.

If there's cultural bias here, it's a bias based on programming
language
precedent. \$[0-9] has a long history of use as a positional
parameter
identifier in programming languages. Swift very explicitly embraces
*that* sort of “cultural bias.” The culture of programmers matters.

--
-Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_________________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Except of course, '#' means "pound" is some contexts, and you might want to make a # operator return a weight.

I'm okay with giving up '#' for this, however.

···

On Oct 18, 2016, at 09:39 , Nevin Brackett-Rozinsky via swift-evolution <swift-evolution@swift.org> wrote:

It seems natural to me that currency symbols should be operators. This would allow, for example, prefix and postfix operators that take a number and return a “Currency” instance:

let inMyPocket = $20
let lochNess = £3.50
let twoBits = 25¢

if (inMyPocket - lochNess) > twoBits { … }

Of course, the unnamed closure parameter identifiers would conflict with that use of the dollar sign. However, I think Anton has the right idea. We already use the number sign for compiler magic, so it would make sense to call the closure parameters #0, #1, etc. In my view those even read better than what we have now.

--
Rick Mann
rmann@latencyzero.com

+1

- Dave Sweeris

···

On Oct 18, 2016, at 11:39 AM, Nevin Brackett-Rozinsky via swift-evolution <swift-evolution@swift.org> wrote:

It seems natural to me that currency symbols should be operators. This would allow, for example, prefix and postfix operators that take a number and return a “Currency” instance:

let inMyPocket = $20
let lochNess = £3.50
let twoBits = 25¢

if (inMyPocket - lochNess) > twoBits { … }

Of course, the unnamed closure parameter identifiers would conflict with that use of the dollar sign. However, I think Anton has the right idea. We already use the number sign for compiler magic, so it would make sense to call the closure parameters #0, #1, etc. In my view those even read better than what we have now.

Nevin

“culturally offensive” is not a logical argument.
A programming language should be logically consistent no matter how many cultures are offended by it.
If Swift is driven by SJW’s then very quickly it will cease to be an effective language.

I don’t think using “SJW” as a slur is appropriate, certainly not in swift-evolution. We aim to be an open and inclusive community. Cultural sensitivity is one of Swift’s goals; that’s why it supports Unicode identifiers… so people can use their native language if they wish. The world is not the Western Latin-1 character set.

True, but sometimes restricting yourself can bring better results. A big reason why technical and scientific progress is advancing so fast in the modern era is also attributed to people being able to rely on a common lingua franca (English today, something else in 100 years perhaps?) and very fast communication amongst people of different cultural backgrounds happening at lighting speed.

People on teams resist to code guidelines for freedom of expression reasons too, but the values of standardisation are greater than what we achieve by prioritising creative expression in the form of writing all my code in kanji or using proper Italian accented characters or following my own code formatting convention... pride and fear often put people off when self imposing limitations for the greater good. English as programming lingua franca brings people together more than it suppresses valuable creative thought.

English is obviously not my first language, but I enjoy the fact that having the documentation, developer forums, this kind of mailing lists, etc... all standardising around English as technical lingua franca is both useful, facilitate communication, and is totally not unprecedented (Latin used to be the defacto lingua franca for medicine, biology, botany, and all sorts of scientific and philosophical discussion... it did not kill the local languages and brought people together).

···

Sent from my iPhone

On 20 Oct 2016, at 07:54, Russ Bishop via swift-evolution <swift-evolution@swift.org> wrote:

On Oct 17, 2016, at 11:45 PM, Rien via swift-evolution <swift-evolution@swift.org> wrote:

None of these goals are mutually-exclusive with logical arguments; that’s a false dichotomy.

I’m not aware of any programming language that is 100% logically consistent. They all make concessions to programmer culture, history, practical concerns, and even opinion/whims. Python doesn’t have multi-line lambdas because Guido doesn’t like them. Even Haskell has unsafePerformIO because the real world is not a pure function. We talk about how beautiful or ugly syntax is all the time, which is absolutely a value judgement.

Russ
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

This is true, but not compelling. While using USD, AUD, CAD, and friends is
better practice for a truly internationalized code base, it does not follow
that use of $ for a more local-consumption code base should be rejected out
of hand.

Jonathan

···

On Wed, Oct 19, 2016 at 1:02 PM, Kevin Ballard via swift-evolution < swift-evolution@swift.org> wrote:

I'm actually vaguely surprised that the other currency symbols are
considered valid identifiers, since they're not alphanumeric symbols. As
for turning them into operators, it's a cute idea, but it doesn't work for
any symbol that's used by multiple countries. For example, would $3.50 be
USD, AUD, CAD, or any of the other dozens of countries that use dollars?

Several people here have called out implicit closure parameters as a
concern, which is actually irrelevant to adopting '$' in parameters.

It is perfectly feasible to accept '$' in parameters *generally*, and
reject identifiers of the form

$ followed by one or more decimal digits

in defining occurrences. This is completely compatible with current Swift
practice, and logically consistent with other kinds of reserved words.

I'm not taking a position pro or con here. I'm saying that we should reject
non-impacting arguments as a basis for deciding one way or the other.

Jonathan

Now for a position:

-1 on this proposal, because '$' should be legal in *any* identifier
position.

+1 for the proposal that '$' should be legal in *any* position.