Re: [go-nuts] tuples! tuples! tuples!

2024-04-30 Thread Andrew Harris
constraint; this matches the formal limit of #66651 4. `func F[In (... any), Out (... any)](f func(In) Out)` multiple variadic tuple constraints On Tuesday, April 30, 2024 at 8:12:09 AM UTC-7 roger peppe wrote: > On Mon, 29 Apr 2024 at 22:06, Andrew Harris wrote: > >> 2. On impl

Re: [go-nuts] tuples! tuples! tuples!

2024-04-29 Thread Andrew Harris
R (Value int, Err error)` and `FSeq[R](strconv.Atoi)`. (I'm losing conviction on that pedantry...) On Monday, April 29, 2024 at 2:24:46 AM UTC-7 roger peppe wrote: > On Sun, 28 Apr 2024 at 12:10, Andrew Harris wrote: > >> Bouncing out from some recent discussions on the github issue

Re: [go-nuts] tuples! tuples! tuples!

2024-04-29 Thread Andrew Harris
wo > iterators together into pairs of values would be no clearer if the > members of the pair were named or not. > > I think this kind of situation occurs most often in generic code, > which is why perhaps this might be an OK time to add tuples > to Go. > > cheers, >

[go-nuts] tuples! tuples! tuples!

2024-04-28 Thread Andrew Harris
Bouncing out from some recent discussions on the github issue tracker, it seems like there's some interest in tuples in Go. I thought the discussion in #66651 led to some interesting ideas, but it's also beginning to drift. Maybe this is a better place to brain-dump some ideas. (This could be a

[go-nuts] Re: Go 1.22 Release Candidate 1 is released

2023-12-24 Thread Andrew Harris
There was some discussion on the GitHub issue(s) that the trailing outer bool is perhaps not adding much in actual usage, shortly after the experiment document. Signatures changed to drop the outer bool, and appearances in docs are vestigial. Of the trailing inner, outer booleans: The inner boo

Re: [go-nuts] Re: [slog] customize defaultHandler

2023-08-29 Thread Andrew Harris
Piping JSON output through jq is worth exploring. This much is enough to be nicer to human eyes: cat log.json | jq -c 'del(.time)' There's a nice Go implementation at https://github.com/itchyny/gojq. On Tuesday, August 29, 2023 at 12:59:55 AM UTC-7 Marcello H wrote: > After playing with it some

[go-nuts] Re: From which programming language did the idea for Golang's interface mechanism design originate?

2023-08-24 Thread Andrew Harris
The comments on Go Data Structures: Interfaces mention Emerald , maybe this is what you were thinking of? On Thursday, August 24, 2023 at 8:42:43 PM UTC-7 xie cui wrote: > I remembe someone in a video in youtube

Re: [go-nuts] How to be a good slog module?

2023-08-23 Thread Andrew Harris
I've found implementing LogValuer can be a useful approach as well. Depending on the package, it can be enough to suggest a package doesn't need to be doing any logging, and if refactoring code from unstructured to structured logging it's useful in any case. On Wednesday, August 23, 2023 at 12:2

Re: [go-nuts] Best IDE for GO ?

2023-08-19 Thread Andrew Harris
The kinds of skills and knowledge covered by https://missing.csail.mit.edu are important and hard to gain from an IDE. I think that's the badge of competence earned here. On Saturday, August 19, 2023 at 11:21:44 AM UTC-7 Robert Engels wrote: The power of IDEs is the ease of refactoring and inte

Re: [go-nuts] call for data on HTTP routing

2023-06-04 Thread Andrew Harris
I wanted to make a quick observation w/r/t Ian's suggestion of not registering ambiguous patterns. The tradeoff isn't ultimately about what behaviors can be associated with what routes, but around what is required to register routes. To intentionally use the kinds of routes we'd interpret as am

Re: [go-nuts] Idiomatic distribute-process-collect pattern

2023-05-21 Thread Andrew Harris
The recipe on 10:26 should work but it's definitely contrived - using Fetch looks strange to me, and the cancellation behavior of errgroup is another moving part that adds some overhead. If it's sufficient, Ian's solution groks better :) On Sunday, May 21, 2023 at 7:38:31 AM UTC-7 Tobias Klaus

Re: [go-nuts] Idiomatic distribute-process-collect pattern

2023-05-20 Thread Andrew Harris
For aggregating results, an alternative to blocking on outstanding payloads is blocking on outstanding workers. You might find this talk interesting, and it has a pretty clever solution for "outstanding workers": https://about.sourcegraph.com/blog/go/gophercon-2018-rethinking-classical-concurren

Re: [go-nuts] Interesting "select" examples

2023-04-07 Thread Andrew Harris
I was surprised looking through old code that I didn't have much in the way of "interesting, non-trivial" selects - in every case where I remember doing something interesting through a select statement, later versions had moved to less interesting selects, more interesting messages from channels

Re: [go-nuts] "go test": common prefix for errors

2023-03-13 Thread Andrew Harris
I'm not sure I completely grasp the use case here in detail, but FWIW, I explored collation of log lines per-test with https://pkg.go.dev/golang.org/x/exp/slog a while ago and ended up with a struct that implements both testing.TB and slog.Handler. The idea was: (1) testing.TB methods that log,

[go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread Andrew Harris
or probably there are other variations that don't require reimplementing sorting. On Tuesday, December 6, 2022 at 7:47:04 PM UTC-8 Andrew Harris wrote: > Just as an intuitive argument, we could do: > sort.Slice(s, func(i, j int) bool { log.Println(i, j); return i > j }) > > The

[go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread Andrew Harris
Just as an intuitive argument, we could do: sort.Slice(s, func(i, j int) bool { log.Println(i, j); return i > j }) The appearances of i and j per step recapitulate the logic of the sorting algo in some weak sense; not slice order On Tuesday, December 6, 2022 at 7:28:39 PM UTC-8 hey...@gmail.com w

[go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread Andrew Harris
Oh, to reverse by index ... I think this doesn't quite fit in the idea of sorts defined by an ordering function purely dependent on the value of the element. I think there may have been a feature request for a `slices.Reverse` function in golang.org/

[go-nuts] Re: Why this simple sorting code doesn't work?

2022-12-06 Thread Andrew Harris
Subtly: return s[i] > s[j] Is the right sort func I think it'd be recommended to look at the generics slices package, which also has a sort On Tuesday, December 6, 2022 at 6:39:29 PM UTC-8 hey...@gmail.com wrote: > Hi, > > I have this very simple sorting code: > > s := make([]int, 0, 10

Re: [go-nuts] Performance for concurrent requests

2022-12-02 Thread Andrew Harris
I wonder a bit about io.ReadAll versus constructing a JSON Decoder. In general, though, using pprof is the best way to start to break down a question like this. Would the actual workload involve more structured JSON, or more computation with decoded values? On Friday, December 2, 2022 at 7:31:5

Re: [go-nuts] Re: is this a bug in "go fmt"?

2022-11-11 Thread Andrew Harris
I think the result of the proposal explains some rewriting in .go files, at least. I believe the conventional wisdom/best practices here are: - Use separate, parallel files to hold platform- (or tag-) specific code, e.g: init_darwin.go, init_linux.go, init_windows.go - Prefer setting envir

Re: [go-nuts] Re: is this a bug in "go fmt"?

2022-11-11 Thread Andrew Harris
Is this relevant? https://github.com/golang/go/issues/41184 On Friday, November 11, 2022 at 1:16:02 PM UTC-8 se...@liao.dev wrote: > You'll need to provide more info if you want to report a bug: > > ``` > main » cat main.go > // +build production > // +build linux > > package main > > 21

Re: [go-nuts] Re: Error Handling Question

2022-10-24 Thread Andrew Harris
> In many cases, including in the standard libraries, there are functions that return errors and then accompanying functions with names like MustFoo() that just call Foo() and panic if there's an error. At least inside the standard lib, the uses of MustXxx document why they behave the way they

Re: [go-nuts] Error Handling Question

2022-10-21 Thread Andrew Harris
Comparing 'panic' and 't.Fatal', they are similar in that there's no notion of recovering and making further progress, they abruptly terminate the process. Still, a wonky thing to say is that a 't.Fatal' call is completely legitimate as a form of "checked"-style error handling. It will log what

Re: [go-nuts] Struggling w/ use of a waitgroup

2022-10-02 Thread Andrew Harris
I think Matthew is correct about the immediate source of the deadlock - because the defer is placed too late in the body of grepFile(), the deferred decrement of the waitGroup isn't run on an os.Open() error. I had the same impression as Jan, I think there is a concern here: the condition for c

Re: [go-nuts] Invalid memory address of string object

2022-09-26 Thread Andrew Harris
could p.Data could be nil here? On Monday, September 26, 2022 at 12:03:20 AM UTC-7 Bernd Fix wrote: > On 9/25/22 19:05, Kurtis Rader wrote: > > Insufficient information. Show us the panic > panic: runtime error: invalid memory address or nil pointer dereference > [signal SIGSEGV: segmentation vio

Re: [go-nuts] Go generics and bloating

2022-08-17 Thread Andrew Harris
This particular example might be hiding some benefits of having the type parameter in the method signature. The type parameter can be useful in something like: func (lhs BinaryPlusOp[T]) Eval( rhs T) T Or, for being explicit about why func (t Number[T]) Sum( []T ) T can't accept a slice of v

Re: [go-nuts] About Go 1.19 memory model clarificaitons on atomic operations.

2022-08-16 Thread Andrew Harris
On Monday, August 15, 2022 at 9:50:17 AM UTC-7 jake...@gmail.com wrote: > On Monday, August 15, 2022 at 5:20:58 AM UTC-4 ma...@changkun.de wrote: > >> Atomic operations on a and b are two different statements. It remains >> unclear where exactly is the sentence that tries to say this: atomic >>

[go-nuts] Re: Go generics and bloating

2022-08-16 Thread Andrew Harris
https://planetscale.com/blog/generics-can-make-your-go-code-slower is the best breakdown I've seen of current implementation details as they hit assembly. There is a little bit of oil/water thing with interfaces and generics - they don't exactly mix, but you can cook however you like ... On Tues

[go-nuts] Re: Using generics to solve Optional argument problem for multiple methods

2022-07-28 Thread Andrew Harris
There's a trivial conversion from any shared option to a flavored optionFunc[T]: type optionFunc[T any] func(*client) func reflavor[T any]( shared func(*client)) optionFunc[T] { return optionFunc[T](shared) } I'm not sure exactly where reflavoring shared -> optionFunc[T] would fit in best,

[go-nuts] lift - a package for generics and type lifting

2022-07-28 Thread Andrew Harris
Hi! Experimenting with Go generics since the 1.18 release, my best trick has been: type enum[T any] struct{} This resulting parametric type has lifted a type flavor, but can be boxed non-parametrically and still match any similarly flavored enum. Recently I tried pulling this idea into a `lift