5 ms·
I always read the colon as separating a term (introduced for the first time) and its definition. Just compare the characters list in literature: Hercule Poir
by teo_zero 3y ago
I always read the colon as separating a term (introduced for the first time) and its definition. Just compare the characters list in literature:
Hercule Poirot: an investigator
Linnet Doyle: a rich heiress
... with the list of variables at the beginning of a function:
x: TypeX
y: TypeY
It makes perfect sense to me.
- agalunar 3y agoI think I would completely agree for you if it were a definition and not a type annotation! That is, "x: 5" instead of "x = 5" (or "x ← 5", &c) looks fine to my eyes. And of course, that's how values for the members of a struct are in fact defined in many languages (such as Rust). I suppose the underlying point is that has-type is a relation, not a definition. Asymmetrical space around a binary relation violates (my) experience, but it's also a bit confusing to use the same syntax for definition and type annotation.
- teo_zero 3y agoYou may have a broader scenario in mind, but my experience is limited to languages like Rust and C where the type is linked to an object the moment that object is declared for the first time, and can't be changed later. These languages do use the same syntax for definition and type annotation. I will remember this conversation when I encounter a language that allows this (declaration in the first line, type annotations follow): var x x : Integer x = 5 ... x : String x = "hello"