Options other than pointers, regarding code duplication

63 views
Skip to first unread message

Kevin Chadwick

unread,
Jan 28, 2021, 8:21:30 AM1/28/21
to golang-nuts
I have three logging functions that are almost identical.

If I move the identicle code into a function without pointers then there is a
noticeable speed decrease. I know this is premature optimisation as logging
shouldn't happen frequently enough or be that large (hopefully).

That said. I am left wondering aside from code generation steps and copy and
paste (current solution) if I am unaware of any options that might avoid pointer
use, such as:

1./ scoped global, like a Class might provide

2./ macro type instantiation that simply inserts the code at compile time but
without the compiler doing any computations

I assume not, from perusing the spec?

p.s. It's fine if the solution is pointers. Just wondering if I can avoid panic
potential.

jake...@gmail.com

unread,
Jan 28, 2021, 11:18:03 AM1/28/21
to golang-nuts
Perhaps providing some code could be helpful. That way we can better understand what the issues are.  Minimally the function signatures you have now, and the signature of common function you are calling inside them, as well as the definitions of any types being passes. Of course, the full code of before and after would be ideal, if you can share.
Reply all
Reply to author
Forward
0 new messages