re: In_array alternative for Golang. Searching value in 'map, array, slice'. VIEW POST

FULL DISCUSSION
 

This code is interesting and it translate the concepts from un-typed variables in PHP to Go accurately, but typically I don't see Go programmers structuring programs in this way.

Since Go is statically typed, you want function args and return values to have their types spelled out. Very rarely do I write code where I do not know the types. Generally, using interface{} is like using void* in C, it's a catch-all and a sign that perhaps you need to structure your code or logic differently.

Just sharing these thoughts since you're learning the language. The code you shared is useful and implements an untyped searched well, but I would strongly recommend to avoid using programming idioms from other languages and re-implementing them Go. When I transitioned from C++ to Go I initially tried to do things the C++ way and experienced this myself.

 

Thanks for your thoughts, I'm really appreciated that you're giving me advice. I understand what you're talking about. I'll search for other lang. implementations and try to them Go. I think your way of getting experience is very efficient. Again, thank you.

code of conduct - report abuse