Live data from Hacker News

Learn Go: Hand-crafted Go exercises and examples

github.com

41–50 of 68 posts

Re: Learn Go: Hand-crafted Go exercises and examples

#41
post #12

This doesn't ask the most important question: why would I learn Go at all?

To answer the question: what would a language look like if you put it's designers in a time capsule for 20+ years and had them make a language that was uninformed by all the language advances and learnings they'd missed out on.

I think certain decisions, like ditching inheritance, were very much informed by the last 20 years of language 'advances'.

They certainly got some things wrong (null for example, and errors aren't great, generic collections would be nice), but it's quite interesting just how much they left out while making a very usable (IMO) language.

I don't want advances and progress in a programming language, I want it to get out of the way and let me think.

Re: Learn Go: Hand-crafted Go exercises and examples

#42

Earlier quoted context omitted.

Your can't really do anything real without pointers in Go though because you won't be able to mutate states out of a function.

Yes you can, lots of functional languages work without mutation. I'd go as far as to say mutating should be the exception, not the default, in more traditional languages.

Go misses almost all tools a functional programming language offers (no iterator or combinators of any kind) and even if you really wanted and decided the verbosity wasn't a problem for you, I'm pretty sure the compiler doesn't optimize it well (it does a lot less optimisations than LLVM for instance).

Re: Learn Go: Hand-crafted Go exercises and examples

#43
post #21

Earlier quoted context omitted.

I learned Rust & Go pretty much at the same time, and it actually works quite well because most of the paradigms are actually the same (structs & function implementation on top of them, error as return value). Rust is clearer about the point you mention[1], while Go introduction spend more time explaining things like threads and channels (which I wasn't familiar with), and finally Rust help you to use them properly,…

Yeah, Go focusing on threads and channels I agree is generally a painful new concept for beginners to learn. I've also seen beginners often "over-correct" and start using channels and goroutines for things they really shouldn't. How was your learning experience with Rust's borrow checking and pointers? Was it introduced to you early on, or later on?

I learned Rust through the book (first edition), which at this time was the only available material, and it was explained right at the beginning (at least borrowing, ownership and mutable borrows).

I like when things are explained upfront, and actually my biggest issue when learning Rust came from not having the smart pointers (like RefCell and Rc, which relax the ownership constraints) explained at the same times as regular ones.

Re: Learn Go: Hand-crafted Go exercises and examples

#45
post #44

I have not yet been able to find a simple "Hello World" example of starting a new project with Go modules instead of $GOPATH.

Hey there I found modules to be confusing coming from GOPATH too, but they're straight forward, super barebones example:

    #!/bin/bash

    cd $HOME

    # Create project directory
    mkdir hellogo

    cd hellogo

    # Init project modfile
    go mod init example.com/hellogo

    # Create the main source file
    # Uses bash's heredoc
    cat  ./main.go
    package main
    import "fmt"
    func main() {
        fmt.Print("Hello world")
    }
    EOF

    # Build it
    go build

    # Run it
    ./hellogo

Re: Learn Go: Hand-crafted Go exercises and examples

#46
post #44

I have not yet been able to find a simple "Hello World" example of starting a new project with Go modules instead of $GOPATH.

Actually, the official Go Blog has a decent "Hello World" example[0] for go modules - I've used this before, had to double check. [0] https://blog.golang.org/using-go-modules

Re: Learn Go: Hand-crafted Go exercises and examples

#47
post #7

Earlier quoted context omitted.

That's definitely true, but I've often seen beginners just say: type Foo struct { ... } func (f *Foo) Bar() { ... } And go "Aha, that's an object and a method, I get it!" but when asked whether they should be using a pointer there or not, have no idea what that even entails. In other words, it's possible to neglect the details of pointers easily and have things generally work

William Kennedy has an excellent post on this https://www.ardanlabs.com/blog/2017/06/design-philosophy-on-... As someone who has written (and read) a decent amount of Go the value vs pointer semantics of the function informs me of how the creator intends for the type to be used. Seeing pointer receivers informs me that there is an expectation of modifying the state while value pointers (which are thankfully more comm…

> Tom has also mentioned that a box of copy paper can hold 100k lines of code.

that comes out to 20 loc per 8.5x11 piece of printer paper.

I feel like that's nearly an order or magnitude too low.

Re: Learn Go: Hand-crafted Go exercises and examples

#48
post #39

Earlier quoted context omitted.

In case the question isn't facetious: Go's main advantage, IMO, is that is both simple and opinionated to the extreme. It's a language that makes a lot of choices for you (from "no while loop" through "no exceptions" to where the brackets go formatting the file). Those choices might be the best choice or not, but the point is that they're already made and they're enforced. The result is that in a big company, all pro…

This is very weak argument. Once these restrictions are embedded in language, it cannot be removed by anyone. On the other hand, same thing can be accomplished by using company-wise style enforcers. If you think that is harder, I'd say forcing every project in big company to use same language is even more harder. My main quip with Go is that its rather more of the same but more poorly done in the name of minimalism.…

But "company wide linters" do carry over to other companies and projects. For Go its already set up, you dont have to think about it. Otherwise youll have a week (or more) discussion for every single quirk in the language and how one would format that and try to apply this to a group of people.

I'd call them more like working standards. Imagine having to discuss how to make a brick wall everytime you need to make one. Things like having a masonry cord (which can equal to a "gutter", line length restriction) and the mixture of the cement, are critical for execution in a team of more than 1 person, and not following standards will make a hacked up job.

Re: Learn Go: Hand-crafted Go exercises and examples

#49
post #44

I have not yet been able to find a simple "Hello World" example of starting a new project with Go modules instead of $GOPATH.

Hey there I found modules to be confusing coming from GOPATH too, but they're straight forward, super barebones example: #!/bin/bash cd $HOME # Create project directory mkdir hellogo cd hellogo # Init project modfile go mod init example.com/hellogo # Create the main source file # Uses bash's heredoc cat ./main.go package main import "fmt" func main() { fmt.Print("Hello world") } EOF # Build it go build # Run it ./hel…

You can also skip building, and run directly using `go run`!

Re: Learn Go: Hand-crafted Go exercises and examples

#50
post #40

Earlier quoted context omitted.

This is the story I keep being told, but it doesn't seem to match with the reality of a language. Two example off the top of my head: Loop variables are captured by "reference", not by value, so it's very easy to create bugs where you capture accidentally capture the wrong thing and don't have the value you'd expect. Nulls, the billion dollar mistake. Most languages are quickly moving away from nulls (and pointers fo…

I'd read some post where Go designers boasted about how they simplified compiler code by cutting down a language feature. It seemed to me they were obsessed about keeping compiler simple which resulted in half-assed language that was then re-casted as achievement in minimalism. I've felt that Go is optimized for compiler designers as opposed to actual developers.

As a Go programmer myself, the syntax of Go is simple yet effective. You are in control of what should be done, and Go will make sure all edgecases are covered in _defined_ behaviour like a managed language would. In C, reading out of bounds is legal (except when the address is not accesdible). In Go, you will get a panic (that you can still catch, but its pointing out an invalid program state).
Post reply on HN