10 ms·
How I Start: Go (2014)
- okket 10y ago(2014) see Github project https://github.com/peterbourgon/how-i-start-go https://github.com/peterbourgon/how-i-start-go and Twitter https://twitter.com/How_I_Start/status/506510262909030400 https://twitter.com/How_I_Start/status/506510262909030400
- petepete 10y agoSo I can't just put my code in ~/Projects like with every other programming language I've ever used?
- tscs37 10y agoCreate the folder ~/Projects/go and use it as gopath, I recommend a vendoring tool to prevent cluttering.
- zamalek 10y agoMost tutorials (all? I had to RTFM) outright omit how to use gopath. Especially with forks.
- tscs37 10y agoBad tutorials then.
- matthewmacleod 10y agoRight, but if all of the tutorials are bad, it kind of points to a problem elsewhere.
- omginternets 10y agoThat people aren't RTFM-ing?
- matthewmacleod 10y agoNo - that the ecosystem or decisions are difficult to understand or communicate effectively.
- omginternets 10y agoSetting an environment variable is trivial, and becoming aware of this requirement also trivial. It's all but spoon-fed here [0] and here [1]. I've never encountered anyone -- both online and offline -- who has had trouble with this beyond "huh, I didn't know I had to do that. Duly noted". Until now, that is. You are making a mountain out of a molehill ... nay, an anthill. [0] https://golang.org/doc/install https://golang.org/doc/install [1] https://golang.org/doc/code.html https://golang.org/doc/code.html
- tscs37 10y agohttps://golang.org/doc/install https://golang.org/doc/install This is the official installation document. If you have problems finding proper tutorials, there is also https://tour.golang.org https://tour.golang.org which also links to the previous document on install instructions.
- PopsiclePete 10y agoMust be some shit tutorials. The ones I read were great. Did you just take "some-random-guy"'s blog at face value? There's an official Go home-page full of beginner guides.
- matthewmacleod 10y agoThis is what I've ended up doing, and it still drives me absolutely batty. Typically I'd group together all of the code and assets for a project in one place; any Go code has to exist in this separate namespace for no convincing reason. It's fine, I can work around it, but it's still quite annoying.
- ptero 10y agoI think I am in the same boat -- Go file layout model seems to be for multiple projects written in Go instead of (my typical case) a multi-language project with a component in Go. It is not really a big deal, I can overcome it with some simlinks and conventions, but this is not elegant; I hope a model to support this better will be added sometime.
- coldtea 10y ago>any Go code has to exist in this separate namespace for no convincing reason. The convincing reason is that you get several automated behaviors in fetching, installing and building this way. If you don't care for those, you can use whatever path you like for your code, and a custom makefile for building. Just don't expect "go build", "go install" etc to work.
- hazbo 10y agoSomething I pretty much do and have heard from other Go people that they do this also, is to just keep all my projects in the GOPATH. Whether they be written in Go or not. It essentially gives you an organised structure based on git URLs, so it's always easy to find anything. I use $HOME/go, and have projects in there written in a bunch of languages.
- woah 10y agoI do this. It's actually a pretty good way to organize code in general, not just Go. Still dumb that they force it on you.
- manojlds 10y agoRelated - https://github.com/kylebanks/goggles https://github.com/kylebanks/goggles
- XorNot 10y agohttps://getgb.io/ https://getgb.io/ if you want to.
- LaFolle 10y agoSetting up GOPATH, when _starting_ Go projects, has been one of the top frictions for newcommers. That why Cloudflare came up with a solution: https://github.com/cloudflare/hellogopher https://github.com/cloudflare/hellogopher. > Hellogopher: "just clone and make" your conventional Go project
- amorphid 10y agoI was frustrated with the directory convention as well. What I did was set up the Go directory structure, and then created a symlink to for my projects directory in the Go directory structure. I was already using a directory convention that followed the GitHub/user/project convention, and it seems to work fine. Use at your own risk :)
- sagichmal 10y agoIt may seem to work fine, but it doesn't. Symlinks are not officially supported by any of the Go tooling. Your setup is working by accident, and may break with any future release.
- zerr 10y agoAren't people annoyed by URL imports? e.g.: import "http://www.geocities.com/bla/packagebla" http://www.geocities.com/bla/packagebla" i.e. I don't want to mention some 3rd party irrelevant company name, and especially its URL in my source code.
- smcl 10y agoI saw a comment recently that suggested URL imports are only meant for quick-start, hacky or stuff that won't be deployed somewhere. If you want a given version instead of the tip of master, for example, you're meant to retrieve them separately and set your GOPATH to that directory.
- fnord123 10y agoThis is called vendorising your dependencies and is done because you can't/shouldn't rely on the third party server being available and serving the same version of the source code to build your code.
- fnord123 10y agoJava broke that barrier a long time ago with com.sun.whatever and com.google.whatever, etc.
- pjmlp 10y agoThose names don't change when you move the code from Subversion, to Github, to Gitlabs, to Mercurial, to cool SV startup offering SCM services.
- fnord123 10y agoThat's true. But the complaint was sullying his/her code with third party names.
- mattmanser 10y agoBut the reason you don't want to mention a third party is precisely because you may want to change that third party. And if you start maintaining a redirect on a site you control, what happens when you let the domain die because you never use it? The amount of HN people who have a personal domain listed in their profile that is dead because life got in the way is surprisingly high (including me until recently).
- tachion 10y agoInterestingly, the very first thing I've read, that is the environment setup contains instructions that I was told are incorrect by Golang people - one should not use brew to install Golang on macs, one should download the official package. The brew installation, for example, lacks the offline tour package, and who knows what else.
- fnord123 10y agoThe brew formula is here: https://github.com/Homebrew/homebrew-core/blob/master/Formula/go.rb https://github.com/Homebrew/homebrew-core/blob/master/Formul... url "https://storage.googleapis.com/golang/go1.8.src.tar.gz" mirror "https://fossies.org/linux/misc/go1.8.src.tar.gz" version "1.8" sha256 "406865f587b44be7092f206d73fc1de252600b79b3cacc587b74b5ef5c623596" This checksum matches the one on the official download page: https://golang.org/dl/ https://golang.org/dl/ 406865f587b44be7092f206d73fc1de252600b79b3cacc587b74b5ef5c623596 The Golang people could save a lot of headaches and fix whatever they see wrong in the formula so people can continue to use their package manager instead of being reduced to Windows style savagery. Edit: looks like someone indeed tried to make an issue: https://github.com/Homebrew/homebrew-core/issues/9272 https://github.com/Homebrew/homebrew-core/issues/9272 If I understand, the Go team made the binary package install stuff not in the source tarball. That's doesn't sound like a good idea but they're some smart people; I'm sure they have some reasons. T'woud be nice if they helped bring brew in-line as well.
- sagichmal 10y agoHomebrew is a perfectly acceptable, even preferred way to install Go on Macs. Who has told you otherwise? They are wrong, or are speaking from a very specific context.
- thewhitetulip 10y agoI agree that Go makes programming simple, in a matter of less than 6months, I learned how to write a webapp in Go just by using the standard library, later, I wrote a guide to teach how to write webapps in Go without using a framework, using an example based approach https://github.com/thewhitetulip/web-dev-golang-anti-textbook/ https://github.com/thewhitetulip/web-dev-golang-anti-textboo...
- camus2 10y ago> Go makes programming simple Go is simple for simple tasks that fit Go type system, and yes the single formatting standard and the linting helps with readability. Go is a pain in the ass for complex tasks that don't fit go type system, like de-serializing polymorphic data or working with XML. But at the end of the day, the lack of polymorphism in the language makes complex things way more complex than they should be. Finally, Go relies way to much on runtime behavior for a statically typed language.
- why-el 10y agoThese are quite unsubstantiated claims. Go is used in many a non-trivial program, such as Kubernetes, Docker, Google internal projects, and so on, and the one denominator among these is the plethora of data formats they need to work with.
- PopsiclePete 10y agoHis claim isn't necessarily wrong, and neither is yours. I find dynamically-typed languages easier to work with when dealing with (de)serialization, it's just that Go isn't too horrible at that to warrant abandoning it and losing out on its other niceties in favor of a different stack. I mean, everything sucks at something, and Go's type-system isn't....great....but it's "good enough" to where you just kind of curl your lips in slight disapproval sometimes instead of tearing your hair out.
- xiaoma 10y ago> "I agree that Go makes programming simple, in a matter of less than 6months, I learned how to write a webapp in Go just by using the standard library" I've met non-technical people who were able to make a webapp in PHP after 6 days with just the standard library and the O'Reilly Head First book.
- grennis 10y agoAfter seeing URL string parsing in application code I would have expected to see at least some sort of discussion about third-party web frameworks.
- viiralvx 10y agoEven a web framework isn't necessary. Most people get around that nastiness using gorilla/mux: https://github.com/gorilla/mux https://github.com/gorilla/mux
- cube2222 10y agoDon't you worry, it's not done like that. Either you use query params, or you use a library like gorilla, where you just insert pattern variables into the url.
- k2xl 10y agoIt is really great that the latest Go version doesn't require setting the GOPATH
- thekingofh 10y agoHas anyone noticed an extreme explosion in languages? It seems like a good hobby project to create your own language and then evangelize evangelize evangelize. I'm all for advancement, but this feels like overload. We have each of the big companies promoting their own languages. Microsoft: C# (and other flavors), Apple: Swift, Google: Go, Mozilla: Rust... I'm sure I could keep going, but that seems to be the trend lately. You can't be a big company and not have your own programming language. So I guess the language changes for each domain. There is no longer the dream of a single language to unite all the plebes! Maybe it was a dream anyways.
- vishbar 10y agoI see what you're saying between Swift, Go, and Rust, but I'm not sure C# belongs in the same category. There are orders of magnitude more real-life lines of code implemented in C# than the other three combined. It's much more comparable to Java. F# may be a better comparison.
- cicero 10y agoIndeed, Microsoft wanted to use a modified Windows-centric version of Java called J++, but Sun wouldn't let them, so they created C#.
- pythonaut_16 10y agoI think this is the future. There will always be a few main do-anything languages, but we're going to see languages that fit certain use cases becoming very common. Historically languages were limited by their compilers and VMs. You ran Java or C++ because it took a large company to come up with a fast enough environment. Now we have the tools and experience that anyone can create a fast enough language in a few weeks. Also historically, if you wanted your code to run faster, the answer was pretty much always to move to a lower level language. Java too slow? Use C++. C++ too slow? Use C and/or optimize choke points with assembly. The tooling exists now that we can solve a lot of those same hard problems using languages and tools designed to solve them without reinventing the wheel in C or assembly.
- insertnickname 10y ago
- alimbada 10y agoIt's 2017 and developers are still abbreviating variable names ('err', 'resp', etc. in the article). It's tragic that readability is still not seen as a priority by so many people.
- fiatjaf 10y ago'error' is a protected keyword in Go.
- LukeShu 10y agoNitpick: Syntactically speaking, it's not a keyword. But it is a universally defined type name, which means you can't use it as a variable name.
- fiatjaf 10y agoThat's what I meant. If I didn't say it, it was because of a typo.
- alimbada 10y agoThen use another word; 'defect' and 'fault' are two acceptable synonyms I managed to look up in less than a minute.
- fiatjaf 10y ago'response' is too large. Having too large lines is not great for readability.
- tedchs 10y agoI absolutely love Howistart, but some of their tutorials are getting a little dated. This one uses Go 1.3, whereas 1.8 is now GA, and there has been a lot of progress around vendorizing dependencies.
- startupdiscuss 10y agoFor those of us who are new to go, can you say a little more about how this might be different if it was updated for 2017? (Or if it is involved, perhaps a link?)
- sagichmal 10y agoThere would be no substantial changes, as this project has little to no interaction with the GOPATH, and doesn't use any dependencies. It's a testament to the stability of the language.
- pdappollonio 10y agoSome things are easier now, like an automatic $GOPATH set to $HOME/go, or the ability of vendoring dependencies so you don't need to worry if companyx.com/project/package no longer exists.
- baby 10y ago1. setting GOPATH as $HOME made me uncomfortable, I don't see why anyone would want to pollute his/her home directory with bin, pkg, and src folders. 2. in his example, `go get github.com/your-username/hello` also automatically compile the thing into a binary in `$GOPATH/bin`. Is that correct?
- zeveb 10y agoI like to do this for my main Go path (I use per-project ones as needed), since I want ~/bin and ~/src (the former is where all of my personal binaries go, and the latter is where all of my personal source trees go). I guess I don't really mind that there's a ~/pkg — I might mind quite a bit more if I ever used a GUI file manager, but I never do that.
- didip 10y agoI don't think GOPATH as $HOME is a common thing (even back then). A lot more people uses $HOME/go as GOPATH. So much so that $HOME/go is the default in Go 1.8.
- hazbo 10y agoTo answer 2) yes, you're correct. If there is a main package that exists at `github.com/your-username/hello`, a go get will leave the resulting binary in $GOPATH/bin.
- gcb0 10y agothat whole thing is so subversion.
- nowbacktowork 10y agoReading the title I was really hoping this was story of a program loading and executing. And that the site had this documented for multiple languages. Does anyone know of a resource like that? I understand it would be different in on each platform but a fun and interesting read either way.