News for hackers. Stuff that matters.
Re:Carbon Language: An experimental successor to C++ by notriddle on Tuesday July 19, 2022 @11:44AM (#32153246)
It's not just Rust syntax. `name: Type` is the syntax used in TypeScript and Python type annotations (also Ocaml, which is probably where Rust got it from). Golang drops the colon, but still keeps the name first.

As for what's wrong with `Type name(constructor, args)`? A lot of tooling wants to be able to parse "mostly-valid C++", like IDEs and compiler diagnostics. Sure, once clang's type inference is finished, the lexer hack and most vexing parse aren't problems, but when the program isn't complete, parsing isolated fragments is impossible, and that limits the amount of useful tooling the language can have.

Re:Carbon Language: An experimental successor to C++ by c-cube on Tuesday July 19, 2022 @12:36PM (#32154237)
The syntax `name: Type` is also friendlier to type inference as you generally have a token indicating a declaration. If you have `var x: Type = …` then you can just omit the type and let inference do its job.

Even better, when you start having more complex patterns on the left-hand side of `=`, you can type annotate them as you want. Hypothetical syntax would be:

    var (x: f32, y, [z1,z2,z3]) = SomeExpression(); 
That's harder to do when you have a type declaration on the left imho.
Re:Carbon Language: An experimental successor to C++ by amai on Tuesday July 26, 2022 @08:33AM (#32237418)
On the other side `name:Type` doesn't allow an IDE to suggest a name based on the type, because you type the name first. Also setting values looks pretty confusing. I claim writing the type before the name is much more readable. Compare

    five: integer = 5
or

    integer five = 5
Re:Carbon Language: An experimental successor to C++ by notriddle on Tuesday July 26, 2022 @09:02PM (#32245867)
> I claim writing the type before the name is much more readable. Compare

I claim writing the name first is much more readable. Compare

    integer five = 5
or

    five: integer = 5
Re:Carbon Language: An experimental successor to C++ by nyanpasu64 on Tuesday July 19, 2022 @02:07PM (#32155667)
It would make sense if Carbon started allowing omitting ": Type", which they currently don't: https://github.com/carbon-language/carbon-lang/blob/trunk/do...
Re:Carbon Language: An experimental successor to C++ by cyber_kinetist on Tuesday July 19, 2022 @12:07PM (#32153742)
And to add, the `name: Type` syntax is not just a modern fad, don't forget the OG language that did this: Pascal! (https://en.wikipedia.org/wiki/Pascal_(programming_language))
Re:Carbon Language: An experimental successor to C++ by beeforpork on Tuesday July 19, 2022 @11:54AM (#32153478)
OK, I see. Yes, C and C++ syntax is definitely ambiguous without semantic analysis. Maybe this could also be explained somewhere.
Re:Carbon Language: An experimental successor to C++ by kzrdude on Tuesday July 19, 2022 @04:50PM (#32157776)
There is a lot of Rust in the Carbon syntax.

`fn`, `name: Type`, `i32`, `->` for return type. `impl` as a keyword. `Self` as a keyword.

Nothing unique to Rust, but it's interesting to see.