Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notation of type value arguments #3497

Closed
msadeqhe opened this issue Dec 12, 2023 · 5 comments
Closed

Notation of type value arguments #3497

msadeqhe opened this issue Dec 12, 2023 · 5 comments
Labels
leads question A question for the leads team

Comments

@msadeqhe
Copy link

Summary of issue:

I think :! is misleading in type argument declarations. Because ! is widely accepted as a symbol to denote negative (! in C) or dangerous (like BANG! in comics) behavior. != is already used as the meaning of negative ! in Carbon.

Details:

Although ! is used to call macros in Rust, but IMO it's a symbol of dangerous here. Because & prefix is required to pass references to functions. But it's not required for macros, therefore a macro can change it's parameters while they don't look like references. It's dangerous and different than regular function calls. Maybe that's why every macro name has ! postfix in Rust.

Also in Swift, when we have .? to access members of an optional value (it returns null if it fails), we can use .! to access its members in a dangerous way (it throws an exception if it fails). And in Kotlin, !! allows a null pointer exception.

Generally ! means negative, dangerous, warning and surprising.

Notation :! is neither negative, nor dangerous. It's a safe way to have type value arguments.

On the other hand, type value arguments are just like let/var arguments but they are types instead of values. So :! can be a keyword just like let/var. template type value arguments already have the keyword:

fn name[KEYWORD T: type](var x: T*, template U: type) {...}

So instead of let template, it will be change to template. It improves consistency with let/var declarations:

// Before
let template ConstraintName:! type = C where <condition>;
let TypeName:! type = <type>;

// After
template ConstraintName: type = C where <condition>;
KEYWORD TypeName: type = <type>;

Also what if we use type instead of KEYWORD, and change the type to auto?

// Before
let template ConstraintName:! type = C where <condition>;
let TypeName:! type = <type>;

// After
template ConstraintName: auto = C where <condition>;
type TypeName: auto = <type>;

So we will have let/var/type/template declarations. Their type can be auto which it means the type is deduced from the value.

When I saw :! at the first time, I immediately ignored to read about Carbon. But months later, when I learned what :! means, I liked the idea (the semantic). I don't know how many programmers had a similar reaction like me. So :! can be changed to a familiar notation (a keyword maybe is preferable).

If it's desirable to change :!, I'll prepare a proposal for it. I see that using a keyword is already considered in proposal P0676. Thanks.

Any other information that you want to share?

No response

@msadeqhe msadeqhe added the leads question A question for the leads team label Dec 12, 2023
@geoffromer
Copy link
Contributor

See #565 and #1425 for other discussions of this issue. As discussed here, in order to make progress we avoid revisiting decisions that have already been made unless unless there is substantial new information to consider, and the main points that you raise have been raised in prior discussions.

By the way, :! is not limited to types; it only means that the parameter is bound at compile time, and ordinary values can be bound at compile time just like types can. As a result, type would be a very confusing keyword to use for this purpose.

@geoffromer
Copy link
Contributor

(Reclassifying)

@geoffromer geoffromer closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2023
@msadeqhe
Copy link
Author

It seems #1425 is a data to consider. Because it has many up votes, it means many programmers doesn't feel :! is related to compile-time.

There is a new information to revisit the decision: The reason that Rust uses it, isn't enough, because as I have explained, ! is not exactly about compile-time in Rust.

@geoffromer
Copy link
Contributor

It seems #1425 is a data to consider. Because it has many up votes, it means many programmers doesn't feel :! is related to compile-time.

As was recently explained in another context, GitHub polls are not representative enough of Carbon's target audience to give us much useful information. GitHub upvotes have all the same problems as polls, and also are inherently biased, and don't give us a denominator we can compare to.

There is a new information to revisit the decision: The reason that Rust uses it, isn't enough, because as I have explained, ! is not exactly about compile-time in Rust.

We were already familiar with how Rust uses !, so that part isn't new, and the rest seems to be opinion or argument, rather than factual information.

@msadeqhe
Copy link
Author

OK, You're right. My reasoning wasn't enough. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
leads question A question for the leads team
Projects
None yet
Development

No branches or pull requests

2 participants