Sobes.tech
Junior — Middle

Kuidas erinevad programmeerimismeetodid, kui nende nimed algavad suure või väikese tähega?

sobes.tech AI

Vastus AI-lt

In Go (Golang), the capitalization of the first letter of a method or function name determines its visibility:

  • If the name starts with an uppercase letter, the method or function is exported and accessible from other packages.
  • If the name starts with a lowercase letter, the method or function is unexported and only accessible within the package.

For example:

package example

type MyStruct struct {}

func (m MyStruct) ExportedMethod() {}  // accessible from other packages
func (m MyStruct) unexportedMethod() {} // accessible only within the package

This simple rule helps manage scope and encapsulation in Go.