Re: [go-nuts] Check for minimum Go version

2017-08-09 Thread 'Chris Manghane' via golang-nuts
You might want to follow the discussion in golang.org/issue/21207 which might be related to this, depending on the reason you need to know the minimum Go version. `go version` doesn't return the version number on non-tagged releases so if you're building off of tip, for example, the output is a bit

Re: [go-nuts] runtime.GOOS case

2017-08-07 Thread Chris Manghane
You can see how the different runtime.GOOS values are defined in the OS-specific runtime files like https://github.com/golang/go/blob/master/src/runtime/internal/sys/zgoos_windows.go. They happen to be lowercase, but I don't know anything that guarantees that in any future. Curious though, why doe

Re: [go-nuts] Reasoning behind behavior of range, when index is maintained

2017-07-25 Thread 'Chris Manghane' via golang-nuts
at after iteration. I'm not sure if that's official reasoning, but the semantics of range statements are different in many other situations as well so it seems consistent to me. On Tue, Jul 25, 2017 at 4:11 PM, Axel Wagner wrote: > On Wed, Jul 26, 2017 at 12:52 AM, Chris Manghane wrot

Re: [go-nuts] Reasoning behind behavior of range, when index is maintained

2017-07-25 Thread 'Chris Manghane' via golang-nuts
This is mentioned directly in the language specification under For statements with range clause : For each entry it assigns iteration values to corresponding iteration > variables if present and then executes the block. and > For an array, pointer to arra

Re: [go-nuts] Naming projects with multiple words

2017-04-19 Thread 'Chris Manghane' via golang-nuts
There's definitely no idiom here. Do what the octokittens do and probably use the first or second option, in that order. The third seems awkward, unless the underscore has some specific meaning (like how _unix is used to compile architecture-specific code). And I'm not really sure if the capitaliza

Re: [go-nuts] Returning an interface using a concrete type?

2017-02-14 Thread 'Chris Manghane' via golang-nuts
Seems to work fine to me: https://play.golang.org/p/6DmDKQLrzd. In your snippet, the concrete type doesn't implement the interface, however. What was the error you got when trying to do apply this to more complicated code. Chris On Tue, Feb 14, 2017 at 12:01 PM, Aaron Wood wrote: > I'm wonderi

Re: [go-nuts] Documenting Interfaces

2017-01-09 Thread 'Chris Manghane' via golang-nuts
It seems like you would need to do both, at least eventually. I'm not sure why you're saying that you will end up copy-pasting the comments; it seems like each implementation would have something particular about it that would change the documentation. For example, io.Reader must be documented at t

