Readit News logoReadit News
vesak · 7 years ago
Go is missing 2 things that I care about:

1) proper dependencies management system (the new module system might address this) and

2) gener... nah, just kidding -- actually null protection. I don't want to see another segfault or null pointer failure ever again.

If it had these two features, I'd probably stop toying around with Rust and Crystal and just use Go. Unfortunately, 2) is probably impossible without seriously breaking old code, and they're not gonna break old code.

yawn · 7 years ago
Totally agree on 2. "Learn a language a year" they said. "Learning new languages expands your thinking" they said. What they didn't say was that once you use ADTs to model data, Maybe/Option types to avoid null, exhaustive pattern matching, etc, you want those features in all the languages you use.

I don't ask for much. I just want a GC'd Rust (one of the few modern languages that has option types in the std lib) or an F# that isn't tied to the .NET standard lib. Please?

how_to_bake · 7 years ago
I think Swift is the closest thing to a GC’d Rust. However, since Windows isn’t a first class platform for Swift, I’d recommend checking out Scala.

I think they’re doing a compiler rewrite that steals the good ideas from Rust (like good error messages).

masklinn · 7 years ago
> F# that isn't tied to the .NET standard lib. Please?

F# is basically OCaml on .Net, so… OCaml?

mastax · 7 years ago
OCaml? ReasonML?
mercer · 7 years ago
In regards to 2: I find it difficult sometimes to work with a language that doesn't have Elixir/Erlang's pattern matching, and sometimes I wish I hadn't learned about it...

(the pipe operator is another favorite I miss often)

mickronome · 7 years ago
I actually stopped learning new languages with these features because I started to get so frustrated they weren't available. Or I implemented then am everyone got weirded out by their 'strangeness'
remoteorbust · 7 years ago
Terrible idea: could you write a transpiler for rust that basically auto-wrapped everything in a Gc<> type and auto-dereferenced?
noncoml · 7 years ago
OCaml?
sheeshkebab · 7 years ago
Couldn’t agree more.

Nil exception handling is horrible in go. The thing wasn’t designed to handle pointers and blows up left and right once someone tries to use them (or untyped objects).

Dependency management is a total mess.

regecks · 7 years ago
When have you seen segfaults in Go? I think 100% of the time, it is either a bug in the Go runtime, or you're using cgo (which is not really Go anymore).

A language as simple as Go without nilable types would be great, though.

jdoliner · 7 years ago
C programs tend to call nil-pointer panics "segfaults" even though go runtime doesn't print the word "segfault" anywhere. I'm guilty of the same thing.
pknopf · 7 years ago
nil pointers exist in Go. It is common to run into them, especially when using "&".
axaxs · 7 years ago
Agreed with 2. I honestly don't understand why the compiler doesn't do analysis to catch such cases. As someone who doesn't work on these things, perhaps it's too intensive? I've made silly nil pointer mistakes before and wondered why the compiler didn't say 'hey dummy, look what you did here'.
xiaq · 7 years ago
Re. "null protection": It is kind of hard to fit non-nullable pointers into Go. The fact that non-nullable pointers do not have a natural initial value and always require an initial assignment is especially problematic in Go's struct semantics, because first of all, struct creation is supposed to be light-weight. If a struct contains pointers, the cheapest way to initialize it would be to assign them nil.

But the more interestingly problem is how Go's struct "constructor" works. It is very low-level, you just assign some fields in a struct like &SomeStruct{X: 1, Y: "y"}; you can also assign all fields, in which case you can omit the keys, like &SomeStruct{1, "y"}. let's call those the key-value variant and positional variant of "free-form constructor".

You can provide a "function constructor", which is simply a function that returns SomeStruct or * SomeStruct, but it is not required, nor can you forbid the free-form constructor.

This is in stark contrast with, say, Java, where the function constructor is both required and the only allowed form. That makes it easy to make sure that non-nullable pointer fields are always initialized, because the compiler only needs to check the constructors.

In Go it is much harder. You can make the free-form constructor check that non-nullable pointer fields get initial values, but then Go has this promise that the author of a struct can add new fields without breaking users of the free-form constructor, as long as they are using the key-value variant instead of the positional variant. So if a struct was originally:

type SomeStruct { X int Y string }

A user can make an instance with &SomeStruct{X: 1, Y: "y"}. If the author of the struct decides to add a new field, the code should still work. That should be the case even if the new field is a non-nullable pointer field. This now defeats the purpose of non-nullable pointer fields.

nicoburns · 7 years ago
> but then Go has this promise that the author of a struct can add new fields without breaking users of the free-form constructor, as long as they are using the key-value variant instead of the positional varian

This is the bit that would need to change. And actually, doing so would provide the same benefits that non-nullable types do in other contexts.

Say a Go library user is using a struct in 5 places, and the library author adds a new field. The user updates the free-form constructor to properly initialise the new field in 4 of those 5 places, but overlooks the 5th. As it stands, that will fail silently if the program is relying on using a non-null value somewhere else in the code. If upgrading the library caused a compile time error then that bug would have been caught.

Rust also has "free-form constructors" like Go, and this is the approach it takes: you must provide a value for all fields.

masklinn · 7 years ago
> first of all, struct creation is supposed to be light-weight.

