Live data from Hacker News

Stages of learning Go, with code examples

sourcegraph.com

101–110 of 118 posts

Re: Stages of learning Go, with code examples

#101
post #5

Just wondering, does Go finally has a package manager with proper versioning of modules? Edit: Somebody is heavily downvoting me on every reply, I would love to know why. I like Go and want to get into it since a few months but the missing package manager held me off. So what is wrong about my question?

I don't have a ton of experience with go, just some one off internal tools development, only a few dependencies. That said, I chose to manage my dependencies manually by making a fork of the relevant repositories. Yeah, it would have been nice if the higher order dependencies were automatically resolved, but the whole thing went smoothly, and felt familiar since it had nothing to do with Go at all. Maybe the take awa…

And how you follow minor version updates with your forked repos?

Re: Stages of learning Go, with code examples

#102
post #80
post #57

Earlier quoted context omitted.

> "go generate" AKA macros. I wish they were at least intellectually honest and just call them "macros" and start nice supporting hygienic macros in the language.

Yes, I do see macros as a possible alternative to generics, but not sure if it would ever happen.

Macros are not an alternative to generics, they're an alternative to C++'s template specialisation.

Most languages with generics don't provide for user-controlled code generation via generics (if they do generics-based codegen at all, IIRC GHC uses erased generics for instance). They tend to use macro systems or preprocessors instead.

Re: Stages of learning Go, with code examples

#103
post #80

Earlier quoted context omitted.

Yes, I do see macros as a possible alternative to generics, but not sure if it would ever happen.

Macros are not an alternative to generics, they're an alternative to C++'s template specialisation. Most languages with generics don't provide for user-controlled code generation via generics (if they do generics-based codegen at all, IIRC GHC uses erased generics for instance). They tend to use macro systems or preprocessors instead.

I know, but they surely would be a better solution than "go generate", as I doubt Go will ever have generics.

Re: Stages of learning Go, with code examples

#104
post #21

Earlier quoted context omitted.

You really don't need a package manager for Go. Honestly, the main reason you need them for node, python, etc is because you're deploying source code to your production environment. You don't do that with Go. You deploy a binary, which has everything wrapped up in itself. Think of it as a self-contained virtualenv that requires zero effort on your part :) In Go, code is packaged via source control repos. If you want…

Please somebody explain me how to manage next situation without manual copying of code and forking repos (in other words, we need to still be able get updates for minor versions from repositories). GOROOT/ pkg src/ lib1 app1 app2 And app1 requires lib1 version 3.x, app2 requires lib1 version 1.x. What can we do? Also, on whole this page https://golang.org/cmd/go/ I can't find ANY info, about how to fetch exact versio…

There's no such thing as lib1 version 3.x. lib1 is a single version. Every import path is a unique package. If you want to make a new version of lib1, you need to give it a different path. This can be as easy as manually inserting "v2" in the path, like /lib1/v2/ or /v2/lib1/

There's no way to use "go get" to get anything other than the head of the master branch... at least, not by default. If you use a service like http://gopkg.in then you can encode a version in the url/import path which can then redirect to a branch in github, so for example import "gopkg.in/natefinch/lumberjack.v2" will get the v2 branch of github.com/natefinch/lumberjack (gopkg.in does this with some git magic)

Re: Stages of learning Go, with code examples

#105
post #98

Earlier quoted context omitted.

> The community asks that you acquire some experience, work with what is there, make sure that you understand it, then suggest improvements. So what is it that you think people who want Go to have generics don't understand? You say that people should acquire some experience before criticizing Go, but you're only accepting a certain kind of experience. I've written tens of thousands of lines of code in similar languag…

> By deciding that only users of Go can criticize Go This describes my feeling when going through the thread and reading that significant weaknesses of Go are not significant.

If you haven't written any Go code, how can you know what weaknesses are significant? This is why people read reviews of every new tech gadget - because the feature list doesn't tell the whole story - you need the input of someone that has actually used the thing.

You can choose who to believe - someone who has tried the language, or someone who merely thinks they know what it'll be like. I know whose opinion I'd trust.

Re: Stages of learning Go, with code examples

