5 ms·
Nice little change in syntax. m := map[Point]string{ Point{29.935523, 52.891566}: "Persepolis", Point{-25.352594, 131.034361}: "Uluru",
by melling 11y ago
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",
}
- nickysielicki 11y agoI 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.
- deleted 11y ago[deleted]
- zachberger 11y agoIt's in the declaration of the map. Rewriting it over and over is redundant encoding
- axaxs 11y agoMuch 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.
- iokevins 11y agoThey seem to say you may choose to continue specifying it, as you prefer (?)
- nickysielicki 11y agoSure, 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.
- zak_mc_kracken 11y agoI'm puzzled about the asymmetry of the syntax. What's the reason behind map[Point]string as opposed to something more symmetrical?
- DrJokepu 11y agoIt 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).
- socceroos 11y agoI've never seen that explained so succinctly. Thank you.
- aikah 11y agomakes 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.
- enneff 11y ago> something everybody would be comfortable with Not possible.
- 4ad 11y agoThis worked for structs since a very long time, the change makes maps consistent too.