← Back to context

Comment by LexiMax

1 day ago

16 years is a bit of an under-estimate. I think the first popular language with this form of declaration was Pascal.

    var
        foo: char;

Go was developed by many of the minds behind C, and inertia would have led them to C-style declaration. I don't know if they've ever told anybody why they went with the Pascal style, but I would bet money on the fact that Pascal-style declarations are simply easier and faster for computers to parse. And it doesn't just help with compile speed, it also makes syntax highlighting far more reliable and speeds up tooling.

Sure, it's initially kind of annoying if you're used to the C style of type before identifier, but it's something you can quickly get to grips with. And as time has gone on, it seems like a style that a lot of modern languages have adopted. Off the top of my head, I think this style is in TypeScript, Python type hints, Go, Rust, Nim, Zig, and Odin. I asked Claude for a few more examples and apparently it's also used by Kotlin, Swift, and various flavors of ML and Haskell.

But hey, if you're still a fan of type before variable, PHP has your back.

    class User {
        public int $id;
        public ?string $name;

        public function __construct(int $id, ?string $name) {
            $this->id = $id;
            $this->name = $name;
        }
    }

I have no problem with ident: type. I have problem with dropping the colon between them for no good reason, even though there used to be 2 quite well-established patterns every language adhered to.

> don't know if they've ever told anybody why they went with the Pascal style

I don’t know if this is the reason but Robert Griesemer, one of the three original guys, comes from a Pascal/Modula background.

Golang exists in this weird place where it's similar enough to C so that intuition connects it with C, but at the same time different enough that you keep tripping over.