DEV Community

Periklis Gkolias
Periklis Gkolias

Posted on

Why do some languages disrupt some common and habitual conventions?

I am diving into Golang, those days. I have noticed that the syntax is most of the times against the "common sense".

For example, this how they declare an array and a function:

var books [5]string

func printListInts(intz ...int) {
    fmt.Println(intz)
}
Enter fullscreen mode Exit fullscreen mode

where most languages do it like

books = string[5] // The length on the right
function foo(int ...mylist) { // Type on the left
}
Enter fullscreen mode Exit fullscreen mode

I am very happy to see structural changes to a languages logic but why are they doing such "trivial" and "nonsense" changes?

Latest comments (9)

Collapse
 
tux0r profile image
tux0r

"Common and habitual conventions" are defined by whoever uses that term. Rob Pike, one of Go's designers, spent some time with Smalltalk and similar languages, Go even adds a couple of features from C's predecessors BCPL and B.

Collapse
 
quii profile image
Chris James

Just wait till you start touching any kind of lisp. You'll basically hate all syntax from then on.

Collapse
 
bgadrian profile image
Adrian B.G.

First of all, I think you are only familiar with only a few of programming languages and paradigms, there are other types of languages beside c-style.

Go will feel familiar in some places, and very strange in others. This happens because it is the only language (I know) that unifies the two branches of languages that started from Algol (Pascal and C). Steve Garcia explains it better than I could ever do:

Collapse
 
perigk profile image
Periklis Gkolias

Yeah, I am mostly familiar with C-style languages, so this makes sense

Collapse
 
ben profile image
Ben Halpern

Here's a good video that touches on some of this if I recall correctly. (Good talk on language design either way, I forget some of the details)

Collapse
 
perigk profile image
Periklis Gkolias

Nice one Ben, I ll check it out. Thanks :)

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 :)