Hi,

Try to write readable code. If your function modifies any of its 
parameters, make it obvious. Name the function properly and/or write a 
comment. If the function does not modify its parameters, make it obvious 
too. There is no hard rule on this one. Sometimes it makes sense to use 
pure functions and sometimes it doesn't.

Henry

On Monday, March 27, 2023 at 9:05:16 PM UTC+7 nc wrote:

> Hello,
>
> I have found that I have a tendency to try to code non-method funcs in a 
> pure way (functionally speaking - so that the caller will not modify any of 
> its params). I know it is  possible to pass a pointer (or slice or map - is 
> that all of them?) as a function param and then modify it in the called 
> func like is done in https://gobyexample.com/pointers in the zeroptr 
> func, but I have a strong preference to try to do this as rarely as 
> possible and to never modify func params if I can get away with it. However 
> I see some Go code written by others that defintely doesn't agree with this 
> idea and I wonder if perhaps I am misguided. Perhaps it would make sense in 
> another language but doesn't have a place in Go. I am not really sure.
>
> I just wanted to know if anybody had any well-formed opinions on this 
> based on tested experience with Go. Thanks for your help.
>
> - nc

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3848a517-7273-4d4b-9a07-bb5f047497b0n%40googlegroups.com.

Reply via email to