Hacker News new | ask | show | jobs
by Per_Bothner 2010 days ago
Which is why the sane way to do it is to have the array-specifier come before the element type:

  [,][]int crazy;
It reads "2-dimensional array of array of int" in L-to-R order.

Similarly, the type "pointer-to-int" should be "*p" or equivalent.

Unfortunately, history/tradition as well parsing problems make the "sane" solution difficult. One solution is the Pascal approach putting the type after the variable being declared, with a colon between:

  crazy : [,][]int;
1 comments

Strongly agreed! During my PhD I had to design array type syntax for a programming language, and we eventually came up with something similar to that: https://futhark-lang.org/blog/2016-12-09-two-syntax-design-p...