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 Switch mode

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.

Last Post!

alxndr

alxndr

Thanks José!

Where Next?

Trending in Notices Top

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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement