> I do still think that it is reasonable for something like credo to
suggest writing `%{foo: 1}` instead of `%{"foo": 1}` in situations where
the quotes are unnecessary.

I see, I got those reversed, thanks for clarifying. I don't think Elixir
should warn on those cases as that could get in the way of more important
warnings shown by the language. So Credo sounds like the way to go.

> I like the suggestion of the json sigil, except that you loose things
like syntax highlighting and bracket matching in editors.

FWIW, this should be a solvable problem. You can change your editor syntax
highlighting so that everything inside ~j"""...""" is treated as JSON. I
know it is possible on Sublime/TextMate, not sure about the rest. I
remember when I used to write things such as <<-SQL in Ruby's heredocs to
get highlighting inside.


*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D

On Fri, Sep 15, 2017 at 3:07 AM, Allen Madsen <[email protected]>
wrote:

> The first suggestion I made was a bad one. I like the suggestion of the
> json sigil, except that you loose things like syntax highlighting and
> bracket matching in editors. I do still think that it is reasonable for
> something like credo to suggest writing `%{foo: 1}` instead of `%{"foo":
> 1}` in situations where the quotes are unnecessary. I mentioned the problem
> in the context of JSON, but it's more generally a problem of it being easy
> to confuse quoted atoms as strings.
>
> Allen Madsen
> http://www.allenmadsen.com
>
> On Thu, Sep 14, 2017 at 5:46 AM, José Valim <[email protected].
> br> wrote:
>
>> Those are both valid syntaxes. I don't think Elixir nor Credo should
>> warn. If another serialization becomes wide-spread in the future in a way
>> it also causes confusion with Elixir syntax, should we also deprecate that
>> other part of the Elixir syntax? The rationale of why it works in Elixir is
>> because we allow :"such an atom" and keywords keep the same syntax except
>> ":" is used at the end.
>>
>> If you are writing a lot of JSON, maybe one idea is to use a sigil so you
>> can literally write JSON?
>>
>>
>> ~j"""
>> {
>>   json: "this is literally json"
>> }
>> """
>>
>>
>> The json can be converted to a data structure at compile-time if you
>> don't have an interpolation. And if you have interpolation, you can
>> probably change each interpolated argument to encode to json. So you can
>> even do things such as:
>>
>> sub = ~j"""
>> {foo: "bar"}
>> """
>>
>> ~j"""
>> {total: #{sub}}
>> """
>>
>>
>>
>>
>>
>>
>>
>> *José Valim*
>> www.plataformatec.com.br
>> Skype: jv.ptec
>> Founder and Director of R&D
>>
>> On Thu, Sep 14, 2017 at 2:02 AM, Allen Madsen <[email protected]> wrote:
>>
>>> I've thought about this and rather than warning when using trailing
>>> colons on quoted atoms. It could make sense to warn when using quoted atoms
>>> when the characters are valid for a non-quoted atom.
>>>
>>> %{"this": "warns"}
>>> %{"this one": "doesn't"}
>>>
>>> I'm also exploring adding this to credo, in case it doesn't make sense
>>> for Elixir core.
>>>
>>> Allen Madsen
>>> http://www.allenmadsen.com
>>>
>>> On Wed, Sep 13, 2017 at 6:16 PM, Allen Madsen <[email protected]> wrote:
>>>
>>>> At work we deal with a lot of JSON and so it's common to have the
>>>> equivalent of JSON in Elixir. A common problem people on my team have when
>>>> they write out the Elixir structure is that they miss converting trailing
>>>> commas into hash rockets.
>>>>
>>>> They have this:
>>>>
>>>> %{"x": 1}
>>>>
>>>> Instead of:
>>>>
>>>> %{"x" => 1}
>>>>
>>>> Because both look like a string, it's very easy to miss. I'm suggesting
>>>> warning about the latter syntax as it can be a source of errors.
>>>>
>>>> My goal is that it become more obvious that you've made this type of
>>>> error. If people don't like this suggestion, I'd love to hear other ideas
>>>> about ways this problem could be addressed.
>>>>
>>>> --
>>>> 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 [email protected].
>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/elixir-lang-core/14344c22-06a8-42c2-a827-29359a826ad0%40
>>>> googlegroups.com
>>>> <https://groups.google.com/d/msgid/elixir-lang-core/14344c22-06a8-42c2-a827-29359a826ad0%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>>> 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 [email protected].
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/elixir-lang-core/CAK-y3Cv%2B9yb0XwRh9tBNiKBE%3D09RL9m7F2
>>> OXK6pUJxpNRA4%3DFQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3Cv%2B9yb0XwRh9tBNiKBE%3D09RL9m7F2OXK6pUJxpNRA4%3DFQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> 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 [email protected].
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/elixir-lang-core/CAGnRm4JAqPxwr7z6W2tAWgUk%3DEU5hj2LM00t
>> Qii5ymC64AJ1XA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JAqPxwr7z6W2tAWgUk%3DEU5hj2LM00tQii5ymC64AJ1XA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/elixir-lang-core/CAK-y3CuBFYgNG1aG2hGAibbK4Q5M6R-
> grrROHccqjQ31evZP0Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3CuBFYgNG1aG2hGAibbK4Q5M6R-grrROHccqjQ31evZP0Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JbQs-cw%2BZ9heK6XkZPu3FcUy7_eOXfBx27cqfoW5w1FA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to