Language Design: Use 'ident: Type' not 'Type ident'
1–10 of 192 posts
Re: Language Design: Use 'ident: Type' not 'Type ident'
#2Re: Language Design: Use 'ident: Type' not 'Type ident'
#3Re: Language Design: Use 'ident: Type' not 'Type ident'
#4You'd have to show me some data that one is easier to work with than the other, because fundamentally types _are_ names, and I find them just as expressive as variable names (many of which are just named after types, lets be honest). Even if I didn't, I don't think my brain struggles to read things in either order (or indeed in languages where types are rarely mentioned).
The same should happen for types.
Re: Language Design: Use 'ident: Type' not 'Type ident'
#5You'd have to show me some data that one is easier to work with than the other, because fundamentally types _are_ names, and I find them just as expressive as variable names (many of which are just named after types, lets be honest). Even if I didn't, I don't think my brain struggles to read things in either order (or indeed in languages where types are rarely mentioned).
Re: Language Design: Use 'ident: Type' not 'Type ident'
#6Syntax isn't unimportant, but don't waste energy on trivial matters like these. Just pick something and people will get used to it. Focus on the semantics of your language - that's what really matters.
Re: Language Design: Use 'ident: Type' not 'Type ident'
#7> This means that the vertical offset of names stays consistent, regardless of whether a type annotation is present (and how long it is) or not.
Why is this necessarily desirable? Strong typing systems have very expressive types, to the point where if something is typed correctly, most of the time my property names are just an alternative casing of the type. Types can be just as expressive or even more expressive than variable names.
> The i: Int syntax naturally leads to a method syntax where the inputs (parameters) are defined before the output (result type), which in turn leads to more consistency with lambda syntax (whose inputs are also defined before its output).
Maybe this is nice in theory? But `Int` really isn't an output here, and the value being assigned isn't either. Rather this seems more like `f(i, Int, value) -> assignment`. It seems just as arguable that `f(Int, i, value) -> assignment` is appropriate.
It seems like some of these are rooted in a "pure mathematical" approach which I can surely appreciate, but ultimately lambda calculus is as much a language as any other programming language, saying "lambda syntax does it this way" doesn't convince me very much.
Re: Language Design: Use 'ident: Type' not 'Type ident'
#8 A * B;
is a multiplication or a variable declaration, or whether A D;
is a two comparisons with a comma operator or a templated variable declaration, without first knowing the names of all declared types.This means in practice that you have to declare types before they are used in a file, which means forward-declarations if they are defined later, that you can't separate lexing and parsing because the parser has to provide constant feedback to the lexer, and that misspelling a type name can lead to a syntax error! C++, not content with merely inheriting C's problems, throws in the “most vexing parse” as a bonus.
Re: Language Design: Use 'ident: Type' not 'Type ident'
#9Language Design: This stuff doesn't matter that much. Focus on more important things. Syntax isn't unimportant, but don't waste energy on trivial matters like these. Just pick something and people will get used to it. Focus on the semantics of your language - that's what really matters.
One of the things that using ":" does is it makes what is "type" and what is "name" unambiguous to both human and computer.
This is, famously, one of the failings of C/C++. Determining what is a type and what is a name is excruciatingly difficult.
Re: Language Design: Use 'ident: Type' not 'Type ident'
#10This feels a little nitpicky/idealistic, I don't think the post does a good job of conveying why it's more beneficial. > This means that the vertical offset of names stays consistent, regardless of whether a type annotation is present (and how long it is) or not. Why is this necessarily desirable? Strong typing systems have very expressive types, to the point where if something is typed correctly, most of the time my…
As other posters have stated, this order makes parsing easier. But I also suggest this benefit extends to your own brain's parsing ability as well. The old order is indirect and suboptimal and makes you think harder.