josevalim
Convert 'charlists' into ~c"charlists"
Hi everyone,
We are considering deprecating 'charlists' in Elixir in favor of ~c"charlist". In many languages, 'foobar' is equivalent to "foobar", that’s not the case in Elixir and we believe it leads to confusion. If we were to deprecate this functionality, users would get a warning/error upfront about the usage of single-quotes.
The first step in this journey is to change the formatter to rewrite 'charlist' into ~c"charlist". This will basically make the migration painless for most developers.
With this in mind, @sabiwara has submitted an awesome PR that implements this change in the Elixir codebase. Perhaps, more importantly, he has also simulated PRs to important projects to access the impact of this change. Here they are:
- phoenix: charlists_as_sigils · sabiwara/phoenix@75ba56c · GitHub
- ecto: charlists_as_sigils · sabiwara/ecto@aaf55d1 · GitHub
- plug: Comparing elixir-plug:main...sabiwara:check-charlists-as-sigils · elixir-plug/plug · GitHub
- gettext: Comparing elixir-gettext:main...sabiwara:check-charlists-as-sigils · elixir-gettext/gettext · GitHub
- postgrex: Comparing elixir-ecto:master...sabiwara:check-charlists-as-sigils · elixir-ecto/postgrex · GitHub
- phoenix_html: https://github.com/phoenixframework/phoenix_html/compare/master...sabiwara:phoenix_html:check-charlists-as-sigils?expand=1
- mint: Comparing elixir-mint:main...sabiwara:check-charlists-as-sigils · elixir-mint/mint · GitHub
As you can see, the changes are minimal to most projects, including postgrex and mint which integrate with OTP libraries. So from a compatibility point of view, this change is relatively straight-forward.
However, should we go ahead with this change? There would be two reasons for such:
-
If single quotes raised/warned in the future, would that lead to better learning and user experience?
-
If
[97, 98, 99]prints as~c"abc"in IEx instead of'abc', is that more, less, or equally confusing? (let’s assume for now that we will either print one or the other, in order to avoid side-tracking the discussion)
Thoughts are welcome!
Most Liked
benwilson512
I can count on one hand the number of times when I wanted a list of printable ints to be shown as a charlist in the ~7 years I’ve been doing Elixir. Also in that time I’ve answered why it does that countless times to new people and in not one of those cases were they interacting with Erlang and needed it to be printed as text. I think the time has come to legitimately question whether this should still be the default given how easy it is to opt in to the behavior.
Love the change.
olivermt
A thousand times yes, also for noobs trying to speak to erlang libs.
Eiji
Amazing! ![]()
Definitely!
Personally I would like to vote for ~c(abc) instead. This would make many beginners think that ~c is “some kind of function”, so significant % of those should take a look at Kernel documentation at start before asking on forum/slack etc. sigil_c documentation would be then a “core/starting point of understanding the charlists”.
I believe we need to enhance said sigil_c documentation a lot. Even if it would not describes charlists in this @doc it still should point to a separate guide describing “what and why” is it.
Popular in Proposals
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








