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

Change capitalization for Sequence, Dictionary and Result #644

Closed
bernardnormier opened this issue Aug 1, 2023 · 3 comments
Closed

Change capitalization for Sequence, Dictionary and Result #644

bernardnormier opened this issue Aug 1, 2023 · 3 comments
Labels
Milestone

Comments

@bernardnormier
Copy link
Member

bernardnormier commented Aug 1, 2023

We currently spell sequence, dictionary and the proposed result in lowercase, like most other keywords.

I propose to use instead Pascal case for these keywords: Sequence, Dictionary and Result.

Rationale

In many languages, including Slice, type names--including generic type names--are Pascal case. Sequence and Dictionary can be used as types, and syntactically Result is used as a return type. Pascal case is the expected capitalization for this usage in Slice.

Note that in Ice, sequence and dictionary could not be used as types. They were more like struct, with:

// Old slice

struct Point { int x; int y; }

sequence<Point> PointSeq;   // sequence is used as "struct" here, to build a new constructed type
@bernardnormier bernardnormier added this to the 0.1 milestone Aug 1, 2023
@InsertCreativityHere
Copy link
Member

I'm fine with any kind of capitalization, we should just pick one and be consistent about it.

Buttt, to play devil's advocate, I've always felt the rationale is that keywords should be lowercase and constructed types should be PascalCase. It just so happens that in many languages dictionary and sequence types are backed by constructed types:
Sequence, HashMap, IDictionary, Vec, IList, etc.
So I'd bet good money that if C# were to add a keyword version for List, it would be lowercase.

Take Java for example, which has both:

  • int a primitive type that is specified by a keyword (and hence lowercase)
  • Integer a constructed type (and hence PascalCase)

Or far interestingly, Rust. One of the core types in Rust is Box. It's used to store data on the heap.
In old Rust, it was so special that it was given a keyword:

let x = ...;
let boxed = box x;

But after some time, they changed their mind and made Box a normal constructed type like anything else:

let x = ...;
let boxed = Box::new(x);

When it was a keyword, they used lowercase, when they made it a constructed type they used PascalCase.
The issue where they phased out the old keyword version: rust-lang/rust#49733

@bernardnormier
Copy link
Member Author

While it's true that keywords are usually lowercase, it's not a strict rule. For keywords used as special type names, it's arguably common to see them in Pascal case.

Take Self in Rust, or Any, Protocol, Self and Type in Swift.

With your example, the old box didn't use a normal type syntax. We use the "normal" type reference syntax for Dictionary etc. (putting aside the non-standard <...>).

Another advantage of changing the spelling of these keywords is you can more easily use them as parameter names and field names, per the usual Slice naming conventions:

op(sequence: Sequence<int32>) // doesn't work without escaping if sequence is keyword

Maybe they could be soft keywords (https://docs.python.org/3/reference/lexical_analysis.html#soft-keywords) but this sounds overkill. It's easy to escape keywords.

@InsertCreativityHere
Copy link
Member

This was implemented in a3f3463

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

No branches or pull requests

2 participants