Deprecate 'single quotes for char lists'

482 views
Skip to first unread message

José Valim

unread,
Sep 22, 2016, 1:04:07 PM9/22/16
to elixir-l...@googlegroups.com
Hello everyone,

I have mentioned a couple times we would start a discussion for deprecating 'single quotes as char lists' from the language.

The use of single quotes to specify something that looks like a string but isn't really 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.

We already have a quite decent way of writing char lists, which is by using sigils: ~c"foo". For new developers, printing a char list as a ~c"foo" will likely give them better clues the type is not the same as "foo".

Of course we should not drive decisions based purely on the getting started experience but I believe the sigil approach will be clearer for beginner and advanced programmers alike.

The plan is not to deprecate them now but rather in the long term. Something like this:

1. Elixir v1.4 will inspect 'abc' as ~c"abc"
2. Elixir v1.6 will effectively deprecate 'abc'
3. Elixir v2.0 "who knows when" will remove single-quotes

Thoughts?

José Valim
Skype: jv.ptec
Founder and Director of R&D

Josh Adams

unread,
Sep 22, 2016, 1:14:10 PM9/22/16
to elixir-l...@googlegroups.com


> 1. Elixir v1.4 will inspect 'abc' as ~c"abc"
> 2. Elixir v1.6 will effectively deprecate 'abc'
> 3. Elixir v2.0 "who knows when" will remove single-quotes
>
> Thoughts?

I love it.

Paul Schoenfelder

unread,
Sep 22, 2016, 1:26:16 PM9/22/16
to elixir-l...@googlegroups.com
At first blush I'm not a fan, I'm not sure that the use of ~c"foo" will be any less confusing than 'foo' - it will still look like a string, and behave like a list, but now with a sigil by it which new Elixir programmers will not remember and will need to look up. I also suspect this means there will be a great deal of code which needs to be updated to handle this deprecation as well. Another question I have is what happens to single quotes? Will they be used for some other purpose once removed? Reserved?

To be honest, I didn't even know about ~c"foo", I've never used it, and haven't seen it in the wild. If you hadn't just now explained what it was, I would've had to go look it up. One of the very first things in the Elixir docs is the discussion of data types, especially string-like ones - if one doesn't read those docs, the confusion is going to occur regardless of what syntax is used to express charlists.

To me it seems like a huge change with little to no real benefit. Of course, that's just my perspective/opinion, maybe the community at large disagrees with that sentiment.

Paul



--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BX9q9SAZjj4otmbjXRBhJyvQk0r%3D8pERwtrFcAczGNPQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Jim Freeze

unread,
Sep 22, 2016, 1:39:36 PM9/22/16
to elixir-l...@googlegroups.com
I've never had a problem with distinguishing between 'foo' and "foo", even as a newby.

But, my question is, when '' is deprecated, will that mean that 'foo' is a syntax error?

Jim


On Thu, Sep 22, 2016 at 12:03 PM, José Valim <jose....@plataformatec.com.br> wrote:

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BX9q9SAZjj4otmbjXRBhJyvQk0r%3D8pERwtrFcAczGNPQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Dr. Jim Freeze, Ph.D.

Peter Hamilton

unread,
Sep 22, 2016, 1:49:28 PM9/22/16
to elixir-l...@googlegroups.com
I +1 the problem as being significant. The number of bug reports I've tackled where someone used single quotes instead of double quotes is quite high. Most often, it's heavily obscured because they passed a charlist into Poison.encode! and the remote service (or in my case, DB) complained about an incorrect schema. Quite obscure.

I'm neutral about the sigil being the first class way to do charlists.

I think we need to settle on what single quotes mean after the change. Are they a syntax error? Do we adopt the practice of it being a string without interpolation?

On Thu, Sep 22, 2016 at 10:39 AM Jim Freeze <jimf...@gmail.com> wrote:
I've never had a problem with distinguishing between 'foo' and "foo", even as a newby.

But, my question is, when '' is deprecated, will that mean that 'foo' is a syntax error?

Jim


