whatyouhide / short_maps

⚠️Retired⚠️ library that provided a ~m sigil for ES6-like map destructuring in Elixir.
https://andrealeopardi.com/posts/a-story-of-regret-and-retiring-a-library-from-hex/
77 stars 5 forks source link

Treat commas as whitespace #5

Closed Havvy closed 8 years ago

Havvy commented 8 years ago

The following should be equivalent, IMO.

whatyouhide commented 8 years ago

The ~m sigil tries to be consistent with the ~w sigil as much as it can, that's why the comma isn't there. Also, the comma is useless from an implementation perspective as variables don't have spaces in them, so whitespace is a good separator. Wdyt?

Havvy commented 8 years ago

(These are my experiences and opinions, not facts of nature.) Variables also are without commas, but when switching from %{a: a, b: b, c: c} to ~m{a b c} (or even from a tuple to a map, I have left commas in by mistake quite a few times for how little I've actually replaced short maps into my code. Treating commas as part of the variable name is a hazard for refactoring. And some people might aesthetically prefer the commas.

whatyouhide commented 8 years ago

They help aesthetically, for sure. However, the whole point of this syntax is too make this pretty common pattern as short and concise as possible. Again, commas would visually help in the ~w sigil as well but they would slightly defeat the purpose of conciseness.

Treating commas as part of the variable name is a hazard for refactoring.

We wouldn't treat commas as part of the variable name though. What I'm very open to do is improving the error message for variables that either have a trailing comma, or other non alphanumeric character in them. Wdyt?

On Tuesday, 6 October 2015, Ryan Scheel notifications@github.com wrote:

(These are my experiences and opinions, not facts of nature.) Variables also are without commas, but when switching from %{a: a, b: b, c: c} to ~m{a b c} (or even from a tuple to a map, I have left commas in by mistake quite a few times for how little I've actually replaced short maps into my code. Treating commas as part of the variable name is a hazard for refactoring. And some people might aesthetically prefer the commas.

— Reply to this email directly or view it on GitHub https://github.com/whatyouhide/short_maps/issues/5#issuecomment-145878735 .

Andrea Leopardi an.leopardi@gmail.com

Havvy commented 8 years ago

Either or sounds good to me. Even if you treat trailing commas the same as whitespace, you would have to make other non-variable characters errors, and if you later decide that commas should be in the same category of whitespace, it's still backwards compatible.

The "whole point of this syntax" is not to make this common pattern as short and concise as possible, but rather to make it more concise by avoiding repetition. Concision at the expense of everything else is usually bad. We want this syntax to still be readable and we also want to make it easy to modify. Changing a ~m{} into %{} and vice versa should be as painless as possible. If one requires commas and the other requires the absence of commas, that makes it more painful.

whatyouhide commented 8 years ago

@Havvy I see your points, but I still stand with a no-comma syntax because of consistency with ~w and because I don't think we're using concision "at the expense of everything else". We can try a different approach :), let's ask the most qualified person I know in this area: @josevalim himself!

Havvy commented 8 years ago

Given lack of consensus, and I doubt @josevalim is going to respond, closing until and if further arguments are provided.