# Consistent syntax for generic parameters

**URL:** <https://internals.rust-lang.org/t/consistent-syntax-for-generic-parameters/242>\
**Category:** bikeshed (deprecated)\
**Created:** [July 23, 2014, 4:30am UTC](https://internals.rust-lang.org/t/consistent-syntax-for-generic-parameters/242 "2014-07-23T04:30:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zoxc](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/zoxc/32/4000_2.png) [@Zoxc](https://internals.rust-lang.org/u/Zoxc)\
**Post date:** [July 23, 2014, 4:30am UTC](https://internals.rust-lang.org/t/consistent-syntax-for-generic-parameters/242/1 "2014-07-23T04:30:26Z")

</div>

Currently you have to write `path<...>` in type contexts and `path::<...>` in expressions. As a C++ user and a new user of Rust forgetting the `::` in expressions is one of the most common errors I make. This is made worse by the fact that the error messages when making this error aren’t obvious. I’ll probably get used to this eventually, but it’s certainly not an inviting trait.

To solve this we need an unified syntax across both types and expressions. However freeing up `<`, and `>` isn’t an acceptable solution. It has a strong precedent set by maths. Neither is using `(...)` since we really want that for calls. `{...}` is taken by object literals and would probably be a bit noisy for generics. That leaves us `[...]` which is currently used for indexing. Given that indexing takes two operands, it doesn’t strictly need matching braces. Rust also have strong functional programming influences which would hopefully make indexing less pervasive than in C. I’ve yet to see it in Rust code, but that may have something to do with it supposedly being broken. I feel it’s preferable to free up `[...]` for generics which would be way more common than indexing in idiomatic Rust code.

Feel free to bikeshed an alternative syntax for indexing. Some suggestions:

```
vec'0
vec'i
vec'(i + 1)

vec'0
vec'i
vec'(i + 1)

vec\0
vec\i
vec\(i + 1)

vec#0
vec#i
vec#(i + 1)
```

---

<div class="post-metadata">

**Author:** ![japaric](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/japaric/32/28_2.png) [@japaric](https://internals.rust-lang.org/u/japaric)\
**Post date:** [July 23, 2014, 4:39pm UTC](https://internals.rust-lang.org/t/consistent-syntax-for-generic-parameters/242/2 "2014-07-23T16:39:35Z")

</div>

> [@Zoxc](#):
>
> I feel it's preferable to free up [...] for generics which would be way more common than indexing in idiomatic Rust code.

There was [an RFC](https://github.com/rust-lang/rfcs/pull/148) about changing the `<>` back to `[]` for generics, which also spawned a [reddit thread](http://www.reddit.com/r/rust/comments/29jrhs/rfc_switch_back_to/).

Finally, the RFC got closed by its author:

> [@TheHydroImpulse](#):
>
> Thanks everyone for comments on both sides of the argument. However, it's clear that it's simply too late for a syntax change without any real benefits that aren't subjective. I originally proposed the RFC because I thought we could get rid of the ambiguities, but I had forgotten about indexing; thus, the only arguments that were left were indeed subjective.

* * *

Regarding your proposed changes, I think is going to be really hard to convince people to change both `[]` indexing and `<>` for generics, given their strong prevalence in PLs due to the C/C++ tradition.

That being said, of your indexing syntax proposals, the last one `vec#0` looks less awkward to me.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:22am UTC](https://internals.rust-lang.org/t/consistent-syntax-for-generic-parameters/242/3 "2019-03-25T08:22:39Z")

</div>

Closed on March 25, 2019, 8:22am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
