News for hackers. Stuff that matters.
Re:Nine years of Go by CSDude on Saturday November 10, 2018 @02:42PM (#18423085)
I love Go, used it a lot for over 3 years. I love the simplicity, directness, the inline structs, but I still cannot get out of the package management mess. I can even tolerate `if err != nil, return err` and do not care enoguh of generics, but I hope Go modules and Go 2 would fix, over the time, it has really become a love-hate relationship for me. My daily driver at work is Java and some Python, I really miss the tooling (of course, not runtime classnotfound errors) and maturity. Not ignoring the success of projects with Go, such a big one as Kubernetes, I think it is a whole different aspect, but Go started to tear me out through the years, and it is hard to defend it.
Re:Nine years of Go by atombender on Saturday November 10, 2018 @04:36PM (#18423644)
We've transitioned entirely to Go modules. It's been largely painless at the codebase level. Being able to ditch GOPATH is fantastic. It helps that "go mod init" includes automatic migration from Dep. So far we haven't run into any serious bugs; compared to Dep (and Glide before it), "go mod" just works.

However, the toolchain is lagging [1], sometimes in quite serious ways. Pretty much every third-party tool that reads Go source code — linters, code generators and so on — uses an unofficial, largely undocumented package called golang.org/x/tools/go/loader to parse Go code into AST structures. This package has not been updated to understand Go modules, and so it fails, and it has been abandoned in favour of a new, also largely undocumented library, golang.org/x/tools/go/packages, that works completely differently. There's a tracking issue [1] that discusses the progress of converting these tools. There's no document that describes how to migrate.

It's annoying because we've come to rely on some, such as Mockery and go-sumtype, that still don't work with Go 1.11. In both cases the authors seem to have abandoned the projects, and updating the code isn't always so trivial.

[1] https://github.com/golang/go/issues/24661

Re:Nine years of Go by xiaq on Sunday November 11, 2018 @12:50AM (#18425178)
I don't think you really mean golang.org/x/tools/go/loader or golang.org/x/tools/go/packages are literally undocumented; simply pasting the URL gives you pretty detailed godoc for both packages. Rather, there is no official "how to load Go packages guide" pointing to those packages, and tool developers probably discovered those only by reading other source code.

FWIW, the .../loader package is explicitly documented as experimental. The .../packages has a deadline of 1 Dec 2018 for breaking changes (both info found in their respective godoc)

Re:Nine years of Go by agnivade on Monday November 12, 2018 @12:35PM (#18434057)
The tools team is still working on go/packages. It is bound to get better.

Given that modules support is still officially experimental, there are bound to be rough edges. But by 1.12, I think we will have a solid modules story.

Re:Nine years of Go by pmoriarty on Saturday November 10, 2018 @03:28PM (#18423313)
I have no love of Go nor of Java, but Python's packaging is a nightmarish tower of babel built upon a mountain of spaghetti.

There are so many incompatible, NIH wannabe solutions to packaging in Python. Recent tools like pipenv have made things easier from the user standpoint, but if you dare to look at how the sausage is made it's still an absolute mess.

Even if newer packaging tools are better, there are still tens of thousands of packages that use the older, nonstandard, even messier solutions.

Re:Nine years of Go by weberc2 on Saturday November 10, 2018 @04:42PM (#18423681)
I feel this. I own the build/deploy/local-dev infrastructure for our Python application, and dependency management is so very broken.
Re:Nine years of Go by plicense on Saturday November 10, 2018 @07:54PM (#18424404)
Why so? We use a frozen requirements file and so far its been decent. What bothers you and how would you like it to be improved?
Re:Nine years of Go by the_clarence on Saturday November 10, 2018 @03:25PM (#18423303)
There is no better way to do errors imo, unless you're going the erlang way of "let it fail". Errors can be passed to the caller the same way exceptions are, and it becomes an endless pursuit of where the error is actually being handled (if at all). I agree that some syntax sugar helps, see Rust, but it doesn't completely fixes the problem.
Re:Nine years of Go by nvarsj on Saturday November 10, 2018 @05:00PM (#18423752)
It's baffling though that the compiler doesn't at least warn when you forget to check the err. So many edge cases with that (especially due to `:=` vs `=` if reassigning a prior err).
Re:Nine years of Go by AlexCoventry on Saturday November 10, 2018 @08:33PM (#18424541)
Re:Nine years of Go by thegeekpirate on Sunday November 11, 2018 @12:26AM (#18425142)
Specifically (if wanted standalone) https://github.com/kisielk/errcheck
Re:Nine years of Go by AlexCoventry on Sunday November 11, 2018 @12:46AM (#18425172)
Personally, I like my linter output in the style of a furious fruit salad, so I go for the kitchen sink.
Re:Nine years of Go by networkimprov on Saturday November 10, 2018 @05:39PM (#18423908)
But there are good ideas on how to do errors better...

See Go2 Error Handling feedback:

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

And possible requirements for Go2 errors:

https://gist.github.com/networkimprov/961c9caa2631ad3b95413f...

Re:Nine years of Go by tigershark on Saturday November 10, 2018 @06:23PM (#18424064)
Exhaustive pattern matching combined with ADT seems way better to me compared to the go error handling where it is pretty much guaranteed that you will shoot your own foot forgetting to handle some errors...
Re:Nine years of Go by weberc2 on Saturday November 10, 2018 @06:52PM (#18424181)
I agree this would be an improvement, but Go’s solution seems to work pretty well.
Re:Nine years of Go by shazow on Saturday November 10, 2018 @02:53PM (#18423141)
Can you expand on "I still cannot get out of the package management mess"?

I've used the community dep project for a while, which was okay. I switched to the GO111MODULE experiment and it's more than okay.

Re:Nine years of Go by CSDude on Sunday November 11, 2018 @03:10AM (#18425436)
Try adding a dependency to a big project like client-go or Docker client, it always gets messy for me.
Re:Nine years of Go by 0x8BADF00D on Saturday November 10, 2018 @03:38PM (#18423360)
> I love Go, used it a lot for over 3 years. I love the simplicity, directness, the inline structs, but I still cannot get out of the package management mess.

The problem is the package managers available are fragmented and fundamentally incompatible. You have dep which is the official “experiment” and 10 others that share no compatibility whatsoever. Until there is either an official package manager or at least a standardization of the package format, you will run into these issues.

Re:Nine years of Go by mseepgood on Saturday November 10, 2018 @03:43PM (#18423396)
I think you missed the last 6 months of development regarding Go dependency management.

It's even mentioned in the blog post: "Last spring, we published a draft design for Go modules, which provide an integrated mechanism for versioning and package distribution. The most recent Go release, Go 1.11, included preliminary support for modules."

Re:Nine years of Go by Zach_the_Lizard on Saturday November 10, 2018 @05:16PM (#18423818)
I think go modules are still experimental, and thus many companies and projects have not yet converted. This has been my experience anyways; I'm still using dep at work.

Because go modules came later, it will take a while for the community to convert, and there will still be dark corners running on Glide for probably another year or two (or longer).

Re:Nine years of Go by weberc2 on Saturday November 10, 2018 @06:53PM (#18424186)
They’re official in version 1.11.
Re:Nine years of Go by Zach_the_Lizard on Saturday November 10, 2018 @07:10PM (#18424257)
From the Go wiki:

>Go 1.11 includes preliminary support for versioned modules as proposed here. Modules are an experimental opt-in feature in Go 1.11, with the hope of incorporating feedback and finalizing the feature for Go 1.12. https://github.com/golang/go/wiki/Modules

They are officially present and will be compatible in some way with future releases, but its still having the kinks worked out.

Re:Nine years of Go by weberc2 on Saturday November 10, 2018 @08:48PM (#18424587)
Ah, my mistake. Thanks for correcting me.
Re:Nine years of Go by shakna on Saturday November 10, 2018 @04:58PM (#18423743)
So there's ten incompatible package managers and one incomplete one. The situation will improve in future, but isn't there yet for all use cases.
Re:Nine years of Go by paulddraper on Saturday November 10, 2018 @07:34PM (#18424343)
> Last spring

> 6 months

> preliminary support

No, I didn't miss hearing about it, just like no one missed hearing the Python 3 release.

You've got nine years of open-sourced Go...even in the best case scenario, it'll take more time that six months after a draft design for this to not be a common, massive pain point.

Re:Nine years of Go by virmundi on Saturday November 10, 2018 @03:32PM (#18423333)
How do you keep track of dirty writes on structs? I want to only persist if the struct was actually changed. I could add getters setters, but a lot of the Go community seems to say I’m stupid for wanting to do that. I could track externally from the strict, but that seems backwards.
Re:Nine years of Go by weberc2 on Saturday November 10, 2018 @04:39PM (#18423656)
Can you elaborate for someone who doesn't know what "keeping track of dirty writes on structs" is for?
Re:Nine years of Go by virmundi on Saturday November 10, 2018 @09:38PM (#18424699)
Sure. I have a Profile. Let's say I load it from the database and make a change. I want to know if I need to save the profile. This is particularly important when using optimistic locking, a.k.a. resource versioning. My profile has a version number, like an ETag. I only want to update if there is a real change, and updating increases that revision number with every persist.

Here's a scenario. A woman gets married. Her last name changes. She updates the profile from Smith to Jones. The last name is now dirty. The code that save the object can say, "Are you dirty?" The struct says, "Yup". Saving code says, "Right! In you go." On the other side, the bit gets flipped back to false (it's cleaned). At the end, the revision updates by one and goes back to the client.

Another scenario. A user opens the edit profile box, doesn't change anything, but hits save. Without a dirty check, the object, which hasn't fundamentally change, gets saved with a new revision number.

Now what is all this about the revision number? I don't want to allow changes to a profile whose revision number is greater than the revision number my client passes. Let's say the Profile has revision 5. The client, which has been disconnected for a bit, says, "Update the profile, at revision 2, with all this new great data." The system needs to reject that update. The client needs to tell the user, "Sorry. That didn't work. Here's all this new data." If the client is especially Canadian, it will also say, "Oh, by the way we've saved your data, would you like us to copy it over the new data". I've never seen Canadian code, and mine is especially Floridian, but it could happen like that.

All of this is fairly easy in OO languages, which Go is not. It's actually easy in Go too if you use -ters and Setters (Go doesn't like GetFirstName(), but is okay with FirstName()). If I use functions attached to structs, easy. Just curious how other feel about this.

Re:Nine years of Go by vthallam on Sunday November 11, 2018 @01:02PM (#18427619)
We use functions on the struct. I know it's not ideal but just works for us.
Re:Nine years of Go by PavlovsCat on Saturday November 10, 2018 @05:04PM (#18423766)
https://en.wikipedia.org/wiki/Persistence_(computer_science)...

I first heard of that in context of writing to the screen, actually, when you don't want to redraw all the things every frame, or simply can't afford to, and only draw the things that have changed (i.e. are "dirty"). So if you were to keep track of the old position of an object, you might redraw the area of background where that object was, and then just draw the object at the new position, instead of drawing the background for the whole screen, and then the object.

Browsers are also kinda heavy on this when it comes to both layout and drawing. E.g. when the content of a div with fixed size changes, you only have to layout and draw the text in the div -- but if the size isn't fixed, you might relayout and redraw everything on the page that follows the div, but might not need to touch anything that comes before it. I'm sure it's incredibly complex, but still much faster than not doing it.

Re:Nine years of Go by randomdata on Saturday November 10, 2018 @04:59PM (#18423751)
He mentions persistence. Probably for use in an ORM-like fashion, where only the table columns that have changed are to be updated.
Re:Nine years of Go by rpeden on Saturday November 10, 2018 @05:20PM (#18423841)
Maybe store a hash of the values in the struct and check against that too see if anything has changed? If you're doing lots of dirty checks, that might be too resource intensive, though.

Or just use getters and setters and if anyone calls you stupid, ask them to demonstrate a better solution that still solves your problem.