Re: [go-nuts] Why is it forbidden to add methods to an existing type?

2022-03-17 Thread Henry
My own preference is to have a small number of methods and put the general functionalities into functions. By putting the general functionalities into functions, you allow code reuse. In object-oriented programming, you normally attach as many functionalities as possible to their corresponding

Re: [go-nuts] Why is it forbidden to add methods to an existing type?

2022-03-17 Thread Ian Lance Taylor
On Thu, Mar 17, 2022 at 7:17 PM Zhaoxun Yan wrote: > > I just came across this taboo in golang - new methods cannot be added to an > existing type: Yes. If we didn't have this prohibition, then the set of interfaces satisfied by a type would depend on which package was using the type. See the

[go-nuts] Constrain a type to be either a slice or a map

2022-03-17 Thread RussellLuo
Hi there, Thanks to Go generics in 1.18, I can write a generic function `LenBetween` for a slice: ```go func SliceLenBetween[T ~[]E, E any](s T, min, max int) bool { return len(s) >= min && len(s) <= max } ``` as well as for a map: ```go func MapLenBetween[T map[K]V, K comparable, V an

Re: [go-nuts] how to protect source code

2022-03-17 Thread Zhaoxun Yan
I think it is best to run your code on an encrypted disk. So it cannot be stolen by taking away the hard-drive. Furthermore if the config and log files are in other folders, it is okay to shut down the encrypted drive I guess. In that case even it is running in memory, the hacker cannot get acces

[go-nuts] Why is it forbidden to add methods to an existing type?

2022-03-17 Thread Zhaoxun Yan
Hi everyone! I just came across this taboo in golang - new methods cannot be added to an existing type: package main import "fmt" func (s string) print(){ fmt.Println(s) } func main() { "hello, world\n".print() } --Error ./main.go:5: cannot define new methods on non-local

Re: [go-nuts] Constrain a type parameter to be assignable to another

2022-03-17 Thread Ian Lance Taylor
On Wed, Mar 16, 2022 at 9:44 PM Michael Andersen wrote: > > Is there a way to constrain one parameter to be assignable to another? Currently there is not. We're not sure how to handle that case. See https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#no-way-

Re: [go-nuts] how to protect source code

2022-03-17 Thread Ian Lance Taylor
On Thu, Mar 17, 2022 at 6:46 AM bbb tt wrote: > > I want to encrypt my algorithm library, is there any good way in Go. My > library is used in both Windows and Linux For a security issue like this it's essential to define the attack you want to defend against. The nature of Go is such that aga

[go-nuts] Re: When will the official encoding/json package support parsing json5?

2022-03-17 Thread Rob Muhlestein
It is my sincere hope that Go will never support anything as poorly designed as JSON5, using reflection is already slow enough. Comments were never intended for JSON and never should be added, ever. But since most discerning development shops are moving to Protobuf for everything that matters,

[go-nuts] Re: are Go generics more like C++ or more like Java?

2022-03-17 Thread Glen Newton
>- exotic use-cases are not supported (for example having an integer *constant* as *generic parameter*, such as you see in C++ fixed size matrix templates, is not supported) Does a longer (but not necessarily exhaustive) list of the unsupported exotic use cases exist? This would be useful to un

[go-nuts] Re: are Go generics more like C++ or more like Java?

2022-03-17 Thread Ali Altun
Go - FAQ: How do generics in Go compare to generics in other languages? https://go.dev/doc/faq#generics_comparison On Wednesday, February 23, 2022 at 9:41:14 PM UTC+1 Jason E. Aten wrote: > Back in 2009, Russ wrote a blog on generics, talking about the tradeoffs > in providing generics: > >

Re: [go-nuts] Re: New edition of the Go Programming Language comming soon ?

2022-03-17 Thread Rob Muhlestein
Thank you very much for this reference. This looks exactly like what I was looking for. I'm always a fan of getting behind what is out there instead of making yet another of the thing. I've purchased a copy and so far can clearly get behind so much of the approach, especially not requiring anyt

[go-nuts] Re: A question troubled me for a long time (about slice and map)

2022-03-17 Thread Brian Candler
(Just as an aside: please don't post screenshot images. Plaintext is easier to read and can be copy-pasted. You can also use https://go.dev/play/ to paste code snippets) I think you have understood the issue well. From the source code at https://golang.org/src/runtime/slice.go : type slice s

[go-nuts] how to protect source code

2022-03-17 Thread bbb tt
I want to encrypt my algorithm library, is there any good way in Go. My library is used in both Windows and Linux -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email t

[go-nuts] Re: Goroutines - handles, signals, and signal handlers

2022-03-17 Thread peterGo
Go1.18 has a new Mutex TryLock method. https://pkg.go.dev/sync@go1.18#Mutex.TryLock Petr On Wednesday, March 16, 2022 at 9:36:50 PM UTC-4 mumbling...@gmail.com wrote: > I'm currently working on a project where I emulate a RISC-V processor for > the purpose of using Go when teaching concepts

[go-nuts] Re: Goroutines - handles, signals, and signal handlers

2022-03-17 Thread Mumbling Drunkard
> - is the handler executed in the goroutine of the target? That's the idea yes. > But then how does that interact with the goroutine which is already running? Does it only execute when the goroutine is next blocked in a select { }, for example? In that case, why not just add a new branch to th

Re: [go-nuts] Golang Packages

2022-03-17 Thread Nickolas Daniel Filip
I've tried on a fresh repo without any tags and it worked just fine. Thank you very much! On Wednesday, March 16, 2022 at 11:40:39 PM UTC+2 se...@liao.dev wrote: > It's available if you use the generated pseudoversion as the version in > the pkgsite url . you can get it via a call to go get (wh

[go-nuts] Re: Goroutines - handles, signals, and signal handlers

2022-03-17 Thread Brian Candler
I don't understand the semantics of this. At what point is the handler function executed and in which goroutine? In other words, when you call `s := sig h 1`: - is the handler executed in the goroutine of the caller? Then how is it different from `s := h(1)` ? - is the handler executed in the

Re: [go-nuts] no git tags in go 1.18 new buildinfo

2022-03-17 Thread JeffG
thx for this link. But it implies a specific usage of tags (interpreting them as a "version" / "pseudo version"). I was thinking about a more general approach, just embed tags. I added a comment to the github issue. Then people can check for a tag in buildinfo and eventually use it as Version