#106
post #98

Earlier quoted context omitted.

> By deciding that only users of Go can criticize Go This describes my feeling when going through the thread and reading that significant weaknesses of Go are not significant.

If you haven't written any Go code, how can you know what weaknesses are significant? This is why people read reviews of every new tech gadget - because the feature list doesn't tell the whole story - you need the input of someone that has actually used the thing. You can choose who to believe - someone who has tried the language, or someone who merely thinks they know what it'll be like. I know whose opinion I'd tru…

> If you haven't written any Go code, how can you know what weaknesses are significant?

First of all, I have written Go code, I just wouldn't call myself an expert. And lack of generics becomes a pain in the ass rather quickly. I decided to come back when they had added generics, but it turns out that isn't happening.

But even if I hadn't ever written a line of Go, I don't think that would invalidate my opinion, because I've used other languages that makes the same mistakes. How many languages do I have to try out before my opinion on language features would be worth considering to you?

Your logic is like that of a child who wants to touch a hot stove. "Have you ever touched this hot stove? No? Then how do you know it will burn?" I've touched enough hot stoves in my life, thanks.

You also haven't responded to anything I said in my previous post, you're just reiterating what you said previously.

Re: Stages of learning Go, with code examples

#107

Earlier quoted context omitted.

Please somebody explain me how to manage next situation without manual copying of code and forking repos (in other words, we need to still be able get updates for minor versions from repositories). GOROOT/ pkg src/ lib1 app1 app2 And app1 requires lib1 version 3.x, app2 requires lib1 version 1.x. What can we do? Also, on whole this page https://golang.org/cmd/go/ I can't find ANY info, about how to fetch exact versio…

There's no such thing as lib1 version 3.x. lib1 is a single version. Every import path is a unique package. If you want to make a new version of lib1, you need to give it a different path. This can be as easy as manually inserting "v2" in the path, like /lib1/v2/ or /v2/lib1/ There's no way to use "go get" to get anything other than the head of the master branch... at least, not by default. If you use a service like…

> There's no such thing as lib1 version 3.x. lib1 is a single version.

I don't agree with this part (or we are talking about different things), but thanks for the second part of reply. At least something :)

Re: Stages of learning Go, with code examples

#108
post #90
post #42

Earlier quoted context omitted.

I would classify godep as a package manager in the same vein as bundler, pip, npm, etc., and in my experience it is absolutely essential if you still want your Go code to compile a month after you wrote it. I think the bit about source versus binary deployment is a bit of a red herring. It's not like any true Scotsman is deploying by running pip update in production either. As a developer you want to have code that c…

>Pull in enough dependencies and the chance of a conflict approaches one. Some of your dependencies will get updated and some of them won't, and soon enough you'll have a hard time finding any combination of versions that will compile. I'm not sure what you mean by "conflict". That's the nice thing about the way go packages work. There's no v1 of a package and v2 of a package. All packages are different. If one depen…

I have no idea what you are talking about.

There is nothing in Go that prevents people from making breaking changes to a package - and therefore breaking changes happen. I'll trust my real-world observations of broken dependencies over your assertion that they can't happen.

My point is if you're not tracking the version of your dependencies, it can be hard to even know what versions to go back to to get something that compiles. It may not be enough to just roll back the package with the breaking change, since you may have other dependencies that have been updated to depend on the new version.

The only way to reliably be able to compile your program in the future is to record the exact versions of all your dependencies.

Re: Stages of learning Go, with code examples

#109

Earlier quoted context omitted.

If you haven't written any Go code, how can you know what weaknesses are significant? This is why people read reviews of every new tech gadget - because the feature list doesn't tell the whole story - you need the input of someone that has actually used the thing. You can choose who to believe - someone who has tried the language, or someone who merely thinks they know what it'll be like. I know whose opinion I'd tru…

> If you haven't written any Go code, how can you know what weaknesses are significant? First of all, I have written Go code, I just wouldn't call myself an expert. And lack of generics becomes a pain in the ass rather quickly. I decided to come back when they had added generics, but it turns out that isn't happening. But even if I hadn't ever written a line of Go, I don't think that would invalidate my opinion, beca…

