Re: [go-nuts] [generics] type constraint for structs

2020-06-24 Thread Pee Jai
Here is my use case: https://godoc.org/github.com/rocketlaunchr/react#UnmarshalState That function has an argument that accepts only a struct. I use the reflect package to iterate over the structs fields (and also to check if it actually is a struct). The function has notapplicability for

Re: [go-nuts] [generics] type constraint for structs

2020-06-24 Thread Robert Engels
Generics will not solve this fully anyway - you’ll still need reflection. Why not just return empty if the user doesn’t pass a struct? > On Jun 24, 2020, at 8:29 AM, Pee Jai wrote: > >  > Here is my use case: > https://godoc.org/github.com/rocketlaunchr/react#UnmarshalState > > That

Re: [go-nuts] [Generics] Concise generics with package level types

2020-06-24 Thread b97tsk
My code shows that returning a generic function might be desirable. The Filter function in my code is as follows: func Filter( type T interface{}, Source Observable(T), )(pred func(T) bool) Operator(T,

[go-nuts] Measuring resource usage of child processes

2020-06-24 Thread Brian Candler
Here's a program with a couple of problems. It runs three concurrent child processes, and measures the resource usage for each of them separately. I'm using a dummy child which is /bin/sh -c "yes >/dev/null", and let it run for a few seconds before forcibly terminating it. package main

[go-nuts] Re: mark pointer methods on interface type definitiion, not function?

2020-06-24 Thread Anderson Queiroz
I see your point, but the interfaces do not deal with the implementation details, they only specify a behaviour. In your proposal the interface definition would constrain how it can be implemented. Whoever is implementing the interface is responsible for the constraints related to the

Re: [go-nuts] How I can translate this shell command to golang code?

2020-06-24 Thread Franco Marchesini
Yes, this is better. Thanks func main() { cmd := exec.Command("dmtxwrite", "-s", "16x48", "-o", "image2.png") cmd.Stdin = strings.NewReader("123456") if err := cmd.Run(); err != nil { panic(err.Error()) } } Il giorno lunedì 22 giugno 2020 18:19:36 UTC+2, Bakul Shah ha scritto: > > You can

[go-nuts] Re: Measuring resource usage of child processes

2020-06-24 Thread Brian Candler
I have a kind-of workaround. Firstly, I see that Go has the ability to start a new session for the child with Setsid called. However on timeout I still need to kill the process group (-pid) instead of the process, which I can do by implementing the context deadline manually: cmd :=

Re: [go-nuts] Is it necessary to start function names within main package with capitalized letter?

2020-06-24 Thread 'Axel Wagner' via golang-nuts
Personally, I tend to do it. Note that it doesn't actually make a difference from a technical perspective - main can't be imported, so it makes no real sense to export any identifiers. As such, the boundaries of what I "export" are somewhat more fluent than usual. But yeah, as you said, for

[go-nuts] Why the user variable isn't getting printed when the query is alright

2020-06-24 Thread davetweetlive
package main import ( "database/sql" "fmt" "log" "time" _ "github.com/go-sql-driver/mysql" ) type Users struct { Id int Username string Password string Email string First_name string Last_name string Created_at time.Time Super_user bool } func main() { db, err := sql.Open("mysql",

[go-nuts] Re: Why the user variable isn't getting printed when the query is alright

2020-06-24 Thread howardcshaw
First, please post plain text. Second, you are not capturing the error from the query; capture and print that error and it will likely inform you what the issue is. (On the row.Scan.) Third, perhaps the issue is your use of $1 instead of ?. This is regarding sqlx, but the issue they describe

Re: [go-nuts] [Generics] Concise generics with package level types

2020-06-24 Thread roger peppe
The draft proposal does not support generic function values. Doing so would make the compiler's code generation job much harder (or maybe not possible) because it would be considerably more difficult to enumerate all the possible instantiation parameters at compile time. On Wed, 24 Jun 2020,

[go-nuts] Re: Why not use F in generic?

2020-06-24 Thread i3dmaster
Actually, this isn't too bad. Given Go already flips types and names in syntax, having the generic specification in front of the entity it decorates doesn't seem too alien looking. The too-mang-() concern has already brought up to the draft, I think it likely require some careful thinking...

Re: [go-nuts] Is it necessary to start function names within main package with capitalized letter?

2020-06-24 Thread 'K Richard Pixley' via golang-nuts
I generally do the reverse. Everything is internal, lower case, until and unless I need it elsewhere.  Then I reevaluate where the boundaries should be at that time. I often find that as an exported API, I need/want different things out of it than I did when it was internal. -- You

[go-nuts] Re: Is it necessary to start function names within main package with capitalized letter?

2020-06-24 Thread Ronny Bangsund
I tend to do it too, because at some point I often find that I might as well create packages (internal or not) from some of the functionality. For example, my latest little tool wraps some AWS functionality with pretty-printing and progress bars, and I suspect I may find use for those in other

Re: [go-nuts] [generics] type constraint for structs

2020-06-24 Thread Ian Lance Taylor
On Wed, Jun 24, 2020 at 12:22 PM David Finkel wrote: > > On Wed, Jun 24, 2020 at 9:34 AM Robert Engels wrote: >> >> Generics will not solve this fully anyway - you’ll still need reflection. >> Why not just return empty if the user doesn’t pass a struct? >> > That sounds like a bug waiting to

Re: [go-nuts] [generics] where to find predefined constraint aggregations?

2020-06-24 Thread i3dmaster
On Wednesday, June 24, 2020 at 3:02:43 PM UTC-7, Ian Lance Taylor wrote: > > On Wed, Jun 24, 2020 at 2:33 PM i3dmaster > > wrote: > > > > example: > > > > type Key interface { > > type comparable, fmt.Stringer > > } > > > > type Value interface { > > type interface{}, copyable

Re: [go-nuts] [generics] type constraint for structs

2020-06-24 Thread Pee Jai
I disagree. A type constraint for a struct would definitely provide compile-time guarantee that only a struct can be used. On Thursday, June 25, 2020 at 8:18:13 AM UTC+10, Ian Lance Taylor wrote: > > On Wed, Jun 24, 2020 at 12:22 PM David Finkel > wrote: > > > > On Wed, Jun 24, 2020 at 9:34

Re: [go-nuts] [runtime] gostring question

2020-06-24 Thread keith . randall
Yes, we can't depend on the data at *p to remain constant. We need to snapshot it at the moment of the gostring call. On Tuesday, June 23, 2020 at 5:52:23 PM UTC-7, Kurtis Rader wrote: > > On Tue, Jun 23, 2020 at 5:32 PM Bill Morgan > wrote: > >> I'm a C programmer so maybe this is a dumb

Re: [go-nuts] Is there +v Stringer interface?

2020-06-24 Thread Miki Tebeka
On Thursday, June 25, 2020 at 2:41:01 AM UTC+3, Ian Davis wrote: > > fmt.Formatter is woefully under documented. > My reference is pkg/errros - https://github.com/pkg/errors/blob/master/errors.go#L127 -- You received this message because you are subscribed to the Google Groups "golang-nuts"

Re: [go-nuts] [generics] type constraint for structs

2020-06-24 Thread Ian Lance Taylor
On Wed, Jun 24, 2020 at 4:57 PM Pee Jai wrote: > > Just to clarify: This is not directly related to generics. It is related to > interfaces (and the type constraints feature) which are incidental to > generics and provides extra power to developers. In this particular use case, > it provides a

Re: [go-nuts] [generics] type constraint for structs

2020-06-24 Thread Robert Engels
But if you interpret the method as ‘format this struct’ a struct has named fields. A primitive has no named fields so the output is empty. It is almost always easier to define the contract if the method in an unbreakable way than rely on the compiler to catch all problems. For example what

[go-nuts] What is the impact of allocation costs on latency?

2020-06-24 Thread doohick
I'm considering Go for a new service application and I'd like to minimize the time between a request being received and the response being sent (i.e., response latency). I like what I've read about all the work that's gone into the golang garbage collector to reduce stop-the-world pause times,

Re: [go-nuts] What is the impact of allocation costs on latency?

2020-06-24 Thread Ian Lance Taylor
On Wed, Jun 24, 2020 at 5:28 PM wrote: > > I'm considering Go for a new service application and I'd like to minimize the > time between a request being received and the response being sent (i.e., > response latency). I like what I've read about all the work that's gone into > the golang

[go-nuts] Graphic Go Algorithms: Graphically learn data structures and algorithms better than before

2020-06-24 Thread huyangtim
free book just 5 day left https://www.amazon.com/gp/product/B08BFXNTFF [image: Graphic Go Algorithms: Graphically learn data structures and algorithms better than before by [yang hu]] Discover how graph algorithms can help you leverage the relationships within your data to develop more

[go-nuts] [generics] Use decorators ($, or @, or #) to specify that the type is a generic type.

2020-06-24 Thread Andrey T.
The idea: Use decorators ($, or @, or #) to specify that the type is a generic type. (Syntax is vaguely follows to * "it is a pointer", so $T becomes a "it is a generic type") 1. Readability - Immediately visible which type is a generic type. 2. Readability - Less braces. Compare func

Re: [go-nuts] Is there +v Stringer interface?

2020-06-24 Thread Ian Davis
fmt.Formatter is woefully under documented. The second argument (called c in the interface definition) is the verb, i.e. 's', 'v', 'd' etc. The first argument provides a state interface with functions to allow you to emit the format of your type. The Flag function on this interface lets you

Re: [go-nuts] [generics] where to find predefined constraint aggregations?

2020-06-24 Thread 'Yongjian (Jim) Xu' via golang-nuts
On Wednesday, June 24, 2020 at 3:55:07 PM UTC-7 Ian Lance Taylor wrote: > On Wed, Jun 24, 2020 at 3:47 PM i3dmaster wrote: > > > > On Wednesday, June 24, 2020 at 3:02:43 PM UTC-7, Ian Lance Taylor wrote: > >> > >> The current generics design draft doesn't support the kind of > >>

Re: [go-nuts] [generics] type constraint for structs

2020-06-24 Thread Pee Jai
Just to clarify: This is not directly related to generics. It is related to interfaces (and the type constraints feature) which are incidental to generics and provides extra power to developers. In this particular use case, it provides a useful compile-time check for an argument that is

Re: [go-nuts] Re: Why not use F in generic?

2020-06-24 Thread Michael Jones
Many (nearly all?) computer languages cater to English readers who have experience with certain noun/verb and noun/modifier ordering. Globally, “bird blue” and “pizza pepperoni” may be more common in other natural languages than blue bird and pepperoni pizza. The proposed order, “the T type

Re: [go-nuts] Re: Measuring resource usage of child processes

2020-06-24 Thread Ian Lance Taylor
On Wed, Jun 24, 2020 at 2:53 AM Brian Candler wrote: > > I have a kind-of workaround. Firstly, I see that Go has the ability to start > a new session for the child with Setsid called. However on timeout I still > need to kill the process group (-pid) instead of the process, which I can do >

Re: [go-nuts] [generics] where to find predefined constraint aggregations?

2020-06-24 Thread Ian Lance Taylor
On Wed, Jun 24, 2020 at 3:47 PM i3dmaster wrote: > > On Wednesday, June 24, 2020 at 3:02:43 PM UTC-7, Ian Lance Taylor wrote: >> >> The current generics design draft doesn't support the kind of >> constraints you are looking for. > > > Is there or will there be a plan? Using generic types with

Re: [go-nuts] Is there +v Stringer interface?

2020-06-24 Thread 'Ian Cottrell' via golang-nuts
You want to implement fmt.Formatter . In general I prefer implementing Formatter to either Stringer or GoStringer if I am only doing it for printing, even for the simple cases, as I feel it better reflects the intent. I reserve implementing the String

[go-nuts] [generics] where to find predefined constraint aggregations?

2020-06-24 Thread i3dmaster
example: type Key interface { type comparable, fmt.Stringer } type Value interface { type interface{}, copyable } type Container(type K Key, V Value) interface { Add(K, V) bool } type HashMap(type K Key, V Value) struct{ m map[K]V } func (h *HashMap(K,V)) Add(k K, v V) bool {

Re: [go-nuts] [generics] where to find predefined constraint aggregations?

2020-06-24 Thread Ian Lance Taylor
On Wed, Jun 24, 2020 at 2:33 PM i3dmaster wrote: > > example: > > type Key interface { > type comparable, fmt.Stringer > } > > type Value interface { > type interface{}, copyable > } > > type Container(type K Key, V Value) interface { >Add(K, V) bool > } > > type HashMap(type K Key, V

Re: [go-nuts] [runtime] Scheduling overhead incurred by the runtime

2020-06-24 Thread Robert Engels
But it is probably easier to set an immediate deadline (0) to effect a poll and I think you’ll get the same behavior. Haven’t tried it. Downside you are going to burn a cpu at 100% per socket but you will go fast. I haven’t looked into the intervals in a while but I think the deadline of 0

Re: [go-nuts] Is there +v Stringer interface?

2020-06-24 Thread andrey mirtchovski
>> fmt.Formatter is woefully under documented. > > My reference is pkg/errros - > https://github.com/pkg/errors/blob/master/errors.go#L127 we have wasted tens of man-hours hunting for a bug that didn't manifest in logs due to that custom formatter. %#v basically went directly to stringer without

Re: [go-nuts] [runtime] Scheduling overhead incurred by the runtime

2020-06-24 Thread Robert Engels
See https://medium.com/@cpuguy83/non-blocking-i-o-in-go-bc4651e3ac8d > On Jun 24, 2020, at 11:34 PM, Deepak Sirone wrote: > >  > Does that mean that I should have the sockets in non-blocking more and set > read deadlines on them? And also use the default case statement in select >

Re: [go-nuts] [runtime] Scheduling overhead incurred by the runtime

2020-06-24 Thread Deepak Sirone
Does that mean that I should have the sockets in non-blocking more and set read deadlines on them? And also use the default case statement in select statements? On Tuesday, June 23, 2020 at 2:20:12 PM UTC-5, Robert Engels wrote: > > You need to keep the routines “hot” - use polling design... >

[go-nuts] Re: [generics] Use decorators ($, or @, or #) to specify that the type is a generic type.

2020-06-24 Thread haskell_mustard via golang-nuts
On Thursday, 25 June 2020 06:17:24 UTC+2, Andrey T. wrote: > 3. Ability to use decorated interface name as spec for type constrains > >func (type T Comparable) Max(a... T) (result T) {...} > >might become > >func Max(a... $Comparable) (result $Comparable) {...} > I don't see how

Re: [go-nuts] Re: Measuring resource usage of child processes

2020-06-24 Thread Brian Candler
My problem is actually around exec.CommandContext. I mentioned os.Process.Kill is because that's the interface that exec.CommandContext uses : > The provided context is used to kill the process (by calling os.Process.Kill) if the context becomes