On Thu, Sep 22, 2016 at 12:03 PM, José Valim <jose....@plataformatec.com.br> wrote:
Hello everyone,

I have mentioned a couple times we would start a discussion for deprecating 'single quotes as char lists' from the language.

The use of single quotes to specify something that looks like a string but isn't really 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.

We already have a quite decent way of writing char lists, which is by using sigils: ~c"foo". For new developers, printing a char list as a ~c"foo" will likely give them better clues the type is not the same as "foo".

Of course we should not drive decisions based purely on the getting started experience but I believe the sigil approach will be clearer for beginner and advanced programmers alike.

The plan is not to deprecate them now but rather in the long term. Something like this:

1. Elixir v1.4 will inspect 'abc' as ~c"abc"
2. Elixir v1.6 will effectively deprecate 'abc'
3. Elixir v2.0 "who knows when" will remove single-quotes

Thoughts?

José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.



--
Dr. Jim Freeze, Ph.D.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAP1mN_xgfFm2Hueem407k994wAGnCvEupWRkOey8SCJnGPT6Jg%40mail.gmail.com.

Andrew Timberlake

unread,
Sep 22, 2016, 1:53:24 PM9/22/16
to elixir-l...@googlegroups.com
I like this. While I've not battled to identify the difference since beginning with Elixir, muscle memory from other languages means I regularly have to stop myself typing 'strings'.

I hope single quotes will be used for strings alongside double quotes. Is that part of this proposal?

Andrew
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAP1mN_xgfFm2Hueem407k994wAGnCvEupWRkOey8SCJnGPT6Jg%40mail.gmail.com.

OvermindDL1

unread,
Sep 22, 2016, 2:10:12 PM9/22/16
to elixir-lang-core, jose....@plataformatec.com.br
As someone who uses charlists extensively for erlang integration I would prefer them to stay, however I understand that a lot of programmers coming from poorly made languages like javascript do expect 'string' to be a string just like "string".  However, from a C++ perspective a 'string' is expected to be an 'array of characters' (though highly limited in length), which is similar to a 'list of characters' of how it is now.

For purely ease-of-use for newbie programmers coming from web languages, it might be best to deprecate it and just use ~c.

But from lower level languages like C++ and for integration with erlang I do prefer 'string', plus it is not hard for a half-decent IDE to colorize "string" and 'string' differently like atom does (teal for "string", blue for 'string' for me).

Mikhail

unread,
Sep 22, 2016, 2:37:08 PM9/22/16
to elixir-lang-core, jose....@plataformatec.com.br
I like how it works for now, but of course there is the problem for newbies (as for OvermindDL1 there was no problem for me on earlier stage). Also I agree with argument that ~c will not be clear enough to remove confusion.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Sincerely,
Mikhail S. Pabalavets

José Valim

unread,
Sep 22, 2016, 3:13:12 PM9/22/16
to elixir-l...@googlegroups.com
Single quotes will become a syntax error in Elixir 2.0.

We need to consider two scenarios here: reading code and writing code.

I believe that when someone reads ~c"" for the first time compared to '', the sigil version will be more foreign, while the single quotes is more likely to be assumed to be *something*. I am not sure one experience is necessarily better than the other.

However, when it comes to writing, I believe the ~c"" version will be less confusing. There is very little chance someone will write ~c"" meaning a string by mistake. Specially if single quotes raise a syntax error in the future. And they are both learnable syntaxes, you need to learn what they mean.

For those who are skeptical because they use single quotes extensively, I have one suggestion: try a change in your project where you replace single quotes by the sigil, give it a week and let us know how it goes. I have done it in a couple of my projects already and I was pleased with the results.

Thanks everyone for the feedback so far!


--

Allen Madsen

unread,
Sep 22, 2016, 10:04:47 PM9/22/16
to elixir-l...@googlegroups.com
+1 from me. When I teach people Elixir, I skip over char lists. By the
time they need to use them, they're typically at the point that
they're mentally able to understand them without being overloaded.
Allen Madsen
http://www.allenmadsen.com
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elixir-lang-co...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JNZ3x9ELz7NQaTNjp_wdMonv0%2BF2H4_Td%2BiGyLjbkHeg%40mail.gmail.com.

Pedro Medeiros

unread,
Sep 23, 2016, 9:21:49 AM9/23/16
to elixir-l...@googlegroups.com
I liked the proposal overall single quotes is confusing to explain to newbies and replace all I have for sigils is easy enough. But all single quotes on 2.0 will be syntax error? even single char String, this is not a good time to implements something similar to other languages where single quotes represents a single char not a String.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3Ctc9upBe6xO6iZKVSjnX%3DbvhgsNc%3D1HfPb_jQi_dLHL4A%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Pedro Henrique de Souza Medeiros
----------------------------------
Cel: +55 (61) 9197-0993
Email: pedr...@gmail.com

Beautiful is better than ugly,
Explicit is better than implicit,
Simple is better than complex,
Complex is better than complicated.

The Zen of Python, by Tim Peters

Bagu Alexandru Bogdan

unread,
Sep 23, 2016, 9:40:02 AM9/23/16
to elixir-lang-core, jose....@plataformatec.com.br
As new elixir developer I like single quotes, you can find them in many languages like Java, C++ and they are like in elixir. For example I've used them to call :httpc from erlang.
If you do this you will break backward compatibility, you will split elixir into parts < version2.0 and >version2.0 like AngularJS do with <1.5 and 2.0.

eksperimental

unread,
Sep 23, 2016, 10:06:11 AM9/23/16
to elixir-l...@googlegroups.com
Jose,
I will be good to hear what other major syntax changes are expected to happen in 2.0
Or any other changes.
thank you,
> > *José Valim*

José Valim

unread,
Sep 23, 2016, 11:07:24 AM9/23/16
to elixir-l...@googlegroups.com
Anything currently planned for 2.0 is with the proper milestone in the issues tracker.

2.0 is still a long time to come but I expect the main goal behind 2.0 is to simply remove functionality that has been deprecated in the past. So any code running on the latest 1.x version should run on 2.0 without any change. So I don't expect large migration woes.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/20160923210603.67c79cf8.eksperimental%40autistici.org.

For more options, visit https://groups.google.com/d/optout.


--


José Valim

Onorio Catenacci

unread,
Sep 23, 2016, 11:28:24 AM9/23/16
to elixir-lang-core, jose....@plataformatec.com.br
This is a great point José i. e. reading code vs. writing code.

When I'm writing code I never expect ' to behave the same as ".  I guess it's just years of software development that have conditioned me to be surprised if they're interchangeable in a language.

But when reading code it can be easy to conflate one with the other because there's not a lot of psychological distance between ' and " (and heaven help us with languages that use ` as well).  So I think from the standpoint of making the code less error-prone under maintenance there's a good argument to be made for forcing people to use ~c.  It will make the distinction more obvious for those reading the code later on.  Things like this and slashed zeros in programming fonts are small things but they can make a lot of difference to maintenance developers. 

oc

Parker Selbert

unread,
Sep 23, 2016, 11:43:37 AM9/23/16
to elixir-l...@googlegroups.com
Ever since getting involved in Elixir I have been relieved that there isn't any debate between ' and ", or remembering which supports interpolation. Learning the distinction between binaries and charlists is important when it comes to interfacing with Erlang modules, but that is something you do after you've learned the basic syntax of Elixir.

Writing ~c"mycharlist" is precisely as verbose as <<mybinary>> would be in Erlang, but much less common in day to day elixir.

I'm fully in favor of the change!

— Parker
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

Drew Olson

unread,
Sep 23, 2016, 12:13:02 PM9/23/16
to elixir-l...@googlegroups.com
This change sounds great, I am very much in favor of it.

To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/1474645407.795782.735004081.047484B9%40webmail.messagingengine.com.

Tallak Tveide

unread,
Sep 23, 2016, 12:39:40 PM9/23/16
to elixir-lang-core, jose....@plataformatec.com.br
You have my vote.

Never used single tick lists much, and they were confusing to me, much due to baggage from Ruby/Perl where they are all strings. Making the syntax more explicit makes sense.

Tallak

Paul Clegg

unread,
Sep 23, 2016, 12:54:30 PM9/23/16
to elixir-l...@googlegroups.com
I have mixed feelings.

On the one hand, it's definitely a bit of an oddity that single quotes and double quotes don't both result in strings, like in most languages, so it's definitely going to lead to rookie mistakes.

On the other hand, it's a pretty significant change to the language, AND, consider that even in Ruby, there *are* differences between single and double quotes -- Double quotes will scan for interpretation, but single quotes don't:

2.2.1 :001 > x = "foo"
 => "foo"
2.2.1 :002 > puts "#{x}"
foo
 => nil
2.2.1 :003 > puts '#{x}'
#{x}
 => nil

So even though they both result in String objects, they don't actually act the same -- which is also true for Elixir/Erlang, except that the differences are more noticeable because the actual data is a different type in the end.

I'd be inclined to leave it as-is, I think, and accept it's just one of those things that makes Elixir different.  The transition would be painful anyway:  If you make single quotes errors, all that existing code could suddenly be incompatible, although easily fixed with new versions -- but that means software dependent on OLD versions would either not be able to upgrade or would be forced to move to new versions.

If you just turn single quotes into strings going forward, you're going to have weird unexpected bugs in that old code where it's expecting charlists and suddenly starts getting bitstrings.

I'd vote -1, I guess.  Might've been nice to have worked this out at the very beginning, but it feels like it might be too late to be worthwhile.

...Paul





--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.

Chris Keele

unread,
Sep 23, 2016, 1:17:09 PM9/23/16
to elixir-lang-core, jose....@plataformatec.com.br
I have no strong opinions on this–although I do hope that useful ' character will eventually be reclaimed for some purpose. I assume inspecting 'abc' as ~c"abc" implies that the usual newcomer confusion of inspecting an integer list and seeing a 'string' will be a somewhat more searchable problem, which is nice.

I did want to observe that, now that I know you can create charlists with sigils, I'll probably never use ' again, because to me ~c[foobar] is much more representative of the underlying data structure. Perhaps this could also be how it inspects, to enforce the 'list' connotation?

Louis Pilfold

unread,
Sep 23, 2016, 1:23:45 PM9/23/16
to elixir-l...@googlegroups.com, José Valim

Hey

I'm +1 so long as single quotes are not then used for strings. I'd much rather avoid disagreements about which style of string syntax to use.

Cheers,
Louis


On 23 Sep 2016 18:17, "Chris Keele" <d...@chriskeele.com> wrote:
I have no strong opinions on this–although I do hope that useful ' character will eventually be reclaimed for some purpose. I assume inspecting 'abc' as ~c"abc" implies that the usual newcomer confusion of inspecting an integer list and seeing a 'string' will be a somewhat more searchable problem, which is nice.

I did want to observe that, now that I know you can create charlists with sigils, I'll probably never use ' again, because to me ~c[foobar] is much more representative of the underlying data structure. Perhaps this could also be how it inspects, to enforce the 'list' connotation?

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.

OvermindDL1

unread,
Sep 23, 2016, 1:40:01 PM9/23/16
to elixir-lang-core, jose....@plataformatec.com.br
Hmm, I quite like that, I wonder how `~[foobar]` would work too...

Peter Hamilton

unread,
Sep 23, 2016, 2:08:46 PM9/23/16
to elixir-lang-core, jose....@plataformatec.com.br
We could also reclaim ' as a macro quote syntax. Just a thought.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/af9fc876-6b66-460a-95bf-b5e188109c95%40googlegroups.com.

Chris Keele

unread,
Sep 23, 2016, 2:22:02 PM9/23/16
to elixir-l...@googlegroups.com

I wonder how ~[foobar] would work

