5 ms·
Gopher Tricks
- pluma 11y agoI swear, one of these days I'll implement a gopher server and client in go just out of spite. Every time I read a link mentioning "gopher" I expect it to be a neat hack based on the obsoleted protocol.
- deleted 11y ago[deleted]
- ruok0101 11y agoYes! Bring back gopher!
- mindcrime 11y ago1a. Install Overbite (http://gopher.floodgap.com/overbite/ http://gopher.floodgap.com/overbite/) OR 1b. Install Lynx or eLinks 2. goto gopher://gopher.floodgap.com
- mindcrime 11y agoI swear, one of these days I'll implement a gopher server and client in go just out of spite. I've been playing around with Gopher a bit lately. I installed eLinks just to have a Gopher client. I've even been thinking about setting up gopher://gopher.fogbeam.com to serve content over Gopher protocol. :-) Every time I read a link mentioning "gopher" I expect it to be a neat hack based on the obsoleted protocol. Came here to say the same thing. Every time I see one of these headlines, I expect something about Gopher[1], not Golang. [1]: https://en.wikipedia.org/wiki/Gopher_(protocol) https://en.wikipedia.org/wiki/Gopher_(protocol)
- digi_owl 11y agoReading over that article i find myself wondering if Gopher would be a good fit for a Freenet like system.
- mseepgood 11y agoBy the author of the linked slide deck (Andrew Gerrand): https://github.com/nf/gogopherd/ https://github.com/nf/gogopherd/ By Brad Fitzpatrick (another Go team member): https://code.google.com/p/gogopherd/ https://code.google.com/p/gogopherd/
- 0xdeadbeefbabe 11y agoAlso http://godoc.org/github.com/peterhellberg/gopher http://godoc.org/github.com/peterhellberg/gopher
- fortytw2 11y agoSaw an earlier version of this talk @ the Berlin Go meetup earlier this week - the exploration and explanation of `sync/atomic` by Andrew is really great
- tshannon 11y agoWell shit, how come I've never seen anonymous structs before. That's pretty cool.
- akhilcacharya 11y agoFinding out Go had anonymous structs is what lead me to start learning Go.
- apta 11y agoWhat about finding out it didn't have generics?
- Manishearth 11y agoThis is incredibly trippy :D http://talks.golang.org/2015/tricks.slide#16 http://talks.golang.org/2015/tricks.slide#16
- bsaul 11y agoI thought this kind of magic code was explicitly what go creators didn't want. If i compare to Objective-C "object respondsToSelector:selector()" or "object isKindOfClass" equivalent, this go "casting to an anonymous struct" code seems extremely convoluted. Plus, i may be wrong, but it seems like it's really not robust. You're trying to cast to an anonymous struct declared locally, that isn't linked to any other interface anywhere, and only implements part of the methods defined in the File struct. It's looks to me just as robust as using strings. What you would like to express, is what's in the comment : aka, test against something related to the File struct/interface.
- johansch 11y agoI get the feeling the Go language creators defined the Go language syntax in many cases so that it explicitly looks different than the corresponding C syntax. Why? (Yes, I know Rob's and Ken's history with regards to C.)
- frou_dh 11y agoLucky for you there's an article explaining exactly that: http://blog.golang.org/gos-declaration-syntax http://blog.golang.org/gos-declaration-syntax --- I like the map. Here's the rules for Conway's Game of Life as a nested map: var cgol = map[state]map[int]state{ alive: { 0: dead, 1: dead, 2: alive, 3: alive, 4: dead, 5: dead, 6: dead, 7: dead, 8: dead, }, dead: { 0: dead, 1: dead, 2: dead, 3: alive, 4: dead, 5: dead, 6: dead, 7: dead, 8: dead, }, }
- johansch 11y agoI read that as arrogance. Before C, naturally no-one knew C. Before Go though, tens of millions know C. They are casually throwing away all of that familiarity in the name of elegance. I think this is what might mean that Go doesn't "win".
- frou_dh 11y agoFor someone who can already program, such things are trivial to learn. If you class doing basic design work and taking time to document it as "arrogance" then I'm afraid you may be suffering from negative mindset.
- myg204 11y ago> throwing away all of that familiarity in the name of elegance That looks like a good deal to me! :)
- jesstaa 11y ago
- XorNot 11y agoIn practice I've not found anonymous structs too useful. You end up being very verbose and then discover you'd have been better off with a named type anyway. It'd be nice to have a shorthand which mixed the type definition and assignment into a single line so you could do something like: S := { x int : 1, y int : 2 } Or even S:= { x := 1, y := 2 }
- PuerkitoBio 11y agoI use them extensively for test cases (`cases := []struct{...} { ... }`) as mentioned in the slides. Also sometimes to marshal/unmarshal one-off json or xml payloads.
- ericbb 11y agoThis trick fits more into the "prank" category. package main import "fmt" // <Add one short line of valid Go code here> func main() { var n int = 1 fmt.Println(n) } Compiler: "prog.go:8: cannot use 1 (type int) as type int in assignment" Here's a trick that I expected to work but doesn't. Would be interested to hear the rationale if anyone knows it. m := map[[]int]int{}
- barsonme 11y ago> Here's a trick that I expected to work but doesn't. Would be interested to hear the rationale if anyone knows it. Per the spec[0]: The comparison operators == and != must be fully defined for operands of the key type; thus the key type must not be a function, map, or slice. If the key type is an interface type, these comparison operators must be defined for the dynamic key values; failure will cause a run-time panic. [0] - https://golang.org/ref/spec#Map_types https://golang.org/ref/spec#Map_types
- ericbb 11y agoBy "rationale" I was thinking more along the lines of "here is the reason we chose to do it this way" not just "here is the way we chose to do it".
- kjksf 11y agohttps://golang.org/doc/faq#map_keys https://golang.org/doc/faq#map_keys "Map lookup requires an equality operator, which slices do not implement. They don't implement equality because equality is not well defined on such types; there are multiple considerations involving shallow vs. deep comparison, pointer vs. value comparison, how to deal with recursive types, and so on. We may revisit this issue—and implementing equality for slices will not invalidate any existing programs—but without a clear idea of what equality of slices should mean, it was simpler to leave it out for now. In Go 1, unlike prior releases, equality is defined for structs and arrays, so such types can be used as map keys. Slices still do not have a definition of equality, though."