Function Basics and Signatures
Parameters, return types, and calling conventions
Function Basics and Signatures is a free Go Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Go Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Defining a Function
In Go, functions are defined with the func keyword:
func greet(name string) string {
return "Hello, " + name
}Parameters and Arguments
Parameters are typed and listed as name type pairs. Multiple parameters of the same type can share the type annotation:
func add(x, y int) int {
return x + y
}
func rect(w, h float64) float64 {
return w * h
}No-Return Functions
Functions that don't return a value simply omit the return type. They implicitly return when execution reaches the end:
func printBanner(title string) {
fmt.Println("=====", title, "======")
}Calling Functions
Call a function by name with parentheses and matching arguments:
result := add(3, 4) // 7
fmt.Println(greet("Go")) // Hello, Go
printBanner("Welcome")Functions as First-Class Values
Functions are first-class in Go — they can be assigned to variables and passed as arguments:
apply := func(n int, f func(int) int) int {
return f(n)
}
double := func(n int) int { return n * 2 }
fmt.Println(apply(5, double)) // 10Function Types
You can define named function types for cleaner signatures:
type Transform func(int) int
func applyAll(n int, fns []Transform) int {
for _, f := range fns {
n = f(n)
}
return n
}Recursive Functions
Go supports recursion. Be mindful of stack depth — Go's goroutine stacks grow dynamically but unbounded recursion still causes a stack overflow:
func factorial(n int) int {
if n <= 1 {
return 1
}
return n * factorial(n-1)
}Function Naming Conventions
Go naming conventions for functions:
- Use
MixedCaps(exported) ormixedCaps(unexported) - Short, action-oriented names:
New,Get,Parse,Write - Avoid
GetXfor simple getters — just useX - Boolean predicates:
IsValid,HasPrefix
init() Function
A special init() function runs automatically when the package is loaded, before main():
- Takes no arguments and returns nothing
- A package can have multiple init() functions
- Use for one-time setup like registering drivers
Function vs Method
A function is not associated with any type. A method has a receiver (covered in Structs & Methods). Both use the func keyword:
// Function
func max(a, b int) int { ... }
// Method
func (c Counter) Value() int { ... }Quick Check
In Go, can a function return multiple values?
Recap: Function Basics
Go functions are expressive and flexible:
func name(params) returnType { }- Parameters of the same type can share their type annotation
- Functions are first-class values
- Define function types for reusable signatures
- Recursion is supported; init() runs on package load
Next: multiple return values in depth.
Frequently asked questions
Is the “Function Basics and Signatures” lesson free?
Yes — the full text of “Function Basics and Signatures” is free to read here on the web, and the Go Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Go Academy course, upgrade to CoddyKit PRO.
What will I learn in “Function Basics and Signatures”?
Parameters, return types, and calling conventions You practise Go Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Go Academy?
No prior experience is required. Go Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Function Basics and Signatures” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Go Academy lesson?
Yes. Every Go Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Function Basics and Signatures
- Multiple Return Values
- Variadic Functions
- defer, Anonymous Functions & Closures