In Ruby and Elixir I always try to take advantage of the flexible sigil delimiter syntax to hint at types: [, ] for arrays, " for strings, | for code and multiline strings like SQL, and {, } for nonliterals like Regex and Times.

We could also reclaim ’ as a macro quote syntax.

Haha, I thought of that but feared it would cause even more newcomer confusion. ;D



-- 
Chris Keele
Web Developer
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-core/_pAjPEayLLI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAOMhEnxdEaHsb%3DnSj7tqw03gz1q5KmJxyHKmSwoyG9OZHPSCww%40mail.gmail.com.

Thomas Depierre

unread,
Sep 27, 2016, 8:43:07 AM9/27/16
to elixir-lang-core, jose....@plataformatec.com.br
Hello :)

I am not a core committer, but i deal with a lot of newcomers. While i completely agree that the single quote vs double quote is a problem and i would like to have better visibility, i would like to point that Sigils in general are really really hard to use, understand and keep in mind for newcomers. They are not intuitive, they are really cryptic and they are made of multiple symbols. Just like regexp are hard to read, Sigils are hard to read for most newcomers.

I do not know if there is a good solution to the problem and a good syntax to explicit charlists. But i would like everyone to think about another solution than sigils. They make code harder to read in general.

alisdair sullivan

unread,
Sep 27, 2016, 9:06:06 AM9/27/16
to elixir-lang-core
i also don't have a better proposal but find sigils terrible for discovery, advertising intent and ergonomics. unless you have a deep perl/ruby background sigils are utterly alien

Onorio Catenacci

unread,
Sep 27, 2016, 1:51:31 PM9/27/16
to elixir-lang-core, jose....@plataformatec.com.br
Hi Thomas,

I'm tempted to quote that old saw about the only intuitive interface being the one where we first get food from; we have to learn everything else after that first food source.

I mean there are several places in Elixir code where it's not exactly newbie-friendly.  I can't tell you how many times uppercase vs. lowercase tripped me up when I started with Elixir.  And I've been writing software for years. 

I don't think of sigils as being any less newbie-friendly than anything else in Elixir.  And I don't think they're that much less "intuitive" than any other mechanism I've ever seen for identifying a block of text for special handling. I hate the word "intuitive" because it's extremely subjective but I can't think of a better way to express the thought.   

Just my opinion obviously.

oc

Chris Keele

unread,
Sep 27, 2016, 2:06:15 PM9/27/16
to elixir-l...@googlegroups.com

I’m inclined to agree: sigils are just another tool. I think there’s a very happy path for discovery here, too:

  • Newcomer happily codes Elixir with excellent String support
  • They eventually run in to an API that requires char lists (probably not early on)
  • They google the error they received and educate themselves about what char lists are, and why they exist
  • They immediately find and use String.to_charlist
  • They eventually notice that this new data structure inspects as a sigil in console
  • They look into it and discover the utility of sigils if they haven’t yet in their journey

It’s the same sort of surprise they get today when they notice a list of integers inspecting oddly, really, but more of a happy accident rather than confusing one.

José Valim

unread,
Sep 27, 2016, 2:09:34 PM9/27/16
to elixir-l...@googlegroups.com

It’s the same sort of surprise they get today when they notice a list of integers inspecting oddly, really, but more of a happy accident rather than confusing one.

The majority of times though those have been described as a confusing occurrence and I am not convinced 'foo' is any better or worse than ~c[foo]. 'foo' may cause them to think it is a string, which is wrong, while ~c[foo] will likely leave them more clueless. One of the things we could do is to make sure "h ~c[foo]" in IEx prints the proper documentation helper too.

eksperimental

unread,
Sep 27, 2016, 4:47:20 PM9/27/16
to elixir-l...@googlegroups.com
On Tue, 27 Sep 2016 20:09:09 +0200
José Valim <jose....@plataformatec.com.br> wrote:

> > One of the things we
> could do is to make sure "h ~c[foo]" in IEx prints the proper documentation
> helper too.


