I'm a bit of a noob so bear with me haha Let's say I have two files, 'functions.nim' and 'drawing.nim' The 'functions.nim' file has:
proc putPixel(x, y: int) =
procedureForDrawingAPixel(x, y)
while true:
update()
while the 'drawing.nim file has:
proc update() =
putPixel(187, 278)
I want the 'functions.nim' file to call the 'drawing.nim' file, and the 'drawing.nim' file then calls the 'functions.nim' file to put a pixel on the screen. Can this be done like this, or would I be better off using three files or something?Can't believe i didn't think of shifting the import statement haha
In some languages top-level declarations are unordered, so you wouldn't have to, but in my view simple top down processing makes reading others' code and reasoning about it simpler; better easy to read than easy to write. :)
Btw making modules interdependent you kind of turn them into one big module... You may consider passing procs as arguments instead (like update(putPixel) (if often used, may be wrapped in a template), then the second module can be independent of the first).
Another way is with include and proc definitions. It keeps everything at the top so imports are not buried in the code, though it creates one big module.
proc putPixel*(x, y: int)
include drawing
proc putPixel*(x, y: int) =
echo "hi"
while true:
update()
'drawing.nim' contains:
proc update*() =
putPixel(187, 278)