Avatar ·

Can I use assert in Go? Or is it evil, as they say about C++?

Hello everyone! I'm a beginner in Go, coming from C++. There I often used assert() to check preconditions and invariants — for example, that a pointer is not nil, that an index is within array bounds, or that an object's state is correct. It was very helpful during debugging. I started writing in Go and noticed that there is no assert function in the standard library. Of course, there is the testing package, but it's only for tests. In production code, I started writing my own checks like: ```go if somePtr == nil { panic("somePtr is nil, this is a bug!") } ``` But a colleague said this is a terrible style, and that in Go it's customary to return errors, not panic. He gave an example from C++, where assert is often criticized because it can be disabled by the NDEBUG macro, leading to hidden bugs. Now I'm confused. On one hand, assert in C++