Live data from Hacker News

Language Design: Use 'ident: Type' not 'Type ident'

soc.me

1–10 of 192 posts

Re: Language Design: Use 'ident: Type' not 'Type ident'

#2
You'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'

#4
post #2

You'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).

I mean most programming languages put some sort of punctuation between names. Eg: function calls are punctuated by parens, imports are punctuated by `::` or `.`.

The same should happen for types.

Re: Language Design: Use 'ident: Type' not 'Type ident'

#5
post #2

You'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).

It's easier to parse if nothing else.

Re: Language Design: Use 'ident: Type' not 'Type ident'

#6
Language 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.

Re: Language Design: Use 'ident: Type' not 'Type ident'

#7
This 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 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 more practical reason as a language designer is that C and C++-style type-before-name syntax is a nightmare to lex and parse, as you can't tell whether

  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'

#9

Language 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.

Actually, syntax IS important because a language has to be able to be read by both a human AND a computer, nowadays.

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'

#10
post #7

This 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…

I've been using Rust a lot recently, which puts names before types and inputs before outputs, and I will absolutely attest to how much mental work is saved by ordering things this way. Skimming or reading Rust comes twice as easy as reading Java, and I do a lot of both. Sure it's an anecdotal report, but I have a real sense here that I feel compelled to report.

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.

Post reply on HN