quii / learn-go-with-tests

Learn Go with test-driven development
MIT License
22.19k stars 2.81k forks source link

"hello world" text should explain the difference between `:=` vs. `=` #622

Open meleu opened 1 year ago

meleu commented 1 year ago

First of all! Huge thank you for this amazing material! I'm new to TDD and Golang and I'm learning a lot! :heart:


As a person who has some years of experience with other programming languages but zero knowledge about Golang, I was a little surprised/confused when I saw statements like these ones:

  prefix := englishHelloPrefix
  prefix = spanishHelloPrefix

I googled and learned that we use:

In order to prevent people from having to leave the book to research this information, I suggest to put a short explanation about that in the text of the "Hello, World" chapter.

This can be especially enlightening for people coming from some interpreted languages background, where there's no clear difference between "declaration" and "assignment".

Brivan-26 commented 1 year ago

He mentioned it in the iteration chapter. But yes, it would be nicer if it was introduced in Hello world chapter

abhishekdas29 commented 1 year ago

The example given in hello world chapter is tricky since the prefix is defined as a named return parameter and thus is initialised automatically. However it does talk about an important aspect of when to use named return parameters as described in https://go.dev/tour/basics/7.