Go course

279 views
Skip to first unread message

Renato Marcandier

unread,
Mar 25, 2020, 12:57:23 PM3/25/20
to golang-nuts
Hello guys,

What's the best course to start with Go?



Regards
RG

David Riley

unread,
Mar 25, 2020, 1:35:23 PM3/25/20
to Renato Marcandier, golang-nuts
If you are already a programmer in another language, the Tour of Go (tour.golang.org) is absolutely the best.

If you are not already a programmer in another language, I personally don't recommend Go as a first language; it's an excellent language, but I feel that people will do better with it once they already grasp the fundamentals of programming and are ready for something with slightly more arcana. Python makes a pretty good first language.


- Dave
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b2aa0e9a-921f-49de-a0be-729a6ca35f5f%40googlegroups.com.

Dan Kortschak

unread,
Mar 25, 2020, 5:08:46 PM3/25/20
to David Riley, Renato Marcandier, golang-nuts
I don't agree that Go is intrinsically harder than python as a beginner
programming language. There are things that are subtle, but these can
largely be avoided in the beginner setting.

Note that there have been discussions here about using Go as a language
for teaching beginners, notably this one
https://groups.google.com/d/topic/golang-nuts/FIRSDBehb3g/discussion

Dan
> https://groups.google.com/d/msgid/golang-nuts/18B2AF64-4888-4730-B282-FCB4C00AB697%40gmail.com
> .


David Riley

unread,
Mar 25, 2020, 7:04:58 PM3/25/20
to Dan Kortschak, Renato Marcandier, golang-nuts
It’s just my opinion, and I’m willing to be wrong. :-)

But having TAed a university introductory computer science course that was first in C and then in Python (and having had several students who failed when it was in C retake in Python and pass with flying colors), I will say that a lot of the elements that tripped beginners up in C which were absent in Python are present in Go.

Most of those (e.g. separate compilation, static typing, a few other bits of arcana) are features that make Go a much more effective systems language than Python, but I do feel like it’s probably best to “take the bumpers off” AFTER the student knows about loops, variables, functions, etc.

Again, it’s only my point of view, and I do have some biases, but they do have some basis.


- Dave

> On Mar 25, 2020, at 17:08, Dan Kortschak <d...@kortschak.io> wrote:
>
> I don't agree that Go is intrinsically harder than python as a beginner

Amnon Baron Cohen

unread,
Mar 26, 2020, 4:51:58 AM3/26/20
to golang-nuts
Go is not C. C programmers have to master explicit memory management, which is a challenge to new and experience programmers alike.
C is a beautiful language. But very low level.

Having spent several years programming in Python, I would say that it is much more complicated than Go.
It has a large and growing number of expressive features which add to the cognitive load of those attempting
to get up to speed on the language. When you learn Go, you don't need to understand dict comprehensions,
decorators, metaclasses, asyncio etc. Compare the breathtaking simplicity of launching a Go routine
with the convoluted mess of python threading.

The lack of strong static typing and a separate compilation phase means that errors which in Go would 
cause a compilation error result in run-time exceptions, when a particular code path gets executed.

Python also has the "feature" that changes in invisible whitespace characters change the programme semantics.
I never really understood the rationale for the feature.

The Go 1 compatibility promise is also helpful. This means that course materials or online code examples written 
8 years ago will still work today. The python community broke most existing code when they moved from Python 2 to Python 3.
(A decade on this transition is still ongoing).
>>> send an email to golan...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/b2aa0e9a-921f-49de-a0be-729a6ca35f5f%40googlegroups.com
>>> .
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to golan...@googlegroups.com.

David Riley

unread,
Mar 26, 2020, 10:29:55 AM3/26/20
to Amnon Baron Cohen, golang-nuts
I'm aware that Go is not C, and memory management was not one of the points I mentioned. Memory management is a thing that trips up even extremely skilled developers. But I've been programming in C since 1997 and Python since 2010, and I've been working in Go long enough (and teaching new programmers) that I'm still pretty confident in my assessment, especially after having run dozens of labs with hundreds of students at varying skill levels.

New programmers often have a lot of trouble being bombarded with lots of new things off the bat. We tend to think of "Hello, world!" as pretty easy, but in C, there are a number of "magic" things in even that which have to be in place to even work which don't get explained until much later:

#include <stdio.h>

int main(void) {
printf("Hello, world!\n");

return 0;
}

To wit:

- What does #include do?
- What on earth does stdio mean?
- Why does our program need to be a function (if they know what functions are, which is not a given)?
- Why does it need to return an int?
- What's with the semicolons?
- Why printf, not print?
- What is \n?

That's not even considering what happens when they inevitably transcribe things wrong and have to figure out why it's breaking several lines from where they left out a semicolon.

Go's intro is somewhat simpler:

package main

import "fmt"

func main() {
fmt.Println("Hello, world!")
}

This simplifies:

- "import thing" is less arcane than "#include <thing>"
- No explicit newline needed with fmt.Println
- No explicit semicolons
- No return from main()

But:

- You still need to import something just to print a line, and it is confusingly (to the novice) named "fmt"
- You still need to declare a function called main(), and most brand-new programmers don't understand functions yet, so this becomes a "wave the dead chicken at it just right" thing
- Semicolons are still there under the surface, but they're inserted by the lexer, and when they get inserted can be really mysterious and trip a lot of people up

In contrast, in Python (3, in this case), it is:

print("Hello, world!")

There are no functions to create (you call one, which is universal in all these examples, but a lot easier to explain), execution just proceeds from top to bottom, variables are created much more easily (explaining the difference between = and := to someone who has never programmed before is quite a task), loops are far less complex, etc.

I'm not claiming Python is a better language, or less confusing overall. Once it gets more complex, Python starts to get in the way a bit more (I've never particularly liked the indent-based block structure, though actually students got a lot less tripped up by that than by brace matching, so there's that). But I steadfastly maintain that Go is not an ideal language to learn as a *first* programming language, simply because the amount of arcana you have to get right just to get simple things off the ground is far more than other languages like Python. And I have a substantial amount of experience with students which indicates where the trouble spots would be that cause people to give up and decide programming isn't for them instead of realizing that they're not starting at the right level.

This isn't a call for Go to change, because I'm totally fine with it being a second language after the basics of programming have been mastered. You don't start driving in a Porsche unless you want a very expensive and hazardous learning experience. Similarly, I think most of us could agree that teaching Java as a first programming language should be a felony, because it takes all these early-learning challenges and amplifies them (not only does main() have to be a function, it has to be in a class (what's a class?) and it has to specifically be "public static int main(String[] args)").

My only contention, and my intent in answering the original question, is that there is a great first-party Tour of Go that is going to be great if you already know how to program, but somewhat opaque if you don't already understand the basic concepts. Python's own first-party tutorial is the same, actually; it's good, but it's set up as an intro to Python assuming you already know the basics and I wouldn't recommend it to a new programmer. Since the OP didn't specify what level they were looking for, I provided both sides of my opinion.


- Dave
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b43ecb5a-c043-44d4-92d6-f8c046dda7ff%40googlegroups.com.

Sebastien Binet

unread,
Mar 26, 2020, 10:35:17 AM3/26/20
to David Riley, Amnon Baron Cohen, golang-nuts


On Thu, Mar 26, 2020 at 3:29 PM David Riley <frave...@gmail.com> wrote:
[...]
But:

- You still need to import something just to print a line, and it is confusingly (to the novice) named "fmt"
- You still need to declare a function called main(), and most brand-new programmers don't understand functions yet, so this becomes a "wave the dead chicken at it just right" thing
- Semicolons are still there under the surface, but they're inserted by the lexer, and when they get inserted can be really mysterious and trip a lot of people up

In contrast, in Python (3, in this case), it is:

print("Hello, world!")

to be fair, in Go, "hello world" can be reduced to:

package main
func main() {
    println("hello world")
}

that's usually how I start my Go-based lecture.
(and then, 2-3 lectures/hands-on sessions after that, I do introduce 'import "foo"')

-s

David Riley

unread,
Mar 26, 2020, 3:18:50 PM3/26/20
to Sebastien Binet, Amnon Baron Cohen, golang-nuts
And since I'm a fan of lifelong learning, I have to admit to not having known that println() was a builtin until this post. Thanks! That does un-complicate it somewhat.

Amnon Baron Cohen

unread,
Mar 26, 2020, 5:18:49 PM3/26/20
to golang-nuts
The println and print builtin may be removed from the language in the future.

Miki Tebeka

unread,
Mar 27, 2020, 5:11:27 AM3/27/20
to golang-nuts
I'm curious if you find https://www.353solutions.com/annotated-go helpful?

Owen Waller

unread,
Mar 27, 2020, 12:32:51 PM3/27/20
to Dan Kortschak, David Riley, Renato Marcandier, golang-nuts
Hi Dave,

