josevalim

josevalim

Creator of Elixir

Replace 'charlist' by ~c[charlist] in your own codebases

Hello everyone,

We had a discussion on elixir-lang-core about deprecating the use of ‘single quotes’ in Elixir for charlists.

The use of single quotes to specify something that looks like a string but isn’t a string is often a source confusion. This is specially frustrating given the expectation brought from other languages where double and single quoted strings can be used almost interchangeably. Therefore we plan to standardize on the already supported ~c[charlist] syntax instead of single quotes.

The plan is not to deprecate them now but rather in the long term:

  1. Elixir v1.4 will inspect ‘charlist’ as ~c[charlist]
  2. Elixir v1.6 will effectively deprecate ‘charlist’ (to emit warnings)
  3. Elixir v2.0 “who knows when” will remove single-quotes (to fail with syntax error)

However, before we move on, we would love if you could try using the ~c[abc] syntax in your codebase instead of 'abc' and report back your thoughts.

This post is not to discuss the deprecation of single quotes per-se but to collect feedback on the usage of ~c[charlist] in your own codebases. Please give it a try and let us know!

Most Liked

josevalim

josevalim

Creator of Elixir

Over the last weeks folks have been sending results and code samples of the experiment proposed on this thread with many cases where the code got considerably more verbose and less readable, such as integration with Erlang APIs, configurations that expect lists of char lists and so on. For those reasons, we have decided to avoid the change because, for such a big change, the core team should be at least 90% on board it is a positive change and we did not have such consensus anymore. Thanks for pinging back here, I forgot to update this thread.

dimitarvp

dimitarvp

That’s a very good idea and would clear confusion. Kudos. :slight_smile:

Would you also consider adding another more specialized function and allow it in case / cond / etc.? I’m thinking about something like is_charlist/1? Maybe add List.is_printable?/1 as well? And allow is_charlist / List.is_printable? / String.is_printable? in case, cond, when and friends?

Or do you think it’s a better practice not to enforce these in when function declarations but to validate parameters in such a manner first thing in a function?

Apologies for slight off-topic.

alxndr

alxndr

This proposal seems to have been closed quite suddenly. Anyone have an update on why? The discussion thread on the elixir-lang-core group seems to be neutral-to-positive as well.

Where Next?

Popular in Notices Top

josevalim
Hello everyone, We had a discussion on elixir-lang-core about deprecating the use of ‘single quotes’ in Elixir for charlists. The use o...
New
josevalim
Hello everyone, Last year we have announced GenStage and then developed Flow. Our initial plan was to make GenStage part of Elixir. Tha...
New
josevalim
Hi everyone, With the v1.7 release, we have received reports of some dependencies no longer working properly on the new release. Develo...
New
ericmj
We are moving the builds for precompiled versions of Elixir, Erlang/OTP, and Hex itself. These are currently hosted on https://repo.hex.p...
New
josevalim
One common concern about using Elixir libraries is that use SomeModule does not make clear how it impacts the caller. While the goal of u...
New
josevalim
Hi everyone, I have updated Elixir’s wiki page on IDE/Editor support and I am now linking to it from the website. If you know of other ...
New
josevalim
Hi everyone, Elixir v1.19.0-rc.0 included a deprecation of the struct update syntax. However, we will ship with a different warning on E...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
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 Postgres...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement