0Pricing
Go Academy · Lesson

The Problem with Many Params

Why constructors get messy.

Why Constructors Get Messy

Go has no default arguments or named parameters. As a type gains options, its constructor signature grows unwieldy and error-prone.

A Constructor Explosion

Imagine a server with host, port, timeout, TLS, and retries. A single constructor needs all of them.

package main

import "fmt"

func NewServer(host string, port, timeout, retries int, tls bool) {
	fmt.Println(host, port, timeout, retries, tls)
}

func main() {
	NewServer("localhost", 8080, 30, 3, false)
}

All lessons in this course

  1. The Problem with Many Params
  2. Option Functions
  3. Building a Flexible API
  4. Defaults and Validation
← Back to Go Academy