Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nice little change in syntax.

    m := map[Point]string{
        Point{29.935523, 52.891566}:   "Persepolis",
        Point{-25.352594, 131.034361}: "Uluru",
        Point{37.422455, -122.084306}: "Googleplex",
    }
may now be written as:

    m := map[Point]string{
        {29.935523, 52.891566}:   "Persepolis",
        {-25.352594, 131.034361}: "Uluru",
       {37.422455, -122.084306}: "Googleplex",
    }


I'm puzzled about the asymmetry of the syntax. What's the reason behind

    map[Point]string
as opposed to something more symmetrical?


It makes sense if you're used to Go. In Go, in function declarations return types come after the argument list, e.g:

    func doSomething(input string) string { ... }
The go map declaration syntax is analogous to the function declaration syntax: the keyword (map, analogous to the func keyword) followed by the type of the keys in brackets (analogous to the argument type in parentheses) followed by the type of the values (analogous to the return type).


I've never seen that explained so succinctly. Thank you.


makes little sense but since go doesn't have user defined parametric types, it makes no difference.

Now I wish I had 1 million dollars and a better brain to work full time on a proper language that would fix go's issues. What a missed opportunity to create something everybody would be comfortable with. It could have been the biggest language of the next 20 years in webdev, CSP is a great concurrency model. At least it will inspire some people in the future I hope. Rust is cool but doesn't have CSP builtin.


> something everybody would be comfortable with

Not possible.


This worked for structs since a very long time, the change makes maps consistent too.


I came into the comments to say that I very much dislike this change. I much prefer the extra syntax to not really knowing what '{29.935523, 52.891566}' actually means.


It's in the declaration of the map. Rewriting it over and over is redundant encoding


They seem to say you may choose to continue specifying it, as you prefer (?)


Sure, I can write code the way I like. But the readability of code affects everyone, not just me.

Still, 4ad's comment above mine changed my mind. I didn't consider that you can do this with structs already (in spite of the fact that I already do that in my code), and I prefer the consistency to the lack of verbosity.


Much agreed. Call me a masochist, but I prefer extra typing if it means readability, to me. And while subjective, retyping Point{} is much clearer to me than {}. It just looks...wrong.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: