[swift-evolution] Enable omitting `let` for constant declarations

Yuta Koshizawa koher at koherent.org
Fri Apr 1 06:58:31 CDT 2016

I think it would be good if the following three declarations were equivalent

let a: Int = 42
a: Int = 42
a := 42

and also the following two were.

let a: Int
a: Int

Then constant declarations become shorter than variable declarations.
It encourages people to use constants in preference to variables.

It also prevents repeating `let` for property declarations and makes
type declarations simpler.

struct Person {
    firstName: String
    lastName: String
    age: Int

Omitting `let` is consistent with that we don't write `let` for
arguments of functions and iterated values in for-in loops.

Not `=` but `:=` for type inferences because `=` cannot distinguish
whether it means a constant declaration or an assignment to a variable
declared in an outer scope. I think `:=` is a natural notation for
type inferences because omitting the type from `a: Int = 42` makes
`a:= 42`. Because I have not strictly checked if it can be parsed in
Swift properly, it may have some other parsing issues.

What do you think about it?

-- Yuta

More information about the swift-evolution mailing list