Re: [go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread 'Chris Manghane' via golang-nuts
ruct { > auth string > } > > func doIt(p Params) string { > return p.auth > } > > doIt(Params{auth: }) > > res, _ := http.DefaultClient.Do(req) > > defer res.Body.Close() > body, _ := ioutil.ReadAll(res.

Re: [go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread 'Chris Manghane' via golang-nuts
That error seems to be from writing that expression outside of a function. There's no problem with structs supporting string fields: https://play.golang.org/p/YeP2qhRdxp. On Tue, Dec 13, 2016 at 10:45 AM, Betsy Lichtenberg wrote: > Do structs support strings? I tried this: > > type Params st

Re: [go-nuts] Should go vet catch people attempting to identify errors by inspecting err.Error()?

2016-10-20 Thread 'Chris Manghane' via golang-nuts
+joetsai, who has been thinking about this a lot recently On Thu, Oct 20, 2016 at 11:10 AM, Pietro Gagliardi wrote: > It seems that something about the way the error interface is designed is > not intuitive enough for some, because a number of people on the IRC > channel keep coming up asking wh

Re: [go-nuts] Wrong order for float64 conversion

2016-10-13 Thread 'Chris Manghane' via golang-nuts
In the Go Language specification under operators ( https://golang.org/ref/spec#Operators), there are a couple examples that demonstrate this exact situation: var u2 = 1< wrote: > https://play.golang.org/p/iZTogUaWWl > > In the program above, foo and bar compile but baz does not. It fails with >

Re: [go-nuts] don't understand the comment in spec Type assertions section

2016-10-13 Thread &#x27;Chris Manghane' via golang-nuts
In that example y is a nil interface value of type l. The last line implies that for a type assertion to another interface type, the operation will only be possible if the underlying value implements both interfaces. That is, the value must have an m() method as well as all of io.reader methods or

Re: [go-nuts] go closure escape analysis

2016-10-05 Thread &#x27;Chris Manghane' via golang-nuts
2_modified.go (y=x line should be *y=x ?) and that is the > same as example1.go ??? >but in example1.go y is escapted and example2.go is not. > 2:how do I see the compile handle closure call results ? compile para ? > > 在 2016年10月5日星期三 UTC+8下午11:38:42,Chris Manghane写道: >>

Re: [go-nuts] go closure escape analysis

2016-10-05 Thread &#x27;Chris Manghane' via golang-nuts
t; closure func so I doubt in example2.go y is passed &y to closure > > I don't know the compile how to analysis this and decide that can be > allocated in stack correctly ? > > 在 2016年10月4日星期二 UTC+8下午11:54:02,Chris Manghane写道: >> >> In example1, the // BAD: y e

Re: [go-nuts] go closure escape analysis

2016-10-04 Thread &#x27;Chris Manghane' via golang-nuts
In example1, the // BAD: y escapes is there because y should not escape from that function, but the current algorithm needs to be improved for this case. In that closure, the address of y is captured as the closure argument p and since p is only dereferenced, the analysis should not consider it to

Re: [go-nuts] Re: go escape analysis

2016-09-30 Thread &#x27;Chris Manghane' via golang-nuts
scape just want to know what's the scope rule >> for escape ? puzzled >> <http://www.baidu.com/link?url=ApC817U9uUoCFHhS_dqb5JzUWJQsslUUA6_TDv3LDZBJgaA-G2ZbRfWA-2cGajgU_MHmTiXVEouMmdPN53mMMXxYd1nvCWWJJvfu5Mmg4Ca> >> >> >> 在 2016年9月29日星期四 UTC+8上午1:39:09,Chris Manghane写道: >>> >

Re: [go-nuts] Re: go escape analysis

2016-09-30 Thread &#x27;Chris Manghane' via golang-nuts
{ > m = make(map[int]int) > } > > _ = m > } > > if I do this m will not escape just want to know what's the scope rule for > escape ? puzzled > <http://www.baidu.com/link?url=ApC817U9uUoCFHhS_dqb5JzUWJQsslUUA6_TDv3LDZBJgaA-G2ZbRfWA-2cGajgU_MHmTiXVE

Re: [go-nuts] Re: go escape analysis

2016-09-28 Thread &#x27;Chris Manghane' via golang-nuts
In the first example, make does not escape the scope of the for statement. In the second example, make is assigned to m, which is outside of the scope of the for statement, which means the make operation escapes its scope and subsequently, is heap allocated. If you want more information about why s

Re: [go-nuts] Go beginner asks for code review

2016-09-22 Thread &#x27;Chris Manghane' via golang-nuts
On Thu, Sep 22, 2016 at 3:31 PM, Leandro Motta Barros wrote: > Hi Sam, > > Looks like your response got truncated. :-/ > > Anyway, there is a good deal of nice tips, there. I am updating my code to > take your feedback into account. Thanks a lot! > > There is one point I still wondering about, ho

Re: [go-nuts] What is the difference between fmt.Print and rand.Intn functions here?

2016-08-31 Thread &#x27;Chris Manghane' via golang-nuts
You can use something like `go build -gcflags="-m -m" ...` to get more information about why something escape. David Chase has added excellent descriptions of why something escapes. There's a lot of detail about fmt.Print functions escape, in general, but without going into detail, we can look at

Re: [go-nuts] labeled loop vs for statement inlining

2016-08-29 Thread &#x27;Chris Manghane' via golang-nuts
I can't explain exactly because my explanation is likely very flawed, but the logic you are looking for is in https://github.com/golang/go/blob/320ddcf8344beb1c322f3a7f0a251eea5e442a10/src/cmd/compile/internal/gc/inl.go#L186. Basically, labeled loops are not considered "hairy" by the compiler and c

Re: [go-nuts] wired value

2016-07-28 Thread Chris Manghane
A simple example: https://play.golang.org/p/RNgW-Ya5BS Conversions between numeric types : "For the conversion of non-constant numeric values, the following rules apply: 1. When converting between integer types, if the value is a signed integer, it i

Re: [go-nuts] fmt.Printf("%v") panics where %#v doesn't

2016-07-15 Thread &#x27;Chris Manghane' via golang-nuts
In your example, MyError2 does not have an Error() method so it is not called. From the fmt package docs (golang.org/pkg/fmt): - 3. If the %v verb is used with the # flag (%#v) and the operand implements the GoStringer interface, that will be invoked. - If the format (which is implicitly