Fl4m3Ph03n1x

Fl4m3Ph03n1x

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?

Showing Posts 1 to 10

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

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.

AstonJ

AstonJ

While it’s true much of Elixir’s syntax was inspired by Ruby, the root of it is almost certainly as @al2o3cr mentioned - not all file systems are case sensitive.

sodapopcan

sodapopcan

Then why is it such a prevalent convention in JavaScript? Also, BEAM files maintain the module name’s casing.

AstonJ

AstonJ

No idea - maybe the creator’s of Ruby wanted to maintain compatibility with those systems?

For file systems that are not case-sensitive these would be the same:

TestsCase
TestScase

Haven’t watched it, but this might be worth a watch:

sodapopcan

sodapopcan

Oh ya, I get the case-sensitive thing, I’m just asking—semi-rhetorically—why JS does if it can cause such problems. When it comes to source file naming, I’ve never been a fan of anything other than all lower snake or kebab case. I have a personal preference for kebab, but since Elixir doesn’t support kebab identifiers, I’m happy with snake.

EDIT: Oops, I think you understood this :grimacing: :sweat_smile:

Fl4m3Ph03n1x

Fl4m3Ph03n1x OP

@ulissesalmeida I hope this post gives you the valuable information you were looking for, all those years back when you were writing the article.

If you found out something else that we don’t know, feel free to let us know!
I hope this thread finds you well and puts that pesky question to an end !

Onor.io

Onor.io

Well something that no one has mentioned to this point; module names are also atoms. Therefore they must start with an uppercase letter. Hence I think it makes some sense to use camel case on module names simply to ease comprehension.

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.

Onor.io

Onor.io

Excellent point. Hairsplitting may be unwelcome in other arenas but in software development it’s essential! :slight_smile:

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews