Fl4m3Ph03n1x

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

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

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

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 :grin:

edit: actually, I don’t think I needed the colon, but … details

sodapopcan

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.

Where Next?

Popular in Questions Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43591 214
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
RisingFromAshes
I've read in another post that it may be possible with a router helper - but I couldn't find an appropriate one, and tbh, I'm still just ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126226 1237
New

We're in Beta

About us Mission Statement