Fl4m3Ph03n1x
Why are module names in Elixir UpperCamelCase, while the file names are snake_case?
Background
I have recently found an old article about Elixir, where the author explains some conventions about Elixir, and in specific, naming and structural conventions for Phoenix projects.
In this article the author mentions:
Module names in Elixir follow the UpperCamelCase convention. (…) and the file name has the same name as the module but uses snake_case as a convention. Why? I don’t know.
(emphasis added by me)
The author mentions the possibility of a technical reason for this. I am unaware of what technical reason could exist, and my belief is that this was mostly a style decision (needs confirmation).
Question
So the question here is the title:
Why are module names in Elixir UpperCamelCase, while the file names are snake_case?
The article is from 2022, so there is a good chance someone (maybe even the author) figured this one out. But I couldn’t find anything regarding this, and curiosity did get the best of me.
- Why do you think this is the case?
- What technical reasoning do you think could be behind this?
Marked As Solved
al2o3cr
Not all filesystems are case-sensitive, so trying to camel-case there will give you files with unwieldylongnameswithoutanypunctuation
I suspect that constraint in Elixir may have been more about “why are Ruby files named like this” and then migrated over, but I don’t have any evidence for that.
Also Liked
sodapopcan
It’s just convention. This is how Ruby does it which of course inspired a lot of Elixir conventions. Also, Erlang modules names are conventionally snake case (and at least must start with a lowercase letter). There is no technical reason, but one thing to keep in mind is that file != module in Elixir, ie, you can have multiple modules in a single file. I often have some files that aren’t named after any of the contained modules, like errors.ex. For me (and this is just me), using camel case would suggest that the file is the module whereas snake case more correctly suggests there is no such correlation
gregvaughn
Hehe. I once tweeted some “evil” Elixir in which I did defmodule :false do. Alas, someone reported it as a bug and it got fixed ![]()
edit: actually, I don’t think I needed the colon, but … details
sodapopcan
Nitpick for clarity: module names are aliases which is why they must start with an uppcase letter. And to nitpick myself, of course you can use straight up atoms as well, ie defmodule :foo, do: (). But yes, always atoms.







