News for hackers. Stuff that matters.
Re:Spf13 is leaving Google by giveupitscrazy on Tuesday July 19, 2022 @02:25AM (#32148184)
I know zero go, despite having worked with it professionally for a short stint that I try and block out of my memory (not go's fault), anyway that first example looks like gibberish to me while the second is super clear.
Re:Spf13 is leaving Google by badsectoracula on Tuesday July 19, 2022 @05:36AM (#32149371)
FWIW i also know zero Go but the first example made sense (though while i don't know Go, i do know it has multiple return values): the "m[key]" part returns two values which are assigned to the "_, ok" expression which represents a value to be ignored and an "ok" variable which is later used in the "; ok" part (i guess ; separates multiple subexpressions similar to C's "," and the overall expression's value is the last subexpression) and so the two values returned from "m[key]" are the map's value and a boolean (or something that can be used like that) that checks if the value was found. In which case "if _,ok := m[key] {" would be the same as something like "if m.contains(key) {".

Of course this is all guesswork based on similar stuff i've seen elsewhere, so i might be off, but i think despite not knowing the language it still looks readable if you know any other mainstream language (and exercise some guesswork/imagination :-P).

Re:Spf13 is leaving Google by konart on Tuesday July 19, 2022 @02:34AM (#32148240)
Well, that's because you do not work with go much I guess?

I can say the same about Fennel, List or Haskell.

The first example is the way to go in Go. It's idiomatic, not a hack. And it works the same way for many things (for example checking if a channel's closed)

Re:Spf13 is leaving Google by tptacek on Tuesday July 19, 2022 @02:29AM (#32148209)
It is deeply idiomatic in the language.
Re:Spf13 is leaving Google by IshKebab on Tuesday July 19, 2022 @02:33AM (#32148231)
But only because there's no `contains` function!
Re:Spf13 is leaving Google by ignoramous on Tuesday July 19, 2022 @03:40AM (#32148610)
If perl has taught us anything... 3 ways to do something is worse than 1.
Re:Spf13 is leaving Google by peoplefromibiza on Tuesday July 19, 2022 @03:43AM (#32148635)
what `contains` what?

you could write this in Go

   if m[key] { }
the comma ok idiom simply lets you distinguish a "zero" value from a missing value.
Re:Spf13 is leaving Google by ndr on Tuesday July 19, 2022 @05:10AM (#32149214)
Agreed that `key in m` or `m.contains(key)` would be clearer, but checking the value rather than the presence is asking for trouble.
Re:Spf13 is leaving Google by simiones on Tuesday July 19, 2022 @05:19AM (#32149273)
`if m[key] { }` is only valid Go if m is a map from something to bool, so I don't know what you even mean.
[dead]
Re:Spf13 is leaving Google by soganess on Tuesday July 19, 2022 @04:10AM (#32148803)
Your parent knows how's to read code and can recognize the purpose of the second statement but not the first. While that is not some end-all metric, it does says something about the Go idiom's clarity.

Hopefully that helps explain the matter...

Re:Spf13 is leaving Google by rat9988 on Tuesday July 19, 2022 @03:57AM (#32148728)
You missed why his comment is insightful. It's for the very reason he knows a bit about the topic but not too much.
Re:Spf13 is leaving Google by LadyCailin on Tuesday July 19, 2022 @04:16AM (#32148845)
It is. Because everyone starts out knowing zero go, and so the learning curve of a language (and for people who know another programming language first) is very much a key metric.
Re:Spf13 is leaving Google by sph on Tuesday July 19, 2022 @04:21AM (#32148877)
I know pretty much nothing about Scala. Anybody cares for my criticism of its type system? And what's with Rust and those ampersands everywhere?

GP wasn't discussing the language in general, just a small feature that depends on an idiomatic pattern used in many other places, saying "it looks gibberish." Of course it does, because it isn't idiomatic for you.

Re:Spf13 is leaving Google by LadyCailin on Tuesday July 19, 2022 @10:35AM (#32152133)
You don’t need to know that to do the comparison. If I tell you to do the same thing in one language it’s “(!:;$&)” and in another it’s “array_contains”, you don’t even need to know the languages to have a reasonable opinion on which is superior.