josevalim
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!
Trending in Proposals
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
olivermt
A thousand times yes, also for noobs trying to speak to erlang libs.
greven
Think this would be a great change for newcomers to the language.
Even though it’s a matter of read the docs it is not consistent with other languages like you said, there is a reason for that but at the same time expected behaviour is good.
Thumbs up from me.
Eiji
Amazing!
Definitely!
Personally I would like to vote for
~c(abc)instead. This would make many beginners think that~cis “some kind of function”, so significant % of those should take a look atKerneldocumentation at start before asking on forum/slack etc.sigil_cdocumentation would be then a “core/starting point of understanding the charlists”.I believe we need to enhance said
sigil_cdocumentation a lot. Even if it would not describescharlistsin this@docit still should point to a separate guide describing “what and why” is it.Sebb
can we then do
?
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.
fuelen
we’ll have
In order to avoid confusion at all, the list of integers should be printed as list of integers. In general, I don’t care. I don’t interact with charlists often.
dimitarvp
I think we should start with
IEx.configure(inspect: [charlists: :as_lists])being the default (as @fuelen seems to be suggesting as well).I vote for the sigil syntax as well –
~c"abc"and~c(abc)should be identical, right?I believe people carry implicit assumptions with them from other tech and that has been visible by the frankly infinite number of times people have come to the forum to ask about why does
[97, 98, 99]show'abc'iniex. So we should piggy-back on those assumptions and have the sigil syntax moving forward.I love the idea.
sergio
The
'foobar' != "foobar"bit me quite a bit when I was learning Elixir. Being explicit about it will be a nice change for newcomers to the language.Having
[97, 98, 99]output to terminal also confused the hell out of me many many times. Seeing~c"abc"in the terminal will be so much better for me and instantly tell me what I’m seeing.I see it as a win/win for newcomers and veterans alike. Fantastic change @josevalim
ityonemo
If I’m not mistaken you could also do
~c'abc'for any (possibly imaginary) person that insists on a head nod to the past. But I think the question is a presentational one and~c(abc)flags stronger in a beginner’s mind that “I might not have done something wrong”, though I do think the best solution is to just do charlists as the number lists. Also very much for prohibiting the use of single quotes (except in sigils) as an error moving forward, though a transitional deprecation warning is probably a good ideajoey_the_snake
It’s a good thing for newcomers who are using charlists by mistake when they don’t want to.
If you aren’t new and want to use charlists it seems slightly more annoying but not the biggest deal.