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

WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
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
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 I...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
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
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31307 143
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement