DEV Community

Discussion on: Why do some languages disrupt some common and habitual conventions?

Collapse
 
dmfay profile image
Dian Fay

The long & short of it is that the creators decided that these idioms convey the concepts the language uses better. I'm not familiar with Go's type system but [5]string seems to imply that something is an array first and a container for strings second; someone who knows the language may be able to elaborate why that distinction is useful. Type on the right can be found everywhere from BASIC to Scala so as far as I know that's simply a case of drawing from conventions you're not familiar with.

Collapse
 
rhymes profile image
rhymes • Edited

There's an explanation in the official Go blog - blog.golang.org/gos-declaration-sy.... Basically they chose that syntax because it's easier to read.

var books [5]string

reads as "declaring a var named books as an array of 5 strings"

Collapse
 
perigk profile image
Periklis Gkolias

That makes sense :)