Re:Onboarding to Elixir
by dgb23 on Tuesday June 22, 2021 @12:02PM
(#27593382)
Navigating those kind of frameworks and libraries is also incredibly frustrating. Where are my data structures? It's all hidden, scattered behind idiosyncratic interfaces that provide little observability.
[ Parent
| on HN ]
Exactly! In Elixir, structs are just a special case of a map with a little bit of compile-time field checking magic. At runtime it's all the same. It's so easy to see the shape of things and figure out where stuff came from. Also, `|> IO.inspect(label: "...")` is one of my favorite things ever in getting my head wrapped around a new struct I haven't encountered before.
if you use vscode, you might like this: https://slickb.it/bits/70
Oh that's lovely! I'm an Emacs user, and I've got two yasnippets that do roughly the same thing:
https://gist.github.com/ashton314/f0a90a46e39b103635f2be8d8e...
The second one adds a pipe in front, which is super handy. Yours gives me some ideas though…
Re:Onboarding to Elixir
by bostonvaulter2 on Tuesday June 22, 2021 @03:51PM
(#27596324)
Do you know if you can insert the current line number with yasnippet? I have two snippets that look almost identical to yours, although my non-pipe version leaves the cursor at the beginning of the label since I've found that I often want to customize the label because I may be inspecting similar variables at different points in the code.
Ah, figured it out. It's very powerful to be able to call elisp inside snippets. Here's my new Labeled Inspect snippet:
# -*- mode: snippet -*-
# name: Labeled Inspect
# key: lin
# --
IO.inspect($1, label: "$2$1 (`(buffer-name)`:`(line-number-at-pos))`")
and a piped version: # -*- mode: snippet -*-
# name: Piped Inspect
# key: pin
# --
|> IO.inspect(label: "$2$1 (`(buffer-name)`:`(line-number-at-pos))`")Excellent! I'm going to have to extend mine. Emacs ftw
Re:Onboarding to Elixir
by bostonvaulter2 on Tuesday June 22, 2021 @03:01PM
(#27595703)
Nice snippet! I think that snippets are often underrated by programmers, especially debugging related snippets (the code is temporary so "duplication" doesn't really matter).
This snippet is my #1 productivity enhancer for elixir. It goes extremely well with multiline cursor. Especially since line numbers are typically the same length so ninjaing out the inspects in a pipeline is usually fast
Re:Onboarding to Elixir
by pablodavila on Tuesday June 22, 2021 @05:05PM
(#27597200)
Also, if you have piped functions you can now use `|> tap(&IO.inspect(&1.a))`at any point (requires 1.12).