Why was 's: string' used for type definition instead of C's 'string s'

Why was ‘s: string’ used for type definition instead of C’s ‘string s’, I notice it’s also used in Pascal so it’s not really new, probably goes back decades. I also notice many other languages use it, e.g. Swift, Rust, TypeScript, even Python, it seem to be a trend. What advantages has it from user perspective and from compiler developer perspective compared to the C way?

Well for one, declaration type inference patterns stay consistent with the rest of the language.

val x = 1
val x: Int = 1

fun double(x: Int) = x * 2

This is makes it nice to parse inferred types. From a compiler perspective, you don’t have to guess or look forward or look backward to see if an identifier is a type or the variable name.

1 Like