Re: [go-nuts] Auto Make a named return map

2021-03-11 Thread 'Axel Wagner' via golang-nuts
On Fri, Mar 12, 2021 at 1:24 AM Kevin Chadwick wrote: > I find named returns produce more readable code but I avoid them when > returning a map. > Personally, I would recommend avoiding naked returns in all cases. In the best case, a naked return is less explicit and requires readers to think ab

Re: [go-nuts] Why this global variable assignment is deleted in the infinite loop?

2021-03-11 Thread 'Axel Wagner' via golang-nuts
Hi, I'm sorry. I don't know why the compiler decides to delete the assignment in one case but not the other. I doubt there is a better answer than "it decides to drop it, because it's faster that way" and "it doesn't drop it, because it doesn't realize that it can, for some reason". However, I al

Re: [go-nuts] Re: Go compiler - where and how the implicit interface "comparable" used?

2021-03-11 Thread 'Axel Wagner' via golang-nuts
On Fri, Mar 12, 2021 at 4:55 AM messi...@gmail.com wrote: > Does it use for generics constraints only? That is my understanding. > As described at > https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#comparable-types-in-constraints > . If so the type c

Re: [go-nuts] struct conversion, new fields, and incompatibility

2021-03-11 Thread 'Axel Wagner' via golang-nuts
On Fri, Mar 12, 2021 at 3:26 AM Robert Engels wrote: > I must be dense on this. I have no idea why there is any use of struct > tags or JSON marshaling in the sample code. > To demonstrate why converting between different struct types is useful. If you want take an struct existing type (defined

Re: [go-nuts] Why this global variable assignment is deleted in the infinite loop?

2021-03-11 Thread WX Lai
Thank you. Yes, the article introducing the go memory model gave precise conditions. However, if fg1 comes like: func fg1() { for x := uint64(0); x < math.MaxUint64; x++ { isRunning-- } } or func fg1() { if isRunning > 0 { isRunning = 0 } } Then the fg2() will ret

[go-nuts] Re: Go compiler - where and how the implicit interface "comparable" used?

2021-03-11 Thread messi...@gmail.com
Does it use for generics constraints only? As described at https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#comparable-types-in-constraints . If so the type comparison and this interface is two unrelated things? On Friday, March 12, 2021 at 11:42:07 AM

[go-nuts] Go compiler - where and how the implicit interface "comparable" used?

2021-03-11 Thread messi...@gmail.com
Hi, I'm reading the new typechecker source code of go compiler(under directory cmd/compile/internal/types2), during the initialization process, universe.go registers an implicit interface "comparable" inside function defPredeclaredComparable

Re: [go-nuts] struct conversion, new fields, and incompatibility

2021-03-11 Thread Robert Engels
I must be dense on this. I have no idea why there is any use of struct tags or JSON marshaling in the sample code. It will fail without any of that. > On Mar 11, 2021, at 5:28 PM, Axel Wagner > wrote: > >  > That seems unrelated to this thread. If you add a field to a proto-message > and tr

[go-nuts] Re: Unexpected error from os.DirEntry on Win10

2021-03-11 Thread peterGo
rob. Function filepath.Glob returns the names of all files matching the pattern. The files may be directories, regular files, links, and so forth. Function os.ReadDir expects the name of a directory. If the name is not a directory, it returns an error. Your Glob pattern is "*.txt". It probably

[go-nuts] Auto Make a named return map

2021-03-11 Thread Kevin Chadwick
I find named returns produce more readable code but I avoid them when returning a map. Why doesn't go auto init or make an empty map for a named return to avoid the potential chance of a panic due to operating on a nil return? -- You received this message because you are subscribed to the Google

Re: [go-nuts] struct conversion, new fields, and incompatibility

2021-03-11 Thread 'Axel Wagner' via golang-nuts
That seems unrelated to this thread. If you add a field to a proto-message and try to do the same struct-conversion Colin mentions, you will run into exactly the same problem. We are talking about language facilities here, not third party code generators. On Thu, Mar 11, 2021 at 11:48 PM Robert En

Re: [go-nuts] struct conversion, new fields, and incompatibility

2021-03-11 Thread Robert Engels
If you use protobufs and the current guidelines you can always add new fields. > On Mar 11, 2021, at 12:43 PM, 'Axel Wagner' via golang-nuts > wrote: > >  > Hi, > > in some sense, every change to an exported symbol is a breaking change. So a > straight-forward "does this change have the pot

Re: [go-nuts] Unexpected error from os.DirEntry on Win10

2021-03-11 Thread 'Axel Wagner' via golang-nuts
I don't understand why you opened a new thread. But FWIW, it would still be useful to know a) what the actual contents of the directory are you are globbing b) which of those file names is then giving you an error c) and which specific call is returning that error. Your message "Unexpected error f

[go-nuts] Unexpected error from os.DirEntry on Win10

2021-03-11 Thread rob
As the subject line says, this is on windows. I'm getting the file not found error for every file returned by the glob function. I guess I misunderstood the purpose of ReadDir, and I really need to call os.Lstat to retrieve the directory information for each individual file that matches the

[go-nuts] Go 1.16.2 and Go 1.15.10 are released

2021-03-11 Thread Carlos Amedee
Hello gophers, We have just released Go versions 1.16.2 and 1.15.10, minor point releases. View the release notes for more information: https://golang.org/doc/devel/release.html#go1.16.minor You can download binary and source distributions from the Go web site: https://golang.org/dl/ To

[go-nuts] Re: [ANN] New german translations

2021-03-11 Thread HaWe
Thanks for your comments. It's nice when one's work is appreciated. About choice of words, have a look at the "Wörterliste". The link is in the box at the top. About Spelling: that seems to be a question of age. I learnt the word "Kode" long before I came across computers (but I do use "Computer"

[go-nuts] Re: [security] Go 1.16.1 and Go 1.15.9 are released

2021-03-11 Thread Anthony Martin
Katie Hockman once said: > The Reader.Open API, new in Go 1.16, will panic when used on a ZIP archive > containing files that start with “../”. > > This issue is CVE-2021-27919 and Go issue golang.org/issue/44916. Should I submit a CVE request for the power switch on my server? Prodding it with i

Re: [go-nuts] struct conversion, new fields, and incompatibility

2021-03-11 Thread 'Axel Wagner' via golang-nuts
Hi, in some sense, every change to an exported symbol is a breaking change . So a straight-forward "does this change have the potential to break a reverse dependency" is simply not the best way to look at compatibility. We nee

Re: [go-nuts] Why this global variable assignment is deleted in the infinite loop?

2021-03-11 Thread 'Axel Wagner' via golang-nuts
You need to either use a mutex (or some other synchronization primitive) or atomic accesses . On Thu, Mar 11, 2021 at 6:12 PM WX Lai <0xbill...@gmail.com> wrote: > Hi, > > The code: https://repl.it/talk/share/The-assignment-disappeared/127774 > > The assignmen

Re: [go-nuts] Why this global variable assignment is deleted in the infinite loop?

2021-03-11 Thread Jan Mercl
On Thu, Mar 11, 2021 at 6:12 PM WX Lai <0xbill...@gmail.com> wrote: > The code: https://repl.it/talk/share/The-assignment-disappeared/127774 > > The assignment of the global variable `isRunning` in function `fg1` does not > work at all. > In fact, the assignment is deleted in the assembly (see th

[go-nuts] struct conversion, new fields, and incompatibility

2021-03-11 Thread 'Colin Arnott' via golang-nuts
When working with wire formats, serialisation, and external types, it is useful to change the struct tags: https://play.golang.org/p/h6b6FmeDuaR. But when the original struct has a field added, this breaks: https://play.golang.org/p/VHmV9r2MxNt. It seems like a foregone conclusion that we sug

[go-nuts] Why this global variable assignment is deleted in the infinite loop?

2021-03-11 Thread WX Lai
Hi, The code: https://repl.it/talk/share/The-assignment-disappeared/127774 The assignment of the global variable `isRunning` in function `fg1` does not work at all. In fact, the assignment is deleted in the assembly (see the comment of the link above). Why the compiler works like this? It dis

[go-nuts] Need help for writing UNIT TEST (Cassandra database)

2021-03-11 Thread Sachin Raut
Hello Team, I have been using the *"Cassandra database" & wrote CRUD functions.* I want to write unit tests for all the CRUD functions, but don't know how to do it. I googled, but found very little information on it. Can anyone who has written Unit Tests (for Cassandra) help me or share the link

[go-nuts] Re: How to install protoc-gen-go (Go protocol buffer compiler plugin) in windows ?

2021-03-11 Thread Joseph Hoeller
whats the path spec for --proto_path for windows, ive been trying to target the go file with its path and im just not getting it in win10 with wsl2 enabled. On Thursday, June 25, 2015 at 6:59:56 AM UTC-4 Joshua wrote: > go get -u github.com/golang/protobuf/protoc-gen-go > > > On Thursday, June

Re: [go-nuts] Re: finalizers questions again

2021-03-11 Thread 'Axel Wagner' via golang-nuts
ISTM that the docs imply this: When the garbage collector finds an unreachable block with an associated > finalizer, it clears the association and runs finalizer(obj) in a separate > goroutine. This makes obj reachable again, but now without an associated > finalizer. Assuming that SetFinalizer is

[go-nuts] Re: finalizers questions again

2021-03-11 Thread tapi...@gmail.com
(sorry, missed a "if") So if the tailscale trick is valid, could I think that an object is not collected for sure if it has a finalizer and the finalizer has not run yet? On Thursday, March 11, 2021 at 9:42:49 AM UTC-5 tapi...@gmail.com wrote: > > The tailscale article > https://tailscale

[go-nuts] finalizers questions again

2021-03-11 Thread tapi...@gmail.com
The tailscale article https://tailscale.com/blog/netaddr-new-ip-type-for-go/ mentions a finalizer trick. The SetFinalizer docs says the finalizer of an object is not guaranteed to be run. So the tailscale trick is valid, could I think that an object is not collected for sure if it has a fina

Re: [go-nuts] Unexpected error from os.DirEntry on Win10

2021-03-11 Thread 'Axel Wagner' via golang-nuts
Hi, I'm not entirely sure what is happening (it's hard to see without getting more information about the actual file tree and what files you get errors for) and what OS you are running on. But one observation is that you glob for *.txt and then call `ReadDir` on the result - that doesn't make much

[go-nuts] Unexpected error from os.DirEntry on Win10

2021-03-11 Thread rob
I've been writing some code to learn about the library changes in Go 1.16. The following code uses filepath.Glob to get a slice of matching filenames, then uses os.ReadDir to get more information about these files.  I found that os.ReadDir reports a file not found error for the filenames retur