16 ms·
First chapter of Kernighan and Donovan's new Go book [pdf]
- srtjstjsj 11y agoLink is to Chapter 1 with no context about whole book/availaibility. Book homepage is here: http://www.gopl.io/ http://www.gopl.io/ mods, please fix Several free full Go eBooks listed at http://hackershelf.com/topic/golang/ http://hackershelf.com/topic/golang/
- Artemis2 11y agoThe K&R for Go, sounds great!
- realrocker 11y agoFrom the book: "But it has comparatively few features and is unlikely to add more. For instance, it has no implicit numeric conversions, no constructors or destructors, no operator overloading, no default parameter values, no inheritance, no generics, no exceptions, no macros, no function annotations, and no thread-local storage."
- Isamu 11y agoFrom the preface: "achieving maximum effect with minimum means." Sort of the anti-Perl? I say this as someone who likes both Perl and Go. Go is very contrarian, and I applaud this.
- masklinn 11y ago> From the preface: "achieving maximum effect with minimum means." Wouldn't be out of place at a marketing agency, with about the same level of truth too. > Sort of the anti-Perl? In what sense? The one thing you can say about Perl is that it's a huge language, so the anti-perl would be a very small language. Go isn't a very small language (like Forth), it isn't even a small one (like Smalltalk or Self) it's about the same size/complexity as an early Java. Somewhat bigger in some ways (more magical builtins and constructs) somewhat smaller in others (simpler visibility rules, no synchronised methods/blocks), but in the best case it's a wash. > Go is very contrarian, and I applaud this. Perl is also very contrarian.
- rudolf0 11y agoI think it's fair to call Go an anti-Perl. Perl is very liberal. There's always more than one way to do things. Go is very conservative, in comparison. I'd agree that both are contrarian, but for very different reasons.
- masklinn 11y ago> I think it's fair to call Go an anti-Perl. Then again, pretty much anything can fairly be called an anti-Perl, possibly even Perl.
- seiji 11y agoGo is very contrarian, and I applaud this. It takes more than reversing the order of parameters and using known-braindead ideas like codified tabs-are-good syntax to make contrarian ideas valuable. Just because you change green lights to mean stop and red lights to mean continue doesn't make contrarian suddenly better than the way things were.
- rudolf0 11y agoWhile I think your comment is unconstructive, I do have to say that I don't quite understand why Go decided to force hard tabs. Even more confusingly to me, I really don't understand why they seem to standardize on tabs expanding to 8 spaces rather than 4. The 2 spaces (of soft or hard tabs) favored by some Ruby and CoffeeScript programmers is too little, but 8 spaces is way too much.
- norswap 11y agoAre they actually proud of having no generics? :o
- dekhn 11y agoNo, the authors specifically said that they would like to have generic features but couldn't figure out a way to implement it without unacceptable performance problems. I'm pretty sure the feature will show up in the next few minor version increments.
- MichaelGG 11y agoBasically they dismissed every implemented approach, despite generics obviously working in other systems. (And it's hardly a "new" feature unless we're counting in multiples of decades.)
- AnimalMuppet 11y ago> Basically they dismissed every implemented approach, despite generics obviously working in other systems. But working at a price. And Go isn't willing to pay the price (especially in terms of compile time). If Go ever adds generics, it will be with a new approach that doesn't blow up compile times.
- 15155 11y agoI wonder how much developer time is spent due to a lack of generics. Developer time costs more than compiler time.
- xrstf 11y agoWhich is why Go is advocating using "go generate" to generate code. See projects such as https://clipperhouse.github.io/gen/ https://clipperhouse.github.io/gen/
- 11y ago
- yokohummer7 11y ago> no default parameter values Hearing this leaves a bad taste in my mouth, because one of the (mis)features I've found in Go is its implicit default value in struct initialization. In Go, you don't get a compile error when you miss some fields while initializing a struct. e.g. type T struct { a int b string c float64 } t := T{c: 1.5} will happily set `t.a` to 0 and `t.b` to an empty string. While this is useful for maintaining backward compatibility (adding more fields to a struct doesn't break upstream code), it also hinders discovering genuine mistakes at compile time. So typical Go programs end up using 0 or an empty string as a sentinel value. This is probably what made me feel Go's dynamic nature the most. It really is pretty close to a dynamic language.
- deleted 11y ago[deleted]
- fixermark 11y agoIt's one of those features that seems mad until and unless one runs into the situation that justifies it. Go provides default values to avoid the C error-factory of random undefined behavior resulting from re-use of whatever is in a memory address; that much is clear. But the reason Go lets you partially instantiate an object (and separates out construction from state) is to make it easier to write unit tests, where the common case is that you want to circumvent the "main line" object construction pathways.
- bradtgmurray 11y agoThat looks a lot like C to me, which I wouldn't call a dynamic language. typedef struct Foo { int a; int b; } Foo; Foo f = (Foo) { .a = 1 }; // This will initialize b to zero.
- hactually 11y agoIsn't it funny how C has so many ways to accomplish the same thing. Why did you use a typedef with a tag? typedef struct { int a; int b; } Foo; Foo f = { .a = 1 };
- jgalt212 11y ago> no default parameter values This would seriously bum me out as I find the easiest to extend the functionality of an existing Python function is to add a new parameter with a default value. This way, regardless of whether the existing code base the calls the new or old version of the function, it performs the same way as it always has.
- bkeroack 11y agoSince Go is statically-typed and compiled, it's much easier to refactor a function compared to Python. Change it and fix everywhere the compiler complains.
- jgalt212 11y agotrue, forgot to think about that. But still potentially a lot of changes to fix, even if you are explicitly told what needs adjusting.
- logic 11y agoAnd this is where Go's tooling shines: https://golang.org/cmd/gofmt/ https://golang.org/cmd/gofmt/ (Refactor automatically, not by hand.)
- TillE 11y agoThat's fine for internal functions, but a big problem when publishing any kind of interface. It's really nice to be able to extend an interface without breaking stuff or adding cruft.
- pconner 11y agoYou can use variadic arguments with an interface type or a single struct parameter to get similar behavior.
- LBarret 11y agocompare this with python, which has carefully evolved into a better language.
- Artemis2 11y agoMore like into two languages that will keep on existing for the next decade.
- middleclick 11y agoQuestion for the Go experts out there: does it make sense to buy this book to learn Go or are there better tutorials/books?
- chimeracoder 11y agoThis book hasn't come out yet. Without having read it, I'd probably recommend it when it does, but for the time being, the online Go tutorial[0] is a great introduction. [0] https://tour.golang.org https://tour.golang.org
- pm90 11y agoEffective Go is a great intro: https://golang.org/doc/effective_go.html https://golang.org/doc/effective_go.html Also, check out the blog posts for more information on specific topics: http://blog.golang.org/ http://blog.golang.org/. They are really well written.
- andmarios 11y ago^ This! It is one of the reasons I like Go. Effective Go is all you need to understand the language and be able to read even the most complex Go programs.
- cronos 11y agoYou can easily learn go by going through all the pages under "Learning Go" here: https://golang.org/doc/ https://golang.org/doc/ and probably some practice projects. This book might be a good alternative but we can't know yet.
- aikah 11y agoI found "Go Blueprints" a good introduction for someone who wants to get into practical projects quickly, and doesn't need an introduction to programming. If I were to write a book about Go it would be exactly that, demonstrating how useful Go can be for day to day tasks, and for cli tools and servers.
- grey-area 11y agoYes it absolutely makes sense to buy this book to learn go; judging by the contents and first chapter it will be comprehensive and a very clear introduction to the core concepts of the language. It will probably end up being the definitive reference.
- vezzy-fnord 11y agoInteresting to see that the direct lineage from Pike's prior languages and CSP experiments is reaffirmed. I wrote about this here earlier, with some notable disagreements in response: https://news.ycombinator.com/item?id=9711639 https://news.ycombinator.com/item?id=9711639
- deleted 11y ago[deleted]
- claystu 11y agoI have no idea what they will specifically say regarding calling C from Go, but the table of contents says that part is only going to be about five pages. I really wish they would beef up this portion of the book.
- harikb 11y agoThe fact that it is a bit non-intuitive to call C from Go is exactly where there are so many 'Pure Go' libraries. I consider this as a short-term hurdle with long-term benefit.
- claystu 11y agoIt would be nice if all C libraries get rewritten in Go, but realistically, there are way too many for that to ever happen.
- skybrian 11y agoThere are lots of libraries in C (and Java) but the question is which ones are essential for whatever you're trying to do? There are lots of Go programs you can write just using the standard library. That appeals to me since I'm generally in favor of avoiding unnecessary dependencies. But if you need it, you need it.
- TillE 11y agoIt really depends on what you're doing, but even in common obvious stuff like networking, there can be functionality in libcurl or OpenSSL that you really need but isn't replicated in Go. Several years ago I remember trying to do SSL certificate verification with Python and finding the standard library lacking. Also bear in mind that good compatibility with C also means good compatibility with just about every other compiled language, including Rust.
- Omnipresent 11y agoTo those in the Go community: - What is Go well suited for other than network programming? - Why might one decide to write the backend API of their web app in Go, compared to say Grails, Python etc.
- chimeracoder 11y ago> What is Go well suited for other than network programming? Why might one decide to write the backend API of their web app in Go, compared to say Grails, Python etc. You'll get a lot of different opinions on this. I'll just speak based on my experience, since Python was my primary language before coming to Go. Everything I used to use Python for, I can do faster in Go. The notable exception to this is statistical analysis, as Go does not have any FORTRAN bindings[0], whereas Python does (through Numpy & co.). I still use a combination of Python, R, and other languages for this. I came to Go for the static typing and native concurrency[1], but I stayed because I'm more productive in it. Python and Go are about equally fun to write, but because I can build things much faster in Go, it ends up feeling more rewarding overall, given that my time is limited. If you don't really have a pressing need for anything else, you can stick with Python. But I found Python to be slow to develop in and cumbersome, and after trying Go out, I realized I was 100x more productive in it. [0] apparently this may no longer be true; if so, that's exciting news! [1] this was also before Python had built-in async. I still prefer Go's concurrency model and syntax, but at least Python has this as an option now.
- bdamm 11y ago100x? Even 10x is very significant. Why is it that you feel so much more productive in Go? Is it ease of refactoring? Lack of frustrating bindings bugs? Something else?
- chimeracoder 11y agoYeah, I know 100x is a huge multiplier, but I've actually tracked myself to the extent possible, and that really is the right order of magnitude for me. There are a number of reasons. I find refactoring is way, way simpler. Refactoring in Python feels painful enough that I always put it off until it gets absolutely necessary. With Go, I find it takes way less time, and also less mental energy. The static typing and strict compiler (enforcement of imports and lvalues, etc.) works well for my writing style. I write what's in my head, without worrying about the small details (only the high level logic), and I can be confident that it'll be easy to fix the small details (syntax, typos) afterwards. It's kind of like how writers often work - they dump words on a page, focusing on getting the main points across, and it's the editor's job to make sure they fix the grammar and style. I end up having a conversation with the compiler and when it stops telling me anything, the code usually does what I want it to. YMMV.
- tyrel 11y agoOne of my co-workers preordered this, I hope to skim through it if he brings it into the office.
- jfb 11y agoK&R is a great book. Even though I have no interest in Go, I'll read this, just to see if it's as good.
- ape4 11y agoer, they left a couple things out of the family tree (page xii). Like C++, Java, C#, ...
- DocSavage 11y agoIt's safe to say that C++ had an influence on the Go language at least as what not to do. The emphasis on language simplicity and compile speed seemed to be a result of fairly large C++ code bases at Google.
- mseepgood 11y ago"Other constructions in Go show the influence of non-ancestral genes here and there"
- fsloth 11y agoWould Go provide a viable alternative to C++ for numeric and computer graphics 'kind of stuff'? I have no problem with C++ but the better-than-python proclamations got me intrigued.
- vvanders 11y agoGiven that there's a GC and from what I understand(I'm no go expert) limited ways to specify memory layout I'd say no.
- fmstephe 11y agoI am curious about the limitations around memory layout. Go provides a fair amount of control to the programmer. Fields appear in the order declared in a struct (although potentially padded), structs declared as values, not pointers, are located in memory with the declaring struct and we can have arrays and slices of non-pointer structs they will all be arranged contiguously in memory. I am not a C/C++ programmer are there more powerful facilities provided in these languages? Real question, not trying to start a flame war :)
- FraaJad 11y agoD is a viable alternative for C++; you still get to enjoy near native performance and cleaner FFI compared to Go, without giving up the features of a modern programming language.
- kid0m4n 11y agoYes. Its always good to read the D success stories.
- andreaferretti 11y agoAlso, Nim would be a good fit for those domains. Macros and custom operators allow one to write dsl for numeric and scientific programming, and you have complete control over memory layout. There is a gc, but you can tune it very precisely
- 11y ago
- rendambathu 11y agoHope this book is going to be another Epic and Great reference like this gem[1] [1] http://t3.gstatic.com/images?q=tbn:ANd9GcTK3WbaQiO5mCmvRGtvcokJUyrd2wcpOj3WcgO8TQyecr3_TrmU http://t3.gstatic.com/images?q=tbn:ANd9GcTK3WbaQiO5mCmvRGtvc...
- _kst_ 11y agoThe link is to an image of the front cover of K&R2 (Kernighan & Ritchie, "The C Programming Language", 2nd edition). You probably meant the image to show up in your comment, but it didn't.
- jasonjei 11y agoJust as K&R introduced us to "Hello, World," I'm amused they adapted their first program to an Unicode world: "Hello, 世界." Seems like a great first chapter, covering computer graphics and web server/byte fetching to boot.
- vorg 11y ago> they adapted their first program to an Unicode world: "Hello, 世界." Would be nice if you could compose those complicated Unicode characters from simpler building blocks, e.g. fmt.Printf("Hello, %a", "→↘𠃊廿↓田介")
- jzelinskie 11y agoI think that would be a fun way to practice kanji, but I'd much rather just type "seikai" and press enter. Modern IMEs are awesome.
- peter303 11y agoI still prefer forced data abstraction, i.e. classes as a core construct. GO does not force that. Data abstraction, when properly done maps the code more closely into the problem domain to be solved. In the long run that makes the code more maintainable and extensible.
- why-el 11y agoI am really not sure this is true. In my opinion classes force an premature taxonomy almost all the time. I like that you can simply attach methods to structs when you decide you want object like behavior.
- tomcam 11y agoI understand both points of view but lean strongly toward why-el's. If there's one thing Java has taught us it's that "premature taxonomy" (love that term) can be a huge unnecessary tax on small to medium sized projects.
- nanoojaboo 11y agois there a way to `go get gopl.io` all the source code at once? currently, you have to do (and know the chapter names) like this `go get gopl.io/ch1/hello-world` (or something like that - I don't remember exact url), but, as mentioned, it only works if you know chapter names. Better if you could just get whole bundle
- linuxfan 11y agoCan people post their opinions on static linking of go binaries? Doesn't it result in increased size of runtime binaries when compared to those generated by C/C++?
- kid0m4n 11y agoYep. It does; but then again my entire static binary (no dependency on libc even) is around 10 MB in size... I love being able to pull down a docker container that fast!
- gjvc 11y agoThis is going to be the standard text for the language. The quality of writing is exceptionally good. It's high time the AW professional computing series had another hit.
- rmcpherson 11y agoI noticed that the lissajous program in 1.4, as included, generates non-random lissajous figures since the random number generator is not seeded. I couldn't find any reference to this in the text and this could be confusing to beginning readers. Is there a recommended way to submit errata?
- LVB 11y agoYou're correct, but in the interest of: We’ll discuss these topics only briefly here, pushing most details off to later chapters, since the primary goal right now is to give you an idea of what Go looks like... it's probably clearer to use the default random source.
- rmcpherson 11y agoGood point, but I also think it will be confusing to beginners who compile and run the program only to find that it always generates the same figure without any explanation as to why. Both the package documentation and text say that the generated figures will be random. The fix is just a couple lines and, I would argue, should be included in the source to eliminate the surprising behavior. http://play.golang.org/p/1WlhOdJ1pk http://play.golang.org/p/1WlhOdJ1pk
- ifross 11y agoIn the preface it does state: To run the examples, you will need at least version 1.5 of Go. $ go version go version go1.5 linux/amd64 Follow the instructions at https://golang.org/doc/install if the go tool on your computer is older or missing.
- morsegeek 11y agoThe deterministic rand behavior is the same for all go versions: https://golang.org/pkg/math/rand/#pkg-overview https://golang.org/pkg/math/rand/#pkg-overview
- sinatra 11y agoThis is a good place to ask this (because Go posts attract a lot of commenters, even those who dislike Go and like some other language): Which language/framework would you choose today for writing WebServices? Preferably with the following characteristics: static type (or at least static analysis), easy deployment (ex, generates a single binary like in Go), supports concurrency very well, is small/simple, has good tooling and debug support, and is fun to write. Go (except for good debug support)? Elixir (dunno how good it is with deployment and debugging)?
- flexd 11y agoI would choose Go. It comes with an excellent built-in package net/http (https://godoc.org/net/http https://godoc.org/net/http) that quickly allows you to setup a web service. An Go's mechanic (?) of implicit satisfaction of interfaces allows you to do some really cool things. One of the gripes about Go seems to be error handling, and your code ends up with a whole bunch of 'if err != nil { stuff }'. Matt Silverlock (http://elithrar.github.io/article/http-handler-error-handling-revisited/ http://elithrar.github.io/article/http-handler-error-handlin...) talks a bit about how you can use some of Go's strengths to create a web services without any frameworks or packages that aren't built-in. Go and net/http is very powerful and allows you to do very much without needing any external packages. If it was up to me, I would write the service in Go and run it in a container somewhere. But the container is not required :) Go has been a bit lacking in debugging options previously as you said, but lately cool projects like godebug https://github.com/mailgun/godebug https://github.com/mailgun/godebug and Delve https://github.com/derekparker/delve https://github.com/derekparker/delve have been released, making it possible to debug programs better.
- sinatra 11y agoYes, just using built-in packages, and not depending on too many third-party packages is definitely attractive to me. The code full of "if err != nil" is an issue that I've also noticed. However, I'm hopeful that this may actually remind me to be more exhaustive in error handling. Why did you mention the container? How kind of benefits would you be getting from a container for Go?
- Animats 11y agoThis is much better than the previous Go documentation, particularly in the concurrency area. The previous Go documentation introduced goroutines and channels, stated the mantra "share by communicating, not by sharing", and then gave examples with variables shared between goroutines. It now seems to be recognized that, in Go, if you want to lock shared data, use the lock primitives. Don't try to construct locking primitives from channels; that's error-prone and hard to read. This new manual seems to recognize this. When they want a shared counter, they use a shared counter with traditional locks.
- Jabbles 11y agoYou've been misinformed. The 2009 version of Effective Go stated, as it does now: "This approach can be taken too far. Reference counts may be best done by putting a mutex around an integer variable, for instance." https://web.archive.org/web/20091113154825/http://golang.org/doc/effective_go.html#sharing https://web.archive.org/web/20091113154825/http://golang.org...
- Animats 11y agoSee the very first example of "channels" in that 2009 version: "In the previous section we launched a sort in the background. A channel can allow the launching goroutine to wait for the sort to complete." ... c <- 1; // Send a signal; value does not matter. That's using a channel as a lock on shared data. Not seeing that in the new book. This is a step forward. (What Go really needs is Rust's borrow checker and move semantics, so that when you communicate on a channel, the compiler checks that you're not sharing too much.)
- nosequel 11y agoOf course if you care about speed at all, you will stay away from Go's mutex's. Time your own code, it is shocking how slow they are. I haven't published my own test times, but with a quick search here's an example of a 10ms loop taking 2s with mutex's. http://www.arkxu.com/post/58998283664/performance-benchmark-go-lang-compares-to-java http://www.arkxu.com/post/58998283664/performance-benchmark-...
- Armand_Grillet 11y agoI'm currently reading it as I started to program in Golang only one month ago and I'd never heard of goimports, this is a nice tool! Mixing it with GoSublime and it does a really good job http://michaelwhatcott.com/gosublime-goimports/ http://michaelwhatcott.com/gosublime-goimports/ The book is well written and it looks like it covers a lot of common topics, I think I'm gonna buy it.
- nimrody 11y ago"Typeset by the authors in Minion Pro, Lato, and Consolas, using Go, groff, ghostscript, and a host of other open-source Unix tools. Figures were created in Google Drawings." groff still going strong... although it seems like Kernighan got tired of drawing using the 'pic' language...
- copperx 11y agoYep, I was really curious to see if he had finally given up and gone to TeX, Indesign, or the like. I guess that if one's not dealing with a lot of math, groff is enough for many typesetting jobs. I'm curious as to which version of groff they used. Heirloom groff? GNU groff? hmm...
- eric_the_read 11y agogroff == GNU roff by definition. I suspect by "Heirloom groff" you mean troff or nroff.
- oconnor663 11y ago> ...its approach to data abstraction and object-oriented programming is unusually flexible. I'm not sure I can get behind that without generics.
- pkrumins 11y agoI just pre-ordered this book. I already have a feeling it will make into my favorite book series [1]. [1]: http://www.catonmat.net/blog/top-100-books-part-one/ http://www.catonmat.net/blog/top-100-books-part-one/
- dataminded 11y agoThey've proven that they can make a PDF. Will they sell me one?