Introduction to Go

Go 101

Both of my TA’ing classes, CIS 521 and CIS 380, are not offered this semester. So to spend the time elsewhere, I’m going to offer a whole new, experimental zero credit course: Go 101: Introduction to Go.

The class will focus on Go syntax, some simple data structure, and Goroutine usage. If we have time, some real-world applications, like OS or network, might be introduced as well.

The class is suitable for anyone who’s interested in Computer Science and Software Engineering, even for people with no prior knowledge in coding. I will try to make the class as approachable as possible. However, if you are interested in learning a language so that you could use an existing framework or tools, like stats, AI, big data, quant, etc., this class might not be ideal for you.

This course is NOT affiliated with Penn. You get absolutely no course credit or any certification whatsoever. This class, in turn, is absolutely free of charge and all course materials will be released into public domain.

I will still leave homework and they will be graded, and potentially I will give out tests/quizzes/exams. These assignments will not have deadlines.

I plan to hold Office Hours if there are many students and demands are high. Otherwise, email or Piazza should suffice.

Resource

Piazza
https://piazza.com/upenn/spring2022/go101
Gradescope
Entry Code WYREYW
Go website
The Go Programming Language
Go 101 (Textbook)
https://go101.org/article/101.html

Let me know via Email if you are not a Penn student but still want to access the quiz.

Schedule

The meeting time is weekly on Thursday 7 PM to 8:30 PM Eastern Time, from January 13th to April 21st, so 15 meetings in total. This is so far tentative.

Meeting is held remotely via Zoom: https://upenn.zoom.us/j/93107977009?pwd=ZnFIR0M3VHdWbG1VOS9remJONFJ2UT09. Class will be recorded.

Slides may or may not be made, depending on the content.

Jan 13

Topic

  • Class intro
  • Programming language intro (and why Go)
  • Binary data and memory intro
  • Primitive data types in Go

Recommend reading

Homework

A quiz is released on Gradescope.

Recording

https://upenn.zoom.us/rec/share/2Zo7h1x8wjBLc0T076D9qAktdORwy2HBi47cW0GDP0vx5yarPxjdzb9pilupCb-_.5AI9jICXkrAZArfN Passcode: 2*+R2EFB

Jan 20

Topic

  • Packages and function intro
  • Variables intro
  • Primitive literals
    • Integer
    • Floating-point
    • Complex
    • Boolean
    • String

Recommend reading

Basic Types and Basic Value Literals -Go 101

Homework

A quiz is released on Gradescope.

Recording

https://upenn.zoom.us/rec/share/CwUbPM2_T1sbMhVBAY_vGwysJMd234extmseDMVD64romoRXQ93lKK-hKah71yYx.1-kwbZNHCoTtvOMs Passcode: Dg8!dHA5

Jan 27

Topic

  • Basic Operators
  • Variables (continued) and Constants
  • Type conversion
  • Scope

Recommend reading

Homework

A quiz is released on Gradescope.

Recording

https://upenn.zoom.us/rec/share/WbADhx89M5ynkIG0o7XEaIzWXMBzuZwNXjlOXLmrOLwaSMAV67qlZ5yeCd62Pr6i.4hZ9JBlD_cSda3ti (Passcode: Nj@T5!x^)

Feb 3

Topic

  • Scope
  • Intro to functions
  • Package and Import
  • Array
  • Write and compile code demo

Recommend reading

Recording

https://upenn.zoom.us/rec/share/Pb3fBvqMnUu6887REkODH1OKu8kWRfNg4HlEPrfrWzCKNtp8PMJ047lBs4a_Iitd.TTIQK1i6qyoEpTXK (Passcode: Hyw3b=nw)

Homework

A programming assignment is released on Gradescope.

Homework

Operators & Functions

In this first assignment, you are asked to write some functions with the given signature, and then implement the required functionalities within it.

There are five parts to the assignment. Due to Go being a compiled language, and in this homework we are testing the ability to write functions, so you have to finish (almost) the entire homework in order to pass the compilation. The autograder will then test if the implemented functions has the correct functionality.

Before you start, please follow the instructions to install Go on your local computer (you should have it if you have finished Quiz 1). Then, follow the demo at the end of Feb 3 class, where we showed how to prepare a Go environment on your computer.

Once you have done that, create a file named main.go under your working directory. This is the file in where you are going to write Go program for this homework, and only this file. After you finished the homework, you should submit ONLY this file onto Gradescope.

For this homework, use package name main.

Part 1

Declare a constant at package-level of the main package, named CourseName, which has type string and value "Go 101".

Recall that a constant declaration starts with const, and that package-level is the top-level of a file (i.e. not in a code block). Also recall that identifiers are case sensitive.

Part 2

Declare a variable at package-level of the main package, named Counter, which has type uint8 and its zero-value. Recall that variable declaration starts with var.

After that, declare a function named IncCounter, which has no arguments and no return values. Each time IncCounter is called, increase Counter by one. Recall operators +, +=, or ++.

Your code should not access Counter anywhere else.

Part 3

Declare a function named BoolOperation, which takes in two bool arguments and returns four bool values.

The first return value is the logical and of the two input arguments; the second return value is the logical or of the two input arguments; the third return value is the logical not of the first input argument; the fourth return value is the logical not of the second input argument.

Recall that logical and uses the binary operator &&, logical or uses the binary operator ||, and logical not uses the unary operator !. Also recall returning values using the return keyword.

Part 4

Declare a function named IntArrayOperation, which takes in a single int array of size 4, and returns three int values.

The first return value is the sum of the first element in the array and the second element in the array; The second return value is the sum of the third element in the array and the fourth element in the array; The third return value is the product (multiplication) of the previous two return values (i.e. the product of the sum of the first and second and the sum of the third and fourth element in the argument array).

Recall operator + and *, also make sure to take care of calculation precedence. Recall the type of an array of type T with size N is [N]T. Recall that accessing the ith element of an array arr uses the indexing arr[i], and that index starts from 0.

You can assume that doing the above operations won’t cause overflows.

Part 5

Declare a function named PackFloatArray, which takes in four float64 as its argument, and returns a single float64 array of size 4.

As the name goes, the return value should be a float64 array whose stored values are the four given arguments, stored with the order they were given. More specifically, the first value in the array should be the first argument given to the function, the second value in the array should be the second argument given to the function, so on and so forth.

To return an array, return it the same way as any other values.


After implementing these five parts, first you should check if your code successfully compiles. Notice that success compilation doesn’t mean that the program is correct, but it does mean that all the types and operations are valid.

Later we will talk about how to properly write test cases for your code. For now, we can just use main function as a way to test our program. Within the main function, write some value and then call the function with the value. Output the results using println or fmt.Println. If the output result seems correct, then you are good.

Submit main.go onto Gradescope and get a score to see how well you did!