My issues is about how I should arrange the files and folders of my source 
code, utilizing Nim's module system. I am just starting with Nim and am coming 
from C++ where I used to duct tape everything together using include statements.

Let's say that my project consists of three main components: a platform layer, 
a game engine layer, and a game logic layer. Not sure if it's relevant, but 
here is some more background on how these layers are interacting with each 
other (very simplified): platform passes input to game -> game asks engine to 
render stuff and playback audio -> engine writes audio and bitmap data to 
buffers for platform layer -> and we go again.

Now my first thought would be to treat those three components as modules. 
Assuming that this makes any sense, how would you suggest to arrange them in 
terms of folders and files? Each of them will be pretty large and certainly 
span across several files for sanity. So I created folders for them:

>   * source
> 

>
>>   * platform
>>   * engine
>>   * game
>> 


I went ahead and created `main.nim` files for every component, and also a file 
`entry.nim` in the root that imports the three modules and provides the main 
loop.

>   * source
> 

>
>>   * entry.nim (imports platform/main, engine/main, game/main)
>>   * platform
>> 

>>
>>>   * main.nim (includes other platform files)
>>>   * other platform files
>>> 

>> 
>>   * engine
>> 

>>
>>>   * main.nim (includes other engine files)
>>>   * other engine files
>>> 

>> 
>>   * game
>> 

>>
>>>   * main.nim (includes other game files)
>>>   * other game files
>>> 


I kind of imagine the main.nim files like index files a web page or entry 
points for modules in an web CMS. Apparently though, the creators of the Nim 
module system had something very different in mind since I had to learn that it 
is not possible to import several modules of the same file name, even when 
assigning different names to them using the `as` keyword.

so here's another approach:

>   * source
> 

>
>>   * entry.nim (imports platform.nim, engine.nim, game.nim)
>>   * platform.nim (includes platform files)
>>   * engine.nim (includes engine files)
>>   * game.nim (includes game files)
>>   * platform
>> 

>>
>>>   * platform files
>>> 

>> 
>>   * engine
>> 

>>
>>>   * engine files
>>> 

>> 
>>   * game
>> 

>>
>>>   * engine files
>>> 


However, I really dislike this approach since now, I have two items of equal 
name (one file and one folder) for every component in the root of my source. I 
feel like that this will get very messy in the future and it just looks 
confusing as it messes up the entire idea behind folders in a file system.

There's one more solution that comes to mind, but that one to me is even uglier 
than the previous one:

>   * source
> 

>
>>   * entry.nim (imports platform/platform, engine/engine, game/game)
>>   * platform
>> 

>>
>>>   * platform.nim (includes other platform files)
>>>   * other platform files
>>> 

>> 
>>   * engine
>> 

>>
>>>   * engine.nim (includes other engine files)
>>>   * other engine files
>>> 

>> 
>>   * game
>> 

>>
>>>   * game.nim (includes other game files)
>>>   * other game files
>>> 


I cannot have something like `import game/game` in my source. That just goes 
against every fiber of my being. The same goes for `import gameModule/game` or 
`import game/main1`, `import engine/main2`, ...

**TL;DR:** When a large module is split into several files that are grouped by 
using a folder that has the name of that module, how should I call the "entry 
point" of that module without using a generic name and without re-using the 
name that's already been given to its containing folder? I am clueless. Have I 
maybe utterly failed to grasp the module system to fail at something so trivial?

Reply via email to