As the original author of the post that Dan has referenced, I can say that Go does indeed make IMHO a good first programming language. It all comes down to how you explain things. Thanks Dan for the reference :)

I'm not going to repeat what the original discussion said, but let me try to pick out a few things.

I was teaching the very young - 10 & 11 year olds. So I had to simplify things down quite a bit. So I didn't cover things like:

* functions - arguments vs parameters I thought this was just too to big a step. Yes they used functions, but they didn't write them, including functions with no parameters and no return values.

* structs - again its just to big a jump. You can do a lot with just numbers and strings

* Local vs global variables - again too big a jump and doesn't make sense without functions.

* Anything you might think of as advanced - so concurrency, testing, packages and modules, file and network IO, even errors etc I left out.

With an older group I'd put all of those back in except concurrency, starting with functions, then packages, then IO.

But that still leaves the key things that all programming languages have in common namely variables, instruction sequencing, selection and repetition. In the UK this is what they have to cover at this age group. This is also the order I introduce these in, and over about 15 hours. So I let them work slowly. At least at this age group typing is still an issue, so they need time just for that.

Static typing I did not find to be a problem at all. The way I approached it was simple. Kids already have a good grasp of numbers (whole and fractions and decimals fractions) and words at this age. So they know that writing "hello+world" in English makes no sense. The "+" symbol is only used with numbers. So "1+1" does make sense in a different context.

All I had to do was ask the kids did they think they needed a number or a word for a variable type? If they where reading a variable from the keyboard that they had to use in a sum, they can work out they need a number not a word. If all they wanted to do was echo the variable back - say their name - then they work out it's a word. It takes a few hours, but within 3-4 hours most of the kids have worked it out. After that its just a syntax and typing problem.

You'll find that having the types helps the kids reason about the programs. This is something I personally find very difficult with python and other typeless languages. It's very hard to reason about an old bit of code because you don't know what the valid operations or data range is of a type, which especially if it a named well helps you reason about the logic. So with kids I would say you want to be as explicit as possible. Static typing helps with this.

The way I introduced numbers was subtle, but matches what they typically see in maths at that age. So a number is an int type initially. Only when we need fractions did I introduce float64, and I only talked about those two numeric types (so no int8 or float32). And I talk about numbers not int or float64, unless I have to be specific.

Words are simply strings, that's just a new name they have to learn and associate with a sequence of characters/letters. They get this really quickly.

The other approach I took was that I gave them partially completed Go programs, where the level of completion tails off each session. So I did this for two reasons. Firstly to cover a bit of boiler plate, things like the import statements and the main() function header. I do talk about these and the partial programs also explain these in the comments but I don't expect the kids to type these lines. Secondly I want them to focus on whatever was key to that session.

The programs are heavily commented to both explain what is there already and what and where I want them to fill in the blanks.

And since the programs are incomplete they won't compile and run to begin with. So they kids have to get he correct syntax from the get go. That's just the same as in English, you have to have the correct spelling and grammar, so the kids have a similar concept at that age.

If you do this they'll absorb things like main() and import just because they will be familiar. So they'll spot it if you leave it out after a few weeks. Or be able to complete an import statement (if you tell them the package name) just by coping a previous example.

My last trick was as I kept things to keyboard IO, I had a little wrapper package that hid the complexity of the text scanner class and converting form strings to ints etc that the programs used.

So to give you an idea of what I had them doing, they where printing "Hello <you name>" after inputting their name, working out how fast the ISS goes in orbit and the orbital period and comparing that to geostationary satellites, doing ROT13 encryption (so A becomes N) (in the UK they have to learn about Caesar ciphers at this age), getting them to print hello world in non-Latin languages (again works well with a divers group) and shows how you can count characters in a string.

Hopefully that helps. I've a pile of material, slightly out of date over the past 18 months as I have been busy on other projects. I'm happy to share that more widely and bring it up to date if that's any help to you or anyone else.

Good luck

Owen

Amnon Baron Cohen

unread,
Mar 29, 2020, 10:50:01 AM3/29/20
to golang-nuts
Thanks! A great write-up.
> wrote: Hello guys, What's the best course to start with Go? Regards RG -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b2aa0e9a-921f-49de-a0be-729a6ca35f5f%40googlegroups.com .
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/18B2AF64-4888-4730-B282-FCB4C00AB697%40gmail.com .
Reply all
Reply to author
Forward
0 new messages