I'm in favor of the square brackets. scala has them as well so we're not
exactly blazing a new trail. I'm not in favor of a second `type` keyword
whose benefit is to disambiguate syntax to the parser. we already use
significant whitespace to identify tokens. for example, we expect to be
parsing a function after we've parsed the `func\s+`. I'll take a parsing
error over repeated the type keyword. In this regard we're not along
either. Erlang's less-than-or-equals operator is =<. It inadvertently makes
whitespace a requirement when doing binary syntax: `X = <<"hello">>`.
Without the significant whitespace after the equals sign, the Erlang parser
always finds the `=<` operator, which leads to a parsing error. A similar
behavior for the square brackets syntax will be desirable.

On Wed 15 Jul 2020 at 09:32 Max <massimiliano.ghila...@gmail.com> wrote:

> I think square brackets are better than parentheses for several reasons:
>
> 1. fewer parser ambiguities (see the post that started this thread) - thus
> fewer cases where programmers must remember "oh, this is a special case, I
> must put additional parentheses somewhere"
> 2. programmers can distinguish more easily between a template
> instantiation `T1[T2]` and a function call `T1(T2)`. Index expressions
> would have the same syntax as single-type template instantiations `T1[T2]`,
> but I believe they are somewhat less common than function calls in most code
> 3. Go already uses a similar syntax for builtin types: `map[K]V`. A
> generic key/value container would look like `Map[K, V]` which is pretty
> close
>
> In my Go interpreter, I went a step further and implemented the syntax
> `T1#[T2, T3]` for generics instantiation. It may not be everybody's
> favorite, but removes all parsing ambiguities.
>
> An alternative syntax, more similar to other proposals I have seen, is
> `T1:[T2, T3]` - it could be visually better, but I think it introduces
> ambiguities in `case` and labels marking `goto` destinations - both already
> use ':' as delimiter.
>
> On Wednesday, July 15, 2020 at 6:14:31 AM UTC+2, Ian Lance Taylor wrote:
>>
>>
>> The advantage of parentheses is that the language already uses
>> parentheses for lists in various places.  Of course that is also the
>> disadvantage.
>>
>> When considering something other than parentheses, I encourage people
>> to look for objective reasons why one syntax is better than another.
>> It's going to be different from other aspects of the language.  So
>> what reason would we have for preferring one syntax over another?
>>
>> For example:
>>
>> Robert already gave reasons why square brackets are better than angle
>> brackets.
>>
>> The disadvantage of guillemets is that they are hard to type on many
>> keyboards.  So to me either square brackets or angle brackets would be
>> better than guillemets.
>>
>> The disadvantage of a two character sequence such as <: :> is that it
>> is more typing.  So again either square brackets or angle brackets
>> seem to me to be better.
>>
>> An example of a reason that square brackets might be a poor choice
>> would be ambiguous parsing, or cases where the code is harder to read.
>>
>> It's true that some other languages use angle brackets, but Go already
>> does many things differently.  That is only a minor advantage for
>> angle brackets.  To me at least it does not outweigh the
>> disadvantages.
>>
>> In short, please try to provide reasons for a different syntax.  "It
>> looks good" is a valid reason, but please try to explain why it looks
>> better than square brackets or parentheses.
>>
>> Thanks.
>>
>> Ian
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/1e8397a5-bcc9-48b8-924b-1d35f4434d14o%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/1e8397a5-bcc9-48b8-924b-1d35f4434d14o%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
-- 
*Curried programmer*
*Homepage*: http://yawboakye.com
I'm tweeting <https://twitter.com/@22bytes> when I'm not coding
<https://github.com/yawboakye> when I'm not holding my niece.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAPJoGXtWxdEf8iyhWjuOeWv_fEtWLtfbkU7ZTnvDOtvYjPVy5w%40mail.gmail.com.

Reply via email to