Live data from Hacker News

NilAway: Practical nil panic detection for Go

uber.com

171–180 of 262 posts

Re: NilAway: Practical nil panic detection for Go

#171

Is there any movement in the language spec to address this in the future with Nil types or something?

Without intention to offend. It's Golang, the language that famously ignored over 30 years of progress in language development for the sake of simplicity.

What answer do you expect?

Re: NilAway: Practical nil panic detection for Go

#172
post #128

Earlier quoted context omitted.

It is a type safe language, not exactly sure what you're hinting at here.

This entire post is a big workaround go's insufficient type system because nil is not modelled in it. That's not safe.

I agree I probably should have said strongly typed instead of safe, as yes, if you dereference a pointer to nil you are going to crash. That being said, I do think "possesses an untyped nil" is a pretty far cry from "not type checked at all". It's certainly much safer than languages like C or C++ which allow type punning, or Java, where both nullables and runtime exceptions associated with types are generally a more pernicious problem.

Re: NilAway: Practical nil panic detection for Go

#173

Earlier quoted context omitted.

Not at all. Otherwise brainfuck would be the simplest language to learn. How do you currently represent a type that is A or B in Go? You have to use an interface. That’s much more complex than using a sum type would be.

Well, Brainfuck is simple to learn. The entire specification fits comfortably on a single page. Simple to learn doesn't automatically imply simple to use for any given purpose. The same is true for Go. > You have to use an interface. That’s much more complex than using a sum type would be. More complex how and by what metric?

> The entire specification fits comfortably on a single page

But to understand the specification and how it can be used to do a programming, you need to have at least a cursory understanding of turing machines and related theory, which isn't necessary to learn Java or python.

Under your definition, the conceptually simplest language is something like SUBLEQ, (the specification is only a single line!) but in this case, being able to implement the language, and learning the language aren't the same thing. Learning the language generally means, like, useful for given purposes.

Re: NilAway: Practical nil panic detection for Go

#174
post #56

Earlier quoted context omitted.

This is the core of the problem. Of course you can learn the language in a weekend, but you're bound to make the same mistakes developers have been doing for decades. This may be ok, as you say, if you allow errors here and there because you are fine dealing with those problems. But at the other end, it may be a user that is affected by the error. Which may be ok as well, but why should it be? We lament the quality o…

Go is just making a certain set of tradeoffs. If you try to fix all the "mistakes developers have been doing for decades", you get Rust. And considering that Rust is already Rust, there is not much point in trying to make Go another Rust. The line has to be drawn somewhere. I think everyone has certain things they'd put on the other side of that line, and strict nils are probably at the top of the list for many, but…

The argument is that Go is making a _wrong_ set of trade-offs.

It was designed, specifically, as per Rob Pike, for _bad_ developers. Developers who couldn't be productive at Google because they weren't properly taught at unis [0].

Then it caught momentum and then here we are, discussing a bad language designed for bad developers as if there is nothing better we can do with our lives.

[0] https://news.ycombinator.com/item?id=16143918

Re: NilAway: Practical nil panic detection for Go

#175
post #71
post #60

Earlier quoted context omitted.

If you squint really hard, the work on generics is a step toward the future. If you don't squint, then I don't think so.

With generics, can you not make a NonNil struct in Go, where the contents of the struct are only a *T that has been checked at construction time to not be nil, and doesn't expose its inner pointer mutably to the public? I would think that would get the job done, but I also haven't really done much Go since prior to generics being introduced Otherwise, since pointers are frequently used to represent optional parameter…

Even if this would be possible, it won't be idiomatic.

Re: NilAway: Practical nil panic detection for Go

#176
post #88

Earlier quoted context omitted.

I never said otherwise. My point is that Go is far harder to learn than they're implying. It certainly can't be learned over the weekend — well, maybe it can be, but the code you end up writing will Inevitably be full of resources leaks, panics, nil pointer issues, improperly handled errors, etc. You may be able to put together some basic logic, but you are far from understanding the language. I don't think it's hone…

I agree that it's very unlikely for someone to learn Go in a week and start writing flawless code. But Go's real strength is in its readability, not writability. I think it's very much possible to learn Go in a week, then read clean Go code like the standard library and understand exactly what's going on. At least that's my interpretation of what it means for a new grad to be productive in Go in less than a week. Nob…

As a fairly experienced engineer, I have to say that reading go code is what gives me the most pause. I find the amount of visual noise and lack of useful abstractions makes it so that to be efficient at reading code, I have to trust that the loop or the error handling code is doing what I expect. The issue with go is that the primitive operations are written `for i := 0; i I generally do the second, because doing the first is extremely tiring when reviewing code, but I dislike it immensely.

Re: NilAway: Practical nil panic detection for Go

#177

Earlier quoted context omitted.

> Default Gender = Male is... not great enum Gender { Unspecified, Male, Female, Other, } impl Default for Gender { default() -> Self { Self::Unspecified } } or: enum Gender { Male, Female, Other, } and use Option instead of Gender directly, with Option::None here meaning the same that we would mean by Gender::Unspecified

I think they are talking about the cons of Go allowing zero value. Rust doesn’t have that problem.

    type Gender int
    const (
        Unspecified Gender = iota
        Male
        Female
        Other
    )
Works the same way. Declaring an empty variable of the type Gender (var x Gender) results in unspecified.

Re: NilAway: Practical nil panic detection for Go

#178
post #71

Earlier quoted context omitted.

With generics, can you not make a NonNil struct in Go, where the contents of the struct are only a *T that has been checked at construction time to not be nil, and doesn't expose its inner pointer mutably to the public? I would think that would get the job done, but I also haven't really done much Go since prior to generics being introduced Otherwise, since pointers are frequently used to represent optional parameter…

Every type in Go has a zero value. The zero value for pointers is nil. So you can't do it with regular pointers, because users can always create an instance of the zero value.

Turns out worse isn’t better after all. Who could have guessed?

Re: NilAway: Practical nil panic detection for Go

#179
post #177

Earlier quoted context omitted.

I think they are talking about the cons of Go allowing zero value. Rust doesn’t have that problem.

type Gender int const ( Unspecified Gender = iota Male Female Other ) Works the same way. Declaring an empty variable of the type Gender (var x Gender) results in unspecified.

…and now you need to check for nonsense values everywhere, instead of ever being able to know through the type system that you have a meaningful value.

It’s nil pointers all over again, but for your non-pointer types too! Default zero values are yet another own goal that ought to have been thrown away at the design stage.

Re: NilAway: Practical nil panic detection for Go

#180

Earlier quoted context omitted.

This is one of those things which feels like just a small trade off against convenience for the language design, but then in practice it's a big headache you're stuck with in real systems. It's basically mandating Rust's Default trait or the C++ default (no argument) constructor. In some places you can live with a Default but you wish there wasn't one. Default Gender = Male is... not great, but we can live with it, s…

Default gender male not how this works in practice. Instead, you define an extra “invalid” value for almost every scalar type, so invalid would be 0, male 1 and female 2. Effectively this makes (almost) every scalar type nullable. It is surprisingly useful, though, and I definitely appreciate this tradeoff most of the time. (Sometimes your domain type really does have a suitable natural default value, and you just ma…

Great, now you’ve brought the pain of checking for nil to any consumer of this type too!
Post reply on HN