5 ms·
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
by giveupitscrazy 4y ago
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.
- konart 4y agoWell, 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)
- tptacek 4y agoIt is deeply idiomatic in the language.
- IshKebab 4y agoBut only because there's no `contains` function!
- ignoramous 4y agoIf perl has taught us anything... 3 ways to do something is worse than 1.
- peoplefromibiza 4y agowhat `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.
- sph 4y ago
- LadyCailin 4y agoIt 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.
- sph 4y agoI 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.
- LadyCailin 4y agoYou 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.
- rat9988 4y agoYou missed why his comment is insightful. It's for the very reason he knows a bit about the topic but not too much.
- soganess 4y agoYour 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...
- badsectoracula 4y agoFWIW 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).