I love the anchoring system, but it is also slowly driving me insane...

Please tell me:
What is the correct way to deal with Anchors in code?If I do something like this:
widget.leftAnchor.target = widget.rightAnchor.target = contentArea.cachedTransform;
widget.leftAnchor.relative = 0f;
widget.rightAnchor.relative = 1f;
widget.leftAnchor.absolute = 48;
widget.rightAnchor.absolute = -48;
widget.topAnchor.target = widget.bottomAnchor.target = null;
Do I need to do anything else after that? Call ResetAnchors() or anything? It seems every time I work with anchors in code things start getting weird...
PS: The evil, tricky part about the above code is that works correctly ONLY IF that GameObject is NOT active in the inspector. Took me a while to figure that one out...
