Why do some languages disrupt some common and habitual conventions?

twitter logo github logo ・1 min read

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

where most languages do it like

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

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

twitter logo DISCUSS (9)
markdown guide
 

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.

 

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"

 
 

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:

 

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

 

"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.

 

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)

 
 

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

Classic DEV Post from Apr 29

Terrible Interview Questions

Job interview questions which are so bad, that they are funny.

Periklis Gkolias profile image
In love with Python, but I admire all the stacks that offer solutions without testing my patience. Avid productivityist, great-food worshipper, always-smiling.