Non-nullable pointers don't make struct creation any more expensive.

> You can provide a "function constructor", which is simply a function that returns SomeStruct or * SomeStruct, but it is not required, nor can you forbid the free-form constructor.

You can have an exported function returning a non-exported type. This restricts the "freeform" constructor to the package's internal's. It severely limits the caller's ability to use it (unless you also provide an interface to work with), but it's there.

DelightOne · 7 years ago
Why isn't Go implementing Optionals like Swift with guard let, if let, etc.?
apta · 7 years ago
Because it would need generics
kellengreen · 7 years ago
Try out dep for dependency management. It's still young, but is getting better all the time.
cube2222 · 7 years ago
The new official way of package management is vGo. Dep was an experiment which was suucceded by vGo, which in 1.11 is officialy (beta) included in the Go toolkit and will be the main way in Go 1.12.

There's a great blog post series about it (though it's dense, plan to spend a few hours to read it all: https://research.swtch.com/vgo)

Dead Comment

ancarda · 7 years ago
>Last release where godoc has a command-line interface

What? Are they removing “godoc <pkg>”? I used that a lot as a man page. It’s especially useful when you don’t have internet access

Edit: it’ll still be available in `go doc`, just that `godoc` will only be a web server. https://tip.golang.org/doc/go1.11#godoc

mappu · 7 years ago
Plaintext at https://github.com/mvdan/talks/blob/master/2018/go1.11.slide if anyone else gets Chrome freezing for a few seconds navigating left/right.
Insanity · 7 years ago
Thanks! I am on my phone and it is impossible to read it.
mchahn · 7 years ago
It is sad when a website design is so bad it requires usage instructions on the home page.
trulyrandom · 7 years ago
Is there a good way to view these Go presentations on mobile? I find them almost impossible to navigate on my smartphone.
nostalgeek · 7 years ago
kodablah · 7 years ago
A change to gofmt like that is going to require a large formatting commit to conform. Presumably/ideally there are CIs that fail on invalid format, so it's not like you can wait until you touch the file again. Not a big deal, but still worth noting.
mappu · 7 years ago
There was a change to gofmt in 1.10, too: https://golang.org/doc/go1.10#gofmt

"""Note that these kinds of minor updates to gofmt are expected from time to time. In general, we recommend against building systems that check that source code matches the output of a specific version of gofmt. For example, a continuous integration test that fails if any code already checked into a repository is not “properly formatted” is inherently fragile and not recommended."""

kodablah · 7 years ago
> For example, a continuous integration test that fails if any code already checked into a repository is not “properly formatted” is inherently fragile and not recommended.

As a frequent repo/commit spelunker, I'm gonna have to disagree here. It is better to have this changed all in one commit instead of tacking on that formatting change along with an unrelated change elsewhere in the file and doing that all over the place at separate times. What's inherently fragile (formatting wise) is making a change to a file that does not meet the current formatting requirements and then having it format on save/commit, messing up blames, code review diffs, etc.

Merovius · 7 years ago
Ideally, CI won't fail on invalid format, but just politely apply the correct format. There's nothing more frustrating than being told to do a job a machine can trivially to better (like executing "gofmt").
iainmerrick · 7 years ago
Right, so, checks and balances.

Server-side you have the check.

Client-side you have a hook that runs gofmt when you commit, and in principle you’ll never hit the server-side check.

Just in case something goes wrong -- and something somewhere always goes wrong -- you don’t want the server to silently rewrite stuff on your behalf.

wawhal · 7 years ago
Finally, I can keep my Go projects wherever I want.
stplsd · 7 years ago
Ech, I like to submit to GOPATH. One less thing to think about.
geezerjay · 7 years ago
I missed any reference to GOPATH. Does this release fixes Go's problem of forcing developers to specify source code directories through GOPATH?
agnivade · 7 years ago
That is correct. Now you can clone and build Go repos anywhere.

Note that support is still experimental, so if you want stability, it is advised to remain inside GOPATH for another release. This is a good post - https://systemdump.io/posts/2018-07-22-go-modules

However, do please feel free to try it out and file bugs.

stplsd · 7 years ago
It is not covered here:

- WebAssembly and Modules have already been covered.

https://github.com/golang/go/wiki/Modules

Animats · 7 years ago
The "prove pass" is a nice step forward. As that is improved, more subscript checks will be optimized out.
iainmerrick · 7 years ago
Huh, a change to spacing in gofmt? Won’t that cause extra source control churn in a lot of projects?
cyphar · 7 years ago
It actually could cause bigger problems than that. Most Go projects I've seen have CI runs that check whether 'gofmt' complains -- and fail builds if they do.

Ultimately though I don't really care all that much. Everyone will fix it in a few commands, and everything will be green again.

iainmerrick · 7 years ago
I care if it makes it harder to browse version history and see which changes were made when, and why.
iudsfyg8ysd98fg · 7 years ago
This is why you lock to a specific version of gofmt and let team upgrade in conjuction with reformatted source repo.
Cthulhu_ · 7 years ago
I like to think it's OK because gofmt reduces formatting churn overall.
masklinn · 7 years ago
In this specific case it doesn't do that: any time you add or remove a field from a structure, if it's one of the "extremes" gofmt might re-pad the entire thing, churning the entire structure.