You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The p/demo/avl package has a constructor function NewTree() that returns a pointer *Tree. In may cases this function is not used because the Tree type can also be defined as a non pointer and called without the need of using the constructor function, for example:
package main
import"gno.land/p/demo/avl"funcmain() {
// Non pointer typevartreeA avl.Treeprintln(treeA.Size())
// Pointer typevartreeB*avl.Tree=avl.NewTree()
println(treeB.Size())
}
// Output:// 0// 0
This is currently possible because the underlying Node type that Tree uses is implemented in a way that handles all relevant nil cases with defaults.
Using a non pointer for the Tree type is convenient for example to have tree variables/properties initialized by default without the need to call NewTree().
It might be worth considering if the avl package, which is widely used, should favor and maybe settle for a pointer or non pointer approach by changing the package implementation to that purpose.
The downside of settling in one of the approaches is that it could be a breaking change.
The text was updated successfully, but these errors were encountered:
Description
The
p/demo/avl
package has a constructor functionNewTree()
that returns a pointer*Tree
. In may cases this function is not used because theTree
type can also be defined as a non pointer and called without the need of using the constructor function, for example:This is currently possible because the underlying
Node
type thatTree
uses is implemented in a way that handles all relevantnil
cases with defaults.Using a non pointer for the
Tree
type is convenient for example to have tree variables/properties initialized by default without the need to callNewTree()
.It might be worth considering if the
avl
package, which is widely used, should favor and maybe settle for a pointer or non pointer approach by changing the package implementation to that purpose.The downside of settling in one of the approaches is that it could be a breaking change.
The text was updated successfully, but these errors were encountered: