Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


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


> 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


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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: