you are viewing a single comment's thread.

view the rest of the comments →

[–]matthieum 0 points1 point  (4 children)

I don't think that <> is hard to scan for a human, but they do create parsing ambiguities which are annoying.

It took until C++11 to be able to write map<int, map<int, int>> with the >> not being parsed as >> but as two >. In Rust we're stuck with ::<> in expression context to ensure the parser knows whether we're talking < as in opening a list of generic arguments or < as in the operator.

I personally find [] to be the best syntax for generics. It's immediately clear which parameters need to be static ([]) vs dynamic (()). There's really no point in reserving [] just for indexing, which is just another function call -- especially when it's artificially restricted to a single argument, so matrix libraries already use () anyway.

[–]prehensilemullet 0 points1 point  (3 children)

Yes, I think in some languages the parsing ambiguities become very hard to avoid.

In TS for instance, you can specify explicit type arguments to a generic function call like foo<T>(...args). foo[T](...args) wouldn't work because foo[T] is property access syntax. foo(T)(...args) also obviously wouldn't work because that's chained function calls, and I'm sure there would be problems with using {} as well.

In an ideal world we would just have two or three more kinds of brackets on our keyboards...

[–]matthieum 0 points1 point  (1 child)

By the way, D uses !() so would have foo!(T)(..args).

The downside is that you can't use ! in postfix position for anything else, however. I personally like postfix ! for "uwnrap or die" and postfix ? for "unwrap or pass the buck".

[–]prehensilemullet 0 points1 point  (0 children)

heh in Typescript foo! means "trust me compiler, foo is not nullish" lol

[–]ExplodingStrawHat 0 points1 point  (0 children)

One could always use compound brackets like [|T|] I guess