If you need to access the field from other modules, then it's literally not private anymore.
If you have specific function that have to work with that private field, then implement it in that common module and have that function exported.
If you want to have read only for that specific field, implement the proc for it like
proc myFieldName(o: TheObject): FieldType =
o.myFieldName
Well, basically, there's no literally should have or shouldn't have when organizing it, just need some sense/reasonable organization.
This is my use case.
# module A
type
Control* = ref object or RootObj
m_text* : string # ( This should be private)
handle* : HWND # ( This can be public)
...
# module B
import A
# here is the implementation of all the methods & properties of Control
proc `text=`*(me : Control, sText : string) =
me.m_text = sText
if me.isCreated :
# change the control text too.
proc `text`*(me : Control) : string =
result = me.m_text
So now, by this setup, user of this type can access m_text. But i want to block that access. And i dont want to mix the implementation code with type declaration code. I need to split as much code as possible. And i dont want to mix the implementation code with type declaration code. I need to split as much code as possible.
In different modules or in different files?
If in different modules, as for now, everything exported are visible to other modules that import it.
If it's only needed in different file, use include statement