romul
Dbg_inspect - Debug inspect like in dbg! macro in Rust
Recently I read release notes of Rust 1.32 and was impressed of dbg macro convenience.
Therefore I decided to implement the same concept in Elixir.
Here is the result: GitHub - romul/dbg_inspect: Implementation of dbg! Rust-macro for Elixir · GitHub
Additional features comparing to IO.inspect/1:
- Prints representation of expression passed as the first argument
- Prints filename and line number where Dbg.inspect/2 was called
- Ability to print values of all variables used in the expression passed as the first argument
- Colored output
- Output to :stderr stream
- No affects prod environment
Output example:
IO.inspect/1 output for the same case:
%{0 => "0", 1 => "1", 2 => "4", 3 => "9"}
Most Liked
wojtekmach
Yes, dbg! macro looks really interesting!
Here’s my take on it: https://github.com/wojtekmach/elixir/commit/27d0019e1d21a3b2f7946a353c2439096df53612.
I think it needs to be in Kernel to be most usable because we need to require/import it to use it, and it’s gonna be annoying to do it every time.
I showed this to a few people and still collecting feedback before proposing this as a feature.
romul
Well, don’t you mind to unite our efforts to provide even more useful solution than Rust out of the box? As you can see I’ve already implemented several additional features for this macro. I could transfer them to your branch. So we will have 2 commits in the proposal ![]()
wojtekmach
I’m pretty happy with the limited feature set I’ve implemented but additional features you’ve added sound interesting too, I’ll definitely play with them. Feel free to argue for these additions when there’s a proposal or send the proposal yourself ![]()
Some feedback:
-
show_vars: truelooks interesting. I didn’t have a need for it yet, but will definitely keep it in mind.Special casing variables in just the first call seems somewhat arbitrary, it wouldn’t for example show
yinDbg.inspect(x |> max(y))and that could be a bug or a feature, not sure! Perhaps it should show all variables used in an expression? You can get them usingKernel.binding. -
if the function is defined as
inspect/2, there’s a clash withKernel.inspect/2so you wouldn’t be able to import it out of the box. One of my goals for this macro was to be available right away, but perhaps that’s no such a big deal, similarly how writingrequire IEx; IEx.pry()isn’t? I’ll definitely try this for a few days without this being in Kernel. -
Dbgis perhaps too similar with OTP’s:dbgmodule? That being said, I’m not super happy withKernel.debugname either but couldn’t come up with neither better module nor function name.
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









