{"id":13490680,"url":"https://github.com/SuperPaintman/the-evolution-of-a-go-programmer","last_synced_at":"2025-03-28T06:31:44.294Z","repository":{"id":52962617,"uuid":"239391401","full_name":"SuperPaintman/the-evolution-of-a-go-programmer","owner":"SuperPaintman","description":"The Evolution of a Go Programmer","archived":false,"fork":false,"pushed_at":"2024-06-14T07:32:27.000Z","size":4,"stargazers_count":1312,"open_issues_count":11,"forks_count":60,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-25T10:06:36.864Z","etag":null,"topics":["developer-roadmap","go","go-roadmap","golang","roadmap"],"latest_commit_sha":null,"homepage":"","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/SuperPaintman.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":"2020-02-09T23:36:02.000Z","updated_at":"2025-03-25T03:11:43.000Z","dependencies_parsed_at":"2024-10-31T04:31:03.944Z","dependency_job_id":null,"html_url":"https://github.com/SuperPaintman/the-evolution-of-a-go-programmer","commit_stats":{"total_commits":5,"total_committers":3,"mean_commits":"1.6666666666666667","dds":0.4,"last_synced_commit":"806a4a7b557574616ec0b5718a23f5f69420f76c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuperPaintman%2Fthe-evolution-of-a-go-programmer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuperPaintman%2Fthe-evolution-of-a-go-programmer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuperPaintman%2Fthe-evolution-of-a-go-programmer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuperPaintman%2Fthe-evolution-of-a-go-programmer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SuperPaintman","download_url":"https://codeload.github.com/SuperPaintman/the-evolution-of-a-go-programmer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245984577,"owners_count":20704793,"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":["developer-roadmap","go","go-roadmap","golang","roadmap"],"created_at":"2024-07-31T19:00:50.062Z","updated_at":"2025-03-28T06:31:44.012Z","avatar_url":"https://github.com/SuperPaintman.png","language":"Go","funding_links":[],"categories":["文章","Go","Article","Repositories"],"sub_categories":["组织","To Organize"],"readme":"# The Evolution of a Go Programmer\n\n## Junior Go programmer\n\n```go\npackage fac\n\nfunc Factorial(n int) int {\n\tres := 1\n\n\tfor i := 1; i \u003c= n; i++ {\n\t\tres *= i\n\t}\n\n\treturn res\n}\n```\n\n## Functional Go programmer\n\n```go\npackage fac\n\nfunc Factorial(n int) int {\n\tif n == 0 {\n\t\treturn 1\n\t} else {\n\t\treturn Factorial(n - 1) * n\n\t}\n}\n```\n\n## Generic Go programmer\n\n```go\npackage fac\n\nfunc Factorial(n interface{}) interface{} {\n\tv, valid := n.(int)\n\tif !valid {\n\t\treturn 0\n\t}\n\n\tres := 1\n\n\tfor i := 1; i \u003c= v; i++ {\n\t\tres *= i\n\t}\n\n\treturn res\n}\n```\n\n## Multithread optimized Go programmer\n\n```go\npackage fac\n\nimport \"sync\"\n\nfunc Factorial(n int) int {\n\tvar (\n\t\tleft, right = 1, 1\n\t\twg sync.WaitGroup\n\t)\n\n\twg.Add(2)\n\n\tpivot := n / 2\n\n\tgo func() {\n\t\tfor i := 1; i \u003c pivot; i++ {\n\t\t\tleft *= i\n\t\t}\n\n\t\twg.Done()\n\t}()\n\n\tgo func() {\n\t\tfor i := pivot; i \u003c= n; i++ {\n\t\t\tright *= i\n\t\t}\n\n\t\twg.Done()\n\t}()\n\n\twg.Wait()\n\n\treturn left * right\n}\n```\n\n## Discovered Go patterns\n\n```go\npackage fac\n\nfunc Factorial(n int) \u003c-chan int {\n\tch := make(chan int)\n\n\tgo func() {\n\t\tprev := 1\n\n\t\tfor i := 1; i \u003c= n; i++ {\n\t\t\tv := prev * i\n\n\t\t\tch \u003c- v\n\n\t\t\tprev = v\n\t\t}\n\n\t\tclose(ch)\n\t}()\n\n\treturn ch\n}\n```\n\n## Fix Go weaknesses with mature solutions\n\n```go\npackage fac\n\n/**\n * @see https://en.wikipedia.org/wiki/Factorial\n */\ntype IFactorial interface {\n\tCalculateFactorial() int\n}\n\n// FactorialImpl implements IFactorial.\nvar _ IFactorial = (*FactorialImpl)(nil)\n\n/**\n * Used to find factorial of the n.\n */\ntype FactorialImpl struct {\n\t/**\n\t * The n.\n\t */\n\tn int\n}\n\n/**\n * Constructor of the FactorialImpl.\n *\n * @param n the n.\n */\nfunc NewFactorial(n int) *FactorialImpl {\n\treturn \u0026FactorialImpl{\n\t\tn: n,\n\t}\n}\n\n/**\n * Gets the n to use in factorial function.\n *\n * @return int.\n */\nfunc (this *FactorialImpl) GetN() int {\n\treturn this.n\n}\n\n/**\n * Sets the n to use in factorial function.\n *\n * @param n the n.\n * @return void.\n */\nfunc (this *FactorialImpl) SetN(n int) {\n\tthis.n = n\n}\n\n/**\n * Returns factorial of the n.\n *\n * @todo remove \"if\" statement. Maybe we should use a factory or somthing?\n *\n * @return int.\n */\nfunc (this *FactorialImpl) CalculateFactorial() int {\n\tif this.n == 0 {\n\t\treturn 1\n\t}\n\n\tn := this.n\n\tthis.n = this.n - 1\n\n\treturn this.CalculateFactorial() * n\n}\n```\n\n## Senior Go programmer\n\n```go\npackage fac\n\n// Factorial returns n!.\nfunc Factorial(n int) int {\n\tres := 1\n\n\tfor i := 1; i \u003c= n; i++ {\n\t\tres *= i\n\t}\n\n\treturn res\n}\n```\n\n## Rob Pike\n\n```text\npackage fac\n\n// Factorial returns n!.\nfunc Factorial(n int) int {\n\tres := 1\n\n\tfor i := 1; i \u003c= n; i++ {\n\t\tres *= i\n\t}\n\n\treturn res\n}\n```\n\n\u003e Tribute to the Iavor Diatchki's original page \"[The Evolution of a Programmer](https://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.html)\".\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSuperPaintman%2Fthe-evolution-of-a-go-programmer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSuperPaintman%2Fthe-evolution-of-a-go-programmer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSuperPaintman%2Fthe-evolution-of-a-go-programmer/lists"}