by psxuaw on 4/25/22, 1:07 AM with 61 comments
by amscanne on 4/25/22, 4:35 AM
fib = func(n int) int {
if cache[n].o.IsSome() {
return *cache[n].o.val
}
return fib(n-1) + fib(n-2)
}
Should be: fib = func(n int) int {
return cache[n-1].Force() + cache[n-2].Force()
}
by CraigJPerry on 4/25/22, 8:21 AM
I chuckled at the juxtaposition of the “expressivity and clarity” comment:
>> you can create composite types (types out of types). This lets you get a lot of expressivity and clarity about how you use Go
Followed by long winded code:
>> However, we can make this a lot more complicated with the power of the Thunk[T] type
And confusion:
>> Why is this so much slower?
This article touches on a lot of the frustration i see with abuse of static typing.
You’re going to write more code and take longer to write it and longer to change it (read: you’re going to cost me more money to build and maintain this code), for the unproven claim that you’ll write less bugs.
The author then goes on to write a logic bug in their memoization code.
But only after they’ve created a generic MPMC queue type by taking an already generic MPMC queue type (a go channel) then writing logic that breaks it (can’t handle an empty queue state) which they code their way out of by throwing more code i have to own.
by reflexe on 4/25/22, 5:21 AM
I also could not find where the author explains their "crimes".
What I am missing here?
by svnpenn on 4/25/22, 4:47 PM
by BreakfastB0b on 4/25/22, 4:20 AM
by nirui on 4/25/22, 9:48 AM
Just a side note: Go test supports benchmarking (https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-i...) which gives you few useful tools such as `b.ReportAllocs()` and `go test -bench . -cpuprofile cpu.out -memprofile men.out`. These tools can give you far better information than just the execution time of a test case.
by nx7487 on 4/25/22, 5:42 AM
Go 1.18 added generics to the language. This allows you to have your types take types as parameters so that you can create composite types (types out of types). This lets you get a lot of expressivity and clarity about how you use Go.
Aren't structs already composite types?by mrlonglong on 4/25/22, 5:21 PM
by Koiwai on 4/25/22, 7:45 AM
by Kostarrr on 4/25/22, 6:44 AM
But you could probably achieve that using go's not-well-known sum types, e.g. like this
https://github.com/FSMaxB/type-safe-builder-experiment/blob/...
by RamblingCTO on 4/25/22, 1:22 PM