Live data from Hacker News

Learn Go: Hand-crafted Go exercises and examples

github.com

21–30 of 68 posts

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

#21
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

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?

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

#22
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

This is me right now. I get the basics of Go, but I don't understand when i'm suppose to have something be a pointer, and when i'm suppose to use * or & . Anyone who has a good explanation in a EL5 way, would help me a lot!!

You want a function that accepts a pointer when you want to modify an outside value within a function without returning the value. In that case, the func accepts a pointer (like in `func(p int)`) and you pass it either a pointer (a var declared as an {some_type}) or the address of a variable (with &variable).

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

#23
post #20
post #8

Earlier quoted context omitted.

Remember ByVal and ByRef from VB? (I hope you don't, it was the dark ages) but those to terms I've found are very useful for getting folk introduced to pointer - and also why.

That is really interesting to me! I never used VB, is the only difference here that it is "named" ByVal and ByRef that you think made it easier for people to understand than "pointers"?

Well, I use those terms (ByVal/Ref) and then say, one is a copy (byVal) and the other is a reference (pointer to you and me) to the thing.

So, pass small things ByVal (int, float), it's on the Stack.

Pass big things (Object) ByRef cause they're in the Heap.

Then I start saying pointer more than ByRef and the link is made.

Then on to ByRef/Pointer to how that then manipulate the shared data.

Once that basic is done, we refine/clarify around what Pointer really is, and also it's syntax.

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

#24
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.

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

#25
post #7

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.

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 common) return a copy of the data.

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

#27
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.

This doesn’t answer the question at all. Also it’s very disingenuous. The designers of Go were very much aware of the the last 20 years of language development. They decided on a subset that catered to software engineering between teams of people spanning a length of time.

It purposefully leaves out lots of features and cutting edge design philosophies because many Of those make things difficult when sharing code between multiple developers Spread over a long length of time.

Go’s philosophy has always been close to KISS. Don’t provide all these cutting edge tricks and tips because you can accomplish the same thing in a far clearer and maintainable way by doing it simpler.

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

#28
post #12

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

Same reason you learn any language. If you have zero interest in learning Go, why did you click or comment on this link? If you’re genuinely interested in what Go programming is like, the Go website has a Tour that is concise and well made.

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

#29
post #12

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

I was wondering the same thing, and it's sad to see this question downvoted. HN discussion quality is turning into Reddit.

It’s downvoted because it’s being facetious. If you actually want to learn about what Go programming is like or used for, go to the Go website and try the tour.

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

#30
post #12

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

Painting in very broad strokes here: If you are coming from C, because you're willing to trade a little bit of speed and footprint to no longer deal with malloc and free. If you're coming from a higher-level, dynamic language, because you're willing to give up some dynamism in order to gain speed and possibly concurrency.
Post reply on HN