> 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
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
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
> 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")}
>
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
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
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
> 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
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
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
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
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
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
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
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
15 matches
Mail list logo