Inspecting numbers in iex and tests

I was think about numbers in console (iex) and tests. It’s hard to read bigger numbers.
Of course in tests we have colors for changes (thanks!), but its only for tests and only when comparing results by assert macro.
So here is my proposition:

Environment

  • Elixir & Erlang versions (elixir -v):
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:4:4] [async-threads:10]

Elixir 1.5.0-dev (40c55f3)

Erlang is from portage. Elixir is compiled from source.

  • Operating system:
Funtoo Linux (Gentoo based) stable (stage1 setup) with latest updates.

Test code:

defmodule MyApp do
  def number_a(), do: 100000
  # ...
  def number_b(), do: 1000000
end

defmodule MyAppTest do
  use ExUnit.Case

  doctest MyApp

  import MyApp

  test "numbers" do
    assert number_a() == number_b()
  end
end

Current behavior

iex(1)> num = 1_000_000
1000000
iex(2)> IO.puts num    
1000000
:ok
iex(3)> IO.inspect num
1000000
1000000

mix test



  1) test numbers (MyAppTest)
     test/my_app_test.exs:9
     Assertion with == failed
     code: a == b
     lhs:  1000000
     rhs:  100000
     stacktrace:
       test/my_app_test.exs:9: (test)



Finished in 0.1 seconds
2 tests, 1 failure

Expected behavior

iex(1)> num = 1_000_000
1_000_000
iex(2)> IO.puts num    
1_000_000
:ok
iex(3)> IO.inspect num
1_000_000
1_000_000

mix test



  1) test numbers (MyAppTest)
     test/my_app_test.exs:9
     Assertion with == failed
     code: a == b
     lhs:  1_000_000
     rhs:  100_000
     stacktrace:
       test/my_app_test.exs:9: (test)



Finished in 0.1 seconds
2 tests, 1 failure

What do you think about it?

Adding underscores might be interesting, but I think Elixir 1.4 is adding red/removed and green/add part of comparisons. If it does not do it with numbers then it should with a PR (I think it does it to anything inspectable)? :slight_smile:

1 Like

It definitely is an interesting idea, but I believe it might break a lot of existing (doc)tests.

Pretty printing integers was considered as addition to Elixir but ultimately it didn’t get through. See this PR: https://github.com/elixir-lang/elixir/pull/4916

1 Like

@wojtekmach: ahhh, one my mistake:
I’m working on one project on github and we have for every smallest change one issue, one PR and one branch (and one card in project).
So I habitually removed only is:open and searched like: is:issue numbers separator.
Also I don’t know that it’s so complicated (I mean I18n part of discussion). I fully agree with decision and its arguments. However it could be a good part of I18n library. I will remember that, because I was think about it (currently I’m working on another secret project and I have hope to release it in this month).
Thanks for all responses!