{"id":25469928,"url":"https://github.com/thinkphp/computer-science-in-go","last_synced_at":"2026-02-16T23:10:23.638Z","repository":{"id":66902964,"uuid":"85220178","full_name":"thinkphp/computer-science-in-go","owner":"thinkphp","description":"computer science in go","archived":false,"fork":false,"pushed_at":"2024-12-30T10:00:39.000Z","size":77,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-30T11:17:54.361Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thinkphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-16T16:50:41.000Z","updated_at":"2024-12-30T10:00:43.000Z","dependencies_parsed_at":"2024-06-21T16:30:57.454Z","dependency_job_id":"270d2c76-50e6-43af-953d-004793cbf859","html_url":"https://github.com/thinkphp/computer-science-in-go","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp%2Fcomputer-science-in-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp%2Fcomputer-science-in-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp%2Fcomputer-science-in-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp%2Fcomputer-science-in-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkphp","download_url":"https://codeload.github.com/thinkphp/computer-science-in-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239436934,"owners_count":19638397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-18T08:31:19.642Z","updated_at":"2026-02-16T23:10:23.633Z","avatar_url":"https://github.com/thinkphp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Essential Go\n\n### Course Description\nThis course introduces students to the Go programming language, focusing on its unique features, syntax, and practical applications. Students will learn the fundamentals of Go and gain hands-on experience through various projects and exercises.\n\n### Course Objectives\nBy the end of this course, students will be able to:\n1. Understand Go's syntax and basic concepts\n2. Write and run Go programs\n3. Implement Go's concurrency features\n4. Work with Go packages and tools\n5. Develop small to medium-sized applications in Go\n\n### Week-by-Week Schedule\n\n#### Week 1: Introduction to Go\n- History and philosophy of Go\n- Setting up the Go development environment\n- \"Hello, World!\" in Go\n  ```go\n  package main\n\n  import \"fmt\"\n\n  func main() {\n      fmt.Println(\"Hello, Harvard!\")\n  }\n  ```\n- Basic syntax and data types\n  ```go\n  var i int = 42\n  f := 3.14\n  s := \"Go is awesome\"\n  b := true\n  ```\n\n#### Week 2: Control Structures and Functions\n- Conditionals (if, else, switch)\n  ```go\n  if x \u003e 0 {\n      fmt.Println(\"Positive\")\n  } else if x \u003c 0 {\n      fmt.Println(\"Negative\")\n  } else {\n      fmt.Println(\"Zero\")\n  }\n\n  switch day {\n  case \"Monday\":\n      fmt.Println(\"Start of the week\")\n  case \"Friday\":\n      fmt.Println(\"TGIF!\")\n  default:\n      fmt.Println(\"Regular day\")\n  }\n  ```\n- Loops (for, range)\n  ```go\n  for i := 0; i \u003c 5; i++ {\n      fmt.Println(i)\n  }\n\n  numbers := []int{1, 2, 3, 4, 5}\n  for index, value := range numbers {\n      fmt.Printf(\"Index: %d, Value: %d\\n\", index, value)\n  }\n  ```\n- Functions and methods\n  ```go\n  func add(a, b int) int {\n      return a + b\n  }\n\n  type Rectangle struct {\n      width, height float64\n  }\n\n  func (r Rectangle) Area() float64 {\n      return r.width * r.height\n  }\n  ```\n- Error handling\n  ```go\n  func divide(a, b float64) (float64, error) {\n      if b == 0 {\n          return 0, errors.New(\"division by zero\")\n      }\n      return a / b, nil\n  }\n  ```\n\n#### Week 3: Data Structures\n- Arrays and slices\n  ```go\n  var arr [5]int = [5]int{1, 2, 3, 4, 5}\n  slice := []int{1, 2, 3, 4, 5}\n  slice = append(slice, 6)\n  ```\n- Maps\n  ```go\n  studentGrades := map[string]int{\n      \"Alice\": 92,\n      \"Bob\":   87,\n      \"Charlie\": 95,\n  }\n  ```\n- Structs\n  ```go\n  type Person struct {\n      Name string\n      Age  int\n  }\n  p := Person{Name: \"Alice\", Age: 30}\n  ```\n- Pointers\n  ```go\n  x := 42\n  ptr := \u0026x\n  fmt.Println(*ptr) // Prints 42\n  ```\n\n#### Week 4: Object-Oriented Programming in Go\n- Interfaces\n  ```go\n  type Shape interface {\n      Area() float64\n  }\n\n  type Circle struct {\n      Radius float64\n  }\n\n  func (c Circle) Area() float64 {\n      return math.Pi * c.Radius * c.Radius\n  }\n  ```\n- Embedding\n  ```go\n  type Animal struct {\n      Name string\n  }\n\n  type Dog struct {\n      Animal\n      Breed string\n  }\n  ```\n- Composition vs. inheritance\n  ```go\n  type Writer interface {\n      Write([]byte) (int, error)\n  }\n\n  type ConsoleWriter struct{}\n\n  func (cw ConsoleWriter) Write(data []byte) (int, error) {\n      return fmt.Println(string(data))\n  }\n  ```\n\n#### Week 5: Concurrency\n- Goroutines\n  ```go\n  go func() {\n      fmt.Println(\"Hello from a goroutine!\")\n  }()\n  ```\n- Channels\n  ```go\n  ch := make(chan int)\n  go func() {\n      ch \u003c- 42\n  }()\n  value := \u003c-ch\n  ```\n- Select statement\n  ```go\n  select {\n  case msg1 := \u003c-ch1:\n      fmt.Println(\"Received from ch1:\", msg1)\n  case msg2 := \u003c-ch2:\n      fmt.Println(\"Received from ch2:\", msg2)\n  case \u003c-time.After(time.Second):\n      fmt.Println(\"Timeout\")\n  }\n  ```\n- Synchronization primitives\n  ```go\n  var mu sync.Mutex\n  var wg sync.WaitGroup\n  ```\n\n#### Week 6: Packages and Modules\n- Creating and using packages\n  ```go\n  // math/math.go\n  package math\n\n  func Add(a, b int) int {\n      return a + b\n  }\n\n  // main.go\n  import \"myproject/math\"\n\n  result := math.Add(3, 4)\n  ```\n- Go modules\n  ```\n  go mod init github.com/username/project\n  go get github.com/somepackage\n  ```\n- Third-party package management\n  ```\n  go get -u github.com/gin-gonic/gin\n  ```\n\n#### Week 7: Testing and Debugging\n- Unit testing with the testing package\n  ```go\n  func TestAdd(t *testing.T) {\n      result := Add(2, 3)\n      if result != 5 {\n          t.Errorf(\"Add(2, 3) = %d; want 5\", result)\n      }\n  }\n  ```\n- Benchmarking\n  ```go\n  func BenchmarkFibonacci(b *testing.B) {\n      for i := 0; i \u003c b.N; i++ {\n          Fibonacci(20)\n      }\n  }\n  ```\n- Debugging tools and techniques\n  ```go\n  import \"log\"\n  log.Printf(\"Debug: x = %d\", x)\n  ```\n\n#### Week 8: Web Development with Go\n- Introduction to net/http package\n  ```go\n  http.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n      fmt.Fprintf(w, \"Hello, Harvard!\")\n  })\n  http.ListenAndServe(\":8080\", nil)\n  ```\n- RESTful API development\n  ```go\n  // Using Gin framework\n  r := gin.Default()\n  r.GET(\"/api/users\", func(c *gin.Context) {\n      c.JSON(200, gin.H{\n          \"users\": []string{\"Alice\", \"Bob\", \"Charlie\"},\n      })\n  })\n  ```\n- Working with databases (SQL and NoSQL)\n  ```go\n  // SQL example\n  db, _ := sql.Open(\"mysql\", \"user:password@/dbname\")\n  rows, _ := db.Query(\"SELECT * FROM users\")\n  ```\n\n#### Week 9: Advanced Topics\n- Reflection\n  ```go\n  t := reflect.TypeOf(3)\n  fmt.Println(t.String()) // \"int\"\n  ```\n- Context package\n  ```go\n  ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\n  defer cancel()\n  ```\n- Best practices and common patterns\n  ```go\n  // Error wrapping\n  if err != nil {\n      return fmt.Errorf(\"failed to process data: %w\", err)\n  }\n  ```\n\n#### Week 10: Final Project\n- Students will work on a final project implementing a small application or service using Go\n\n### Assessment\n- Weekly coding assignments (40%)\n- Midterm exam (20%)\n- Final project (30%)\n- Class participation (10%)\n\n### Required Materials\n- \"The Go Programming Language\" by Alan A. A. Donovan and Brian W. Kernighan\n- Access to a computer with Go installed (version 1.16 or later)\n\n### Online Resources\n- [Go Official Documentation](https://golang.org/doc/)\n- [Go by Example](https://gobyexample.com/)\n- [A Tour of Go](https://tour.golang.org/)\n\n\n```\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"hello world\")\n}\n\n$ go run hello-world.go\nhello world\n\n$ go build hello-world.go\n$ ls\nhello-world    hello-world.go\n\n$ ./hello-world\nhello world\n```\n\n## Variables\n\n* var declares 1 or more variables.\n* You can declare multiple variables at once.\n* Go will infer the type of initialized variables\n* Variables declared without a corresponding initialization are zero-valued. For example, the zero value for an int is 0.\n* The := syntax is shorthand for declaring and initializing a variable, e.g. for var f string = \"apple\" in this case. This syntax is only available inside functions.\n```\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\n    var a = \"initial\"\n    fmt.Println(a)\n\n    var b, c int = 1, 2\n    fmt.Println(b, c)\n\n    var d = true\n    fmt.Println(d)\n\n    var e int\n    fmt.Println(e)\n\n    f := \"apple\"\n    fmt.Println(f)\n}\n```\n\n\n## Examples\n\n```\n\npackage main\n\nimport \"fmt\"\n\nfunc bubblesort(arr []int) {\n\n     done := true\n \n     var changes, i int \n \n     for done {\n\n         changes = 0\n         \n         for i = 0; i \u003c len(arr) - 1; i++ {\n\n             if arr[ i ] \u003e arr[ i + 1 ] {\n\n                arr[ i ], arr[ i + 1 ] = arr[ i + 1 ], arr[ i ]\n\n                changes++ \n             }   \n         } \n\n         if changes == 0 {\n\n            done = false\n         }\n     }\n}\n\nfunc main() {\n\n     arr := []int{9,8,7,6,5,4,3,2,1}\n\n     bubblesort( arr )\n\n     for _, v := range arr {\n\n         fmt.Printf(\"%d \", v)\n     }   \n}\n\n```\n\n\n\n\n## References\n\n- https://www.golang-book.com/books/\n\n- https://golang.org/\n\n- https://cs.lmu.edu/~ray/notes/introgo/\n\n- https://go.dev/doc/effective_go\n\n- https://gobyexample.com/\n\n- https://www.programming-books.io/essential/go/\n\n- https://www.digitalocean.com/community/tutorials/how-to-build-and-install-go-programs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkphp%2Fcomputer-science-in-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkphp%2Fcomputer-science-in-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkphp%2Fcomputer-science-in-go/lists"}