I have been studying the scenic code and have a question about the module naming convention.
Here’s my problem - I quickly discovered that the first module to be called was MyApp
so I wondered where the code was. It happens to be in a file called my_app.ex
- this then supplies a module name MyApp.Sensor.Supervisor
so I thought to myself “where can I find this code” – the answer is in a module lib/sensors/supervisors.ex
(the name changed from MyApp
to my_app
seems strange – file names are UTF8 so I don’t see why camel case files names are not used) keeping the file and module names identical seems to be fairly common in many languages …
Now lib/sensors/supervisors.ex
just says:
defmodule MyApp.Sensor.Supervisor do
…
end
In other words it defines a single module MyApp.Sensor.Supervisor
.
So now I wonder “is this a local convention or a global convention?”
In Erlang module names and file names are exactly the same, that is the module xyz
will always be found in a file xyz.erl
this makes finding module code (if you know the name) very easy - also since module names are unique we can put all the modules in the same directory (people tend not to do this - but I do, since it makes the problem of deciding a directory name go away).
If a .ex
file contains a single module definition I don’t really understand why the file name should not be exactly the same as the module name. If this were the case finding where the code is can be done with a simple find
command.
In the scenic case the names differ - firstly some CamelCase stuff happens and some pluralisation MyApp.Sensor.XXX
is in a directory called lib/sensors/XXX.ex
(note the plural) – is this a local convention or a widely adopted practise? Had there been only one sensor would the directory been called lib/sensor
and the plural s dropped?
If the conventions here are widely used then where are they documented?
Cheers