I'm getting confused trying to refactor computation inside a package into 3 stages of pre
, process
and post
.
One idea was to develop 3 new sub-packages with this approach:
The problem is I have to repeat some code in each sub-package as commented here. Also, after refactoring I'm receiving runtime errors which might indicate that the refactor has not been a stable one:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x58 pc=0x88e36e]
goroutine 1 [running]:
projects/printer/app/threed/support/pre.(*ASupportPre).volumeCalc(...)
In C++ you can do whatever you want:
I wonder, in Go, how I can break down computation in my package into 3 stages. Is there a best practice which I might be missing?
My original package:
package support
type ASupport struct {
tris tri.Tris
boundary *boundary.Boundaries
// ...
}
// Functions with `ASupport` as receiver
func (s *ASupport) volumeCalc() {
// ...
}
func (s *ASupport) PutSupport(a Sup) {
// ...
}
// ...
I intend to refactor the functions with *ASupport
type as receiver, into 3 sub-packages of pre
, process
and post
according to the computation stage they belong to.
User contributions licensed under CC BY-SA 3.0