I came to comment this very same thing, and I'm glad to see your message.
the other place is ExDoc, Searching for ~c[] should lead somehow (I don't know how we can do this)
to the "sigil_" function

José Valim

unread,
Sep 27, 2016, 4:57:12 PM9/27/16
to elixir-l...@googlegroups.com
I would also like to add that the first step on all of this is to change inspect and the docs to use ~c[] on v1.4. The deprecation of 'foo' should come on v1.6, which is at least one year later. This means we have at least one year to collect feedback on those changes. If we end up believing they are not the way to go, we will simply not deprecate it.

Other than that, did anyone try replacing 'foo' by ~c[foo] in their projects? How did it go?
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--

Booker Bense

unread,
Sep 27, 2016, 9:14:01 PM9/27/16
to elixir-lang-core, jose....@plataformatec.com.br


On Tuesday, September 27, 2016 at 1:57:12 PM UTC-7, José Valim wrote:
I would also like to add that the first step on all of this is to change inspect and the docs to use ~c[] on v1.4. The deprecation of 'foo' should come on v1.6, which is at least one year later. This means we have at least one year to collect feedback on those changes. If we end up believing they are not the way to go, we will simply not deprecate it.


How is converting inspect to use ~c[] going to interact with Erlang error messages? 

- Booker C. Bense 

José Valim

unread,
Sep 28, 2016, 2:48:28 AM9/28/16
to Booker Bense, elixir-lang-core
Same way as today except they will be ~c[error] instead of 'error'.

Bagu Alexandru Bogdan

unread,
Sep 28, 2016, 3:01:02 AM9/28/16
to elixir-lang-core, jose....@plataformatec.com.br
Hi,

This is a little bit tricky when you want to use string interpolation with the syntax above, but I start to like it :)

iex> a="testing"
"testing"

iex> ~c(a)     
'a'
iex> ~c[a]
'a'

iex> ~c[#{a}]
'testing'
iex> ~c(#{a})
'testing'

iex> to_charlist(a)
'testing'





On Thursday, 22 September 2016 20:04:07 UTC+3, José Valim wrote:
Hello everyone,

I have mentioned a couple times we would start a discussion for deprecating 'single quotes as char lists' from the language.

The use of single quotes to specify something that looks like a string but isn't really 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.

We already have a quite decent way of writing char lists, which is by using sigils: ~c"foo". For new developers, printing a char list as a ~c"foo" will likely give them better clues the type is not the same as "foo".

Of course we should not drive decisions based purely on the getting started experience but I believe the sigil approach will be clearer for beginner and advanced programmers alike.

The plan is not to deprecate them now but rather in the long term. Something like this:

1. Elixir v1.4 will inspect 'abc' as ~c"abc"
2. Elixir v1.6 will effectively deprecate 'abc'
3. Elixir v2.0 "who knows when" will remove single-quotes

Thoughts?

Brian Bugh

unread,
Oct 1, 2016, 1:18:11 PM10/1/16
to elixir-lang-core, jose....@plataformatec.com.br
I am a programming teacher and I think Elixir's string handling in general are a bit complex for beginners. I'm in favor of simplifying it where possible!

I have been playing with ~c[Hello] since this thread came up and I am liking it a lot. It's clear that it's a shortcut for making a character list when expressed with []. I tried out ~c"Hello" and didn't like it. I realize that they're the same behind the scenes, but the cognitive signaling of ~c[] as a shortcut to a list is correct while ~c"" as a shortcut to a string is not, at least on the surface. How will inspect work with the sigil? Will it result in a list of integers or as a sigil? If sigil, I'm definitely a fan of ~c[]

iex(1)> ~c[AGCT]
[65, 67, 71, 84]  # this one?

iex(2)> ~c"AGCT"
~c[ACGT]          # or this?


The only thing I don't like about sigils it's harder to type. On that note, I made an Atom snippet to make trying this out easier with c[<tab>, so I'm going to try to never type single quotes again.

'.source.elixir':
 
'charlist':
   
'prefix': 'c['
   
'body': '~c[$1]$2'

Cheers!

-Brian
Reply all
Reply to author
Forward
0 new messages