Live data from Hacker News

Show HN: es6_maps, new Elixir syntax feature via runtime compiler hacking

github.com

11–20 of 31 posts

Re: Show HN: es6_maps, new Elixir syntax feature via runtime compiler hacking

#11
post #5
post #3

Earlier quoted context omitted.

> I'm sick of having to type everything twice, like e.g. `%{foobar: foobar}` I'm actually very confused by this use case. How often do you have to do that? Fill a map with kv tuples where keys and values have the exact same value?

This pattern appears frequently in just about all programming languages. I’ve written a lot of JS and Python, and a moderate amount of Elixir, and this pattern crops up quite often. Usually it’s a side effect of complex scopes with several layers of function calls. Honestly I’m a little surprised you haven’t seen this pattern. The only times it wouldn’t be used are when people rename variables, which is frankly a pra…

JS and python are just about all programming languages?

I'm not trying to be snarky, but e.g. I haven't seen it in Go, F# and Rust, some languages where I have at least seen _some_ code. I also don't remember a similar pattern in Java, C# and C nor PHP or Dart, but I will readily admit that it's I haven't coded in any of these in the last two years, so I might be a bit out of touch and I'm not super proficient in all those languages

Re: Show HN: es6_maps, new Elixir syntax feature via runtime compiler hacking

#12
post #5

Earlier quoted context omitted.

This pattern appears frequently in just about all programming languages. I’ve written a lot of JS and Python, and a moderate amount of Elixir, and this pattern crops up quite often. Usually it’s a side effect of complex scopes with several layers of function calls. Honestly I’m a little surprised you haven’t seen this pattern. The only times it wouldn’t be used are when people rename variables, which is frankly a pra…

JS and python are just about all programming languages? I'm not trying to be snarky, but e.g. I haven't seen it in Go, F# and Rust, some languages where I have at least seen _some_ code. I also don't remember a similar pattern in Java, C# and C nor PHP or Dart, but I will readily admit that it's I haven't coded in any of these in the last two years, so I might be a bit out of touch and I'm not super proficient in all…

Go, and F# do almost all positional arguments. I think Rust too. Java, C#, C, PHP are also positional only or 99% of the time. I assume Dart too.

We are talking named/keyword/etc.

Personally I find positional arguments to be an anti-pattern in all but a very specific set of circumstances.

Re: Show HN: es6_maps, new Elixir syntax feature via runtime compiler hacking

#13
post #8

This was done previously with the `short_maps` library, which the author—a member of the Elixir core team—eventually retired and archived due to regrets from the undesirable impacts on clarity. https://github.com/whatyouhide/short_maps https://andrealeopardi.com/posts/a-story-of-regret-and-retir...

That's quite surprising to me. As someone who writes a lot of Javascript, I usually find it easiest to read with this syntax than without it, and I generally recommend to my team that they use the shorthand where they can. This is because the meaning is clear and well-known, and being concise (while still being clear) is very valuable.

I wonder what specifically the original author found made it more difficult to read. Was it unfamiliarity? They allude to some confusion between sigils and strings, so I wonder if the issue was partly an Elixir-specific one.

Re: Show HN: es6_maps, new Elixir syntax feature via runtime compiler hacking

#14
post #8

This was done previously with the `short_maps` library, which the author—a member of the Elixir core team—eventually retired and archived due to regrets from the undesirable impacts on clarity. https://github.com/whatyouhide/short_maps https://andrealeopardi.com/posts/a-story-of-regret-and-retir...

I really don’t understand why some people are so against this as a language feature. I get that the community tries to stay away from “magic” but where is the line between magic and convenient syntactic sugar.

For example keyword lists as the last argument to a function don’t need brackets, and keyword lists are really lists of tuples where the first item is an atom. I feel like those two things are in some ways less obvious and more magical than this map shorthand.

Re: Show HN: es6_maps, new Elixir syntax feature via runtime compiler hacking

#15

I personally don’t think this is a good idea, and I think the formatter plugin is going to give someone insane amounts of regret one day. It’s neat as “look what I did” but Elixir is all about removing magic. It (lack of magic) is one of the things I appreciated most, having originally come from Ruby and Rails. I’ve been using it professionally for nearly ten years, and I can say this isn’t a feature I’ve ever really…

i don’t like adding foundational syntax using libraries, but i do wish they would add this to the language. deconstruction by pattern is super common and the syntactic sugar would be most welcome.

Re: Show HN: es6_maps, new Elixir syntax feature via runtime compiler hacking

#16
post #12

Earlier quoted context omitted.

JS and python are just about all programming languages? I'm not trying to be snarky, but e.g. I haven't seen it in Go, F# and Rust, some languages where I have at least seen _some_ code. I also don't remember a similar pattern in Java, C# and C nor PHP or Dart, but I will readily admit that it's I haven't coded in any of these in the last two years, so I might be a bit out of touch and I'm not super proficient in all…

Go, and F# do almost all positional arguments. I think Rust too. Java, C#, C, PHP are also positional only or 99% of the time. I assume Dart too. We are talking named/keyword/etc. Personally I find positional arguments to be an anti-pattern in all but a very specific set of circumstances.

C#, F# and PHP all support named arguments and they're quite common for optional parameters.

Re: Show HN: es6_maps, new Elixir syntax feature via runtime compiler hacking

#17
post #5

Earlier quoted context omitted.

This pattern appears frequently in just about all programming languages. I’ve written a lot of JS and Python, and a moderate amount of Elixir, and this pattern crops up quite often. Usually it’s a side effect of complex scopes with several layers of function calls. Honestly I’m a little surprised you haven’t seen this pattern. The only times it wouldn’t be used are when people rename variables, which is frankly a pra…

JS and python are just about all programming languages? I'm not trying to be snarky, but e.g. I haven't seen it in Go, F# and Rust, some languages where I have at least seen _some_ code. I also don't remember a similar pattern in Java, C# and C nor PHP or Dart, but I will readily admit that it's I haven't coded in any of these in the last two years, so I might be a bit out of touch and I'm not super proficient in all…

If we're talking about constructing structs, like in `Foo { bar, baz: 123 }` (with the `bar` style shortcut in it), I have used that kind of syntax 10 times in 16 KLOC of Rust. Not a lot, but it does happen, and I found it kinda neat when LSP integration suggested its use.

I've probably used it more for pattern matching (`let Foo { bar, baz } = ...`), but haven't measured the number of instances of that idiom.

Re: Show HN: es6_maps, new Elixir syntax feature via runtime compiler hacking

#18
A good reminder that macros give you super powers!

I don't know a lot of elixir, so I can't say if this is a great idea for inclusion into the standard or not, but it's undeniable that giving macro-based access to the AST adds a lot of expressivity and flexibility.

Re: Show HN: es6_maps, new Elixir syntax feature via runtime compiler hacking

#19
post #8

This was done previously with the `short_maps` library, which the author—a member of the Elixir core team—eventually retired and archived due to regrets from the undesirable impacts on clarity. https://github.com/whatyouhide/short_maps https://andrealeopardi.com/posts/a-story-of-regret-and-retir...

I really don’t understand why some people are so against this as a language feature. I get that the community tries to stay away from “magic” but where is the line between magic and convenient syntactic sugar. For example keyword lists as the last argument to a function don’t need brackets, and keyword lists are really lists of tuples where the first item is an atom. I feel like those two things are in some ways less…

Magic == “I don’t like it, but I want to sound more objective or rational than I really am”.

You’re definitely correct that there’s as good an argument that these implicit features you mention are “too magical” as there is the the “ES6” syntax is too magical.

Post reply on HN