Skip to content

Instantly share code, notes, and snippets.

@naranyala
Last active July 26, 2025 14:27
Show Gist options
  • Select an option

  • Save naranyala/0d71500a10078c8b141b36c9227f17a6 to your computer and use it in GitHub Desktop.

Select an option

Save naranyala/0d71500a10078c8b141b36c9227f17a6 to your computer and use it in GitHub Desktop.
for the community, a getter and setter implementation in odin programming
package main
import "core:fmt"
Person :: struct {
name: string
}
// Getter and setter procedures
get_name :: proc(p: Person) -> string {
return p.name
}
set_name :: proc(p: ^Person, value: string) -> bool {
if len(value) == 0 {
return false // Validation
}
p.name = value
return true
}
main :: proc() {
person: Person
if set_name(&person, "Alice") {
fmt.println(get_name(person)) // Outputs: Alice
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment