Back to articles
The Secret Life of Go: Generics

The Secret Life of Go: Generics

via Dev.toAaron Rose

Compile-Time Safety, Type Constraints, and When to Write Code Twice Eleanor is a senior software engineer. Ethan is her junior colleague. They work in a beautiful beaux arts library in Lower Manhattan — the kind of place where coding languages are discussed like poetry. Episode 29 Ethan was staring at a stack trace that had just crashed his local testing environment. panic: interface conversion: interface {} is string, not main.UserStruct Eleanor walked by, pausing behind his chair. "A runtime panic. Let me guess: you pulled something out of the sync.Map we built yesterday and tried to cast it to the wrong type." "I thought I was saving a User struct," Ethan sighed, rubbing his temples. "But somewhere else in the code, I accidentally saved the user's ID as a string under the same key. When I tried to pull it out and assert it as a User , the program blew up." He leaned back. "You warned me that sync.Map uses any and drops type safety. But this feels like a step backward. Am I really su

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles