[go-nuts] Re: [Proposal] Error slot

2023-01-09 Thread Oliver Smith
"or main could be lazy and let `error<-` panic when err != nil:" * would require that `action`'s signature be `func action() (string, error<-)` On Monday, January 9, 2023 at 12:10:25 PM UTC-8 Oliver Smith wrote: > A complete example (followed by the code it replaced)

[go-nuts] Re: [Proposal] Error slot

2023-01-09 Thread Oliver Smith
if err != nil { return err } fmt.Println(motd, pwd) return nil } func main() { if err := action(); err != nil { fmt.Printf("ERROR: %s\n", err) } } ``` https://play.golang.com/p/2_pk-FNv-dk On Tuesday, December 27, 2022 at 3:52:41 PM UTC-8 Oliver Smith wrot

[go-nuts] [Proposal] Error slot

2022-12-27 Thread Oliver Smith
Discussing implementations of the (returns..., error) idiom from golang in other languages, I noted a common thing: non-go developers often conceptualized this as a back channel and didn't intuit that it's just a return-value convention. This lead me to a new idea for addressing the excess verb

[go-nuts] Re: Generics - please provide real life problems

2020-12-27 Thread Oliver Smith
What's the Big-O on determining whether N functions are a/ identical, b/ similar but expressing potentially unique behavior, c/ subtly varied. identical, assuming x and y have the same type: func (t *T) fX() bool { return t.x == t.z } func (t *T) fY() bool { return t.y ==

[go-nuts] on 'while'

2020-12-07 Thread Oliver Smith
Recognizing this is likely to be a dead horse already flogged to infinity, I've been unsuccessful trying to find discussions on the topic of why while was nixed in-favor of the more verbose and error-prone for-based implementations, hoped someone could furnish links? c.f // concise, non-repeti

[go-nuts] [error handling] RFC 'else'

2020-12-02 Thread Oliver Smith
Do I understand correctly that "last return value is error" is purely convention and there is no formal error handling in current go? My instinct is to leverage the 'else' keyword along with the notion of a "stock error whose return list's last element is type error with value != nil. func n

[go-nuts] Conditional move & hoist optimizations

2020-11-10 Thread Oliver Smith
Looking at how go compiles/optimizes a couple of common constructs, which I boiled down to a simple '\t' replacement loop. godbolt of sources: https://go.godbolt.org/z/Pnf3vh ``` func v1(s []byte, detab bool) (d []byte) { d = make([]byte, len(s)) for i := 0; i < len(s); i++ { char := s[i

Re: [go-nuts] Better generator support

2020-10-26 Thread Oliver Smith
n indicator the caller retains responsibility for closing the channel. On Sunday, October 25, 2020 at 5:18:27 PM UTC-7 axel.wa...@googlemail.com wrote: > On Mon, Oct 26, 2020 at 12:29 AM Oliver Smith < > oliver...@superevilmegacorp.com> wrote: > >> This pattern/idiom is ve

[go-nuts] Better generator support

2020-10-25 Thread Oliver Smith
Looking at how C++ has chosen to provide it's users with generators served as a bit of a wake-up call for me on how we implement them in Go. We write them backwards: ```go func getPositiveOdds(numbers []int) <-chan int { channel := make(chan int) go func () { defer close(channel)

[go-nuts] Re: Efficient bitmask twiddling

2020-09-01 Thread Oliver Smith
Do godbolt links get eaten? https://godbolt.org/z/vbeobs On Tuesday, September 1, 2020 at 12:53:57 PM UTC-7 Oliver Smith wrote: > In the process of developing a piece of middleware, I need to translate > from a bit-array into a bitmask. I am struggling to find a way to express > t

[go-nuts] Efficient bitmask twiddling

2020-09-01 Thread Oliver Smith
In the process of developing a piece of middleware, I need to translate from a bit-array into a bitmask. I am struggling to find a way to express this in go that doesn't result in terrible performance. The approaches I would try in most other languages were along the lines of: ``` mask = (bool1

[go-nuts] [generics] Violates beauty ethos

2020-08-11 Thread Oliver Smith
I recognize the hefty constraints in introducing generics, but for me the most egregious part is the cognitive and visual overhead it introduces by pushing more and more stuff off-screen-right and the processing overhead of so many sequences of parens on the same line. My key thought is "the sa