Re: [go-nuts] Appreciating Go

2018-02-25 Thread Maxim Ivanov
> That's why I've used *time.Time, not time.Time - if you try to use it when > t.Err is set you'll get panic because of nil value. > > > Runtime checks doesn't count :) Compiler still allowed you to use value, when error was set. -- You received this message because you are subscribed to th

Re: [go-nuts] Appreciating Go

2018-02-25 Thread Alex Efros
Hi! On Sun, Feb 25, 2018 at 01:51:08AM -0800, Maxim Ivanov wrote: > > type Time struct { > > Err error > > *time.Time > > } > Problem is that it continues to be product type, nothing really enforces > that you can't use t as a time.Time when t.E

Re: [go-nuts] Appreciating Go

2018-02-25 Thread roger peppe
On 24 February 2018 at 22:02, Bakul Shah wrote: > r := os.Open(filename) > if isError(r) { return r.(error) } > f := r.(*os.File) // or better: var f *os.File; f = r I don't think the "or better" alternative would be possible. The of r is still `*os.File|error`, not *os.File, and this not assigna

Re: [go-nuts] Appreciating Go

2018-02-25 Thread Maxim Ivanov
> Short version to just get a taste: > > type Time struct { > Err error > *time.Time > } > > func now(pass bool) Time { > if !pass { > return Time{Err: errors.New("not now")} >

Re: [go-nuts] Appreciating Go

2018-02-25 Thread Alex Efros
Hi! On Sat, Feb 24, 2018 at 02:02:37PM -0800, Bakul Shah wrote: > r := os.Open(filename) > if isError(r) { return r.(error) } > f := r.(*os.File) // or better: var f *os.File; f = r > > Error checking being a common pattern, isError() can be added as a builtin > or trivially in errors pkg. Likely

Re: [go-nuts] Appreciating Go

2018-02-25 Thread 'Axel Wagner' via golang-nuts
On Sat, Feb 24, 2018 at 11:04 PM Bakul Shah wrote: > r := os.Open(filename) > if isError(r) { return r.(error) } > f := r.(*os.File) // or better: var f *os.File; f = r > This still does not seem meaningfully different to me, though. * You are writing isError(r), instead of err != nil * You are

Re: [go-nuts] Appreciating Go

2018-02-24 Thread Bakul Shah
r := os.Open(filename) if isError(r) { return r.(error) } f := r.(*os.File) // or better: var f *os.File; f = r Error checking being a common pattern, isError() can be added as a builtin or trivially in errors pkg. Likely the enclosing function also returns an error so the return in the second lin

Re: [go-nuts] Appreciating Go

2018-02-24 Thread roger peppe
> I once counted there were about 8000 uses of ,error as > return types for functions in $GOROOT/src which could benefit > from sum types. I'm not entirely convinced that sum types are a net win as a substitute for (T, error) return values. Where currently we have: f, err := os.Open(filena

Re: [go-nuts] Appreciating Go

2018-02-23 Thread Bakul Shah
On Fri, 23 Feb 2018 17:39:16 -0800 Ian Lance Taylor wrote: Ian Lance Taylor writes: > On Fri, Feb 23, 2018 at 5:23 PM, Bakul Shah wrote: > > > > I once worked out some details of adding sum types to Go and I > > think it is quite doable and easy to implement. > > There is an extensive discussion

Re: [go-nuts] Appreciating Go

2018-02-23 Thread Ian Lance Taylor
On Fri, Feb 23, 2018 at 5:23 PM, Bakul Shah wrote: > > I once worked out some details of adding sum types to Go and I > think it is quite doable and easy to implement. There is an extensive discussion of sum types in Go over at https://golang.org/issue/19412. Ian -- You received this message b

Re: [go-nuts] Appreciating Go

2018-02-23 Thread Bakul Shah
On Thu, 22 Feb 2018 12:55:01 + Jesper Louis Andersen wrote: > > For sums, in Go, I have to return a pair, > > x, err := someOperation(..) > > but this is slightly inconsistent, insofar I can return "nil, nil", which > might not be a valid value, or I can return "3, Error(..)" but in that c

Re: [go-nuts] Appreciating Go

2018-02-22 Thread Jesper Louis Andersen
Usually, the type theoretic basis is what is called a sum-type. They are corresponding to a logical OR or a '+' addition operation in algebra. A "struct" is rightfully a variant of a product-type, or a logical AND or a '*' multiplication operation in algebra[0]. Most (commonly used) programming lan

Re: [go-nuts] Appreciating Go

2018-02-22 Thread Josh Humphries
On Thu, Feb 22, 2018 at 4:56 AM, Steven Hartland wrote: > On 22/02/2018 09:46, andrewchambe...@gmail.com wrote: > > Just a list of things I like about Go, thanks everyone for the hard work: > > snip... > > Minor things that could be improved in order of importance: > > - Ways to express immutabil

Re: [go-nuts] Appreciating Go

2018-02-22 Thread Steven Hartland
On 22/02/2018 09:46, andrewchambe...@gmail.com wrote: Just a list of things I like about Go, thanks everyone for the hard work: snip... Minor things that could be improved in order of importance: - Ways to express immutability ... as a concurrent language it can still be easy to make mistakes

[go-nuts] Appreciating Go

2018-02-22 Thread andrewchamberss
Just a list of things I like about Go, thanks everyone for the hard work: Good things go has: - Go has an extremely useful std library. - Go has the best backwards compatibility I have seen (I'm pretty sure code from go version 1.0 still works today.). - Go has the nicest code manipulation tools