My apologies, there didn't seem to be much to address.

> the only people who would use Go are people who aren't aware of the last few decades of compiler research: people who think coroutines are a new idea and aren't sure whether generics are useful

This is simply untrue. Most developers I know that like Go have written tens of thousands of lines of code in other languages that do have generics and more advanced features. You seem to assume that because people disagree with you, that they must just be ignorant. How about if people disagree with you because we have different tastes in languages? Some people love LISPs, they drive me crazy. Some people love Python, I think it's merely ok. ... I love Go, and you hate it. That's ok. I don't think everyone has to like Go. But I don't tell the LISP people they should drop all this paren BS. I don't tell the Python people that they should add braces and static typing to their language.

> what is it that you think people who want Go to have generics don't understand?

...that generics are not needed in many of the cases where they're used. That YAGNI holds true a lot more often than they think. I had actually started coming to this conclusion (about generics) before I even started writing Go - and I'd already started using them less. Not having foo> in my code simplified it a lot, and given that most of the time I only ever implemented one version... it just wasn't worth defining a whole bunch of generic logic, when really I only had one concrete implementation that I'd ever use.

> My core complaint about Go: the authors simply have ignored decades of compiler research.

Not ignored, so much as "considered and discarded".

You say you've written Go and the lack of generics was a problem rather quickly. I have been writing Go for almost 2 years full time and 9 months on the side before that. Generics have almost never been a problem for me.

I see two possible reasons why we've had different experiences with Go:

Either you happened to be working on a project that really benefits from generics (something that makes heavy and repeated use of trees or vector/matrix math, etc)... or you were trying to write Go code the way you'd write in some language that does have generics.

If the former, well, that's truly unfortunate. Go doesn't work well for all projects. I wish it were better at that sort of thing, and maybe at some point we'll get some features that'll help out with those pain points. Maybe those features will be something like Generics... but I, for one, hope that it's not just generics like everyone else has generics, because I've been there, and I don't like it. There's a hell of a lot of code that doesn't need matrix math and left leaning red black trees and such. Go is good for all those projects.

If the latter, well, then you've really just shot yourself in the foot. This is like taking a minivan offroading in mud and then getting mad that it handles poorly. You have to use the language in the way it was designed. Yes, this means you probably have to write a min function every once in a while. Yes, this means you have to write a loop to test if a string is in a slice of strings. Just like you can't take the shortcut through the mud in the minivan. Just like you have to write type classes in haskell, or getters and setters in Java. Every language has its quirks.

All that being said, it's also completely valid fot you to say you just don't like Go. That's fine. I don't like a lot of languages, even though many other people do. But telling other people they're wrong or dumb for liking Go is not a position you can really justify. It's a matter of opinion, and opinions can't be wrong.

Re: Stages of learning Go, with code examples

#110

Earlier quoted context omitted.

> If you haven't written any Go code, how can you know what weaknesses are significant? First of all, I have written Go code, I just wouldn't call myself an expert. And lack of generics becomes a pain in the ass rather quickly. I decided to come back when they had added generics, but it turns out that isn't happening. But even if I hadn't ever written a line of Go, I don't think that would invalidate my opinion, beca…

My apologies, there didn't seem to be much to address. > the only people who would use Go are people who aren't aware of the last few decades of compiler research: people who think coroutines are a new idea and aren't sure whether generics are useful This is simply untrue. Most developers I know that like Go have written tens of thousands of lines of code in other languages that do have generics and more advanced fea…

Every small min function that you ride has the potential to have bugs. In a language with generics there is only one min function meaning only one source of potential bugs.

So is it simpler to have all these little functions doing basically the same thing with the chance of bugs or 1 generic implementation that works for all of them?

Looking at things in this light bug potential in Go is O(n) whereas a language with generics is O(1).

The point being that without generics you end up implementing lots of these small similar functions and making lots of potential sources of bugs.

Idiomatic Go encourages writing easy and simple to fix code, which is good. However what I get for all this is go allows me to write the simple and easy to fix code that could potentially have bugs everywhere.

Hope this makes sense, haven't used voice typing for anything this large yet.

Post reply on HN