News for hackers. Stuff that matters.
Re:Microfeatures I'd like to see in more languages by tobyhinloopen on Thursday January 05, 2023 @05:16PM (#34267649)
Elixir’s testing library uses meta programming to show the code that fails and what the values were at both sides of a comparison.

IE

    a = 1; b = 2
    assert a == b
Will fail with error like:

    Assertion failed,
    a == b
    Left is 1
    Right is 2
So you don’t have a bunch of assert-functions; you just assert anything and it will spit out a decent error.
Re:Microfeatures I'd like to see in more languages by masklinn on Thursday January 05, 2023 @05:35PM (#34267891)
With how old pytest is, I assume that's where they got it from. Does it perform recursive value printing, or bespoke comparisons?

e.g. in pytest it won't just print out the values of "a" and "b", it will recursively document intermediate values until it's reached the toplevel expression:

    assert f() == g()
    assert 42 == 43
      where 42 = <function TestFailing.test_simple.<locals>.f at 0xdeadbeef0002>()
      and   43 = <function TestFailing.test_simple.<locals>.g at 0xdeadbeef0003>()
and it's possible to customise the report so you can report as a diff:

    assert "foo 1 bar" == "foo 2 bar"
      - foo 2 bar
      ?     ^
      + foo 1 bar
      ?     ^
Re:Microfeatures I'd like to see in more languages by elcritch on Thursday January 05, 2023 @05:24PM (#34267736)
Yes! That feature is great. I got used to it in Elixir and Nim provides it as well. It's one of those little things that makes programming nicer.
Re:Microfeatures I'd like to see in more languages by cpurdy on Saturday January 07, 2023 @07:43PM (#34294751)
This is one that I like a lot. Years ago (1997 timeframe) I had implemented it in a Java compiler, and a few years later in a Java library (https://github.com/oracle/coherence/blob/4e6e343e1ffd9bbfea3...) that would create an exception on the assertion failure and parse its stack trace to find the source code file name, and read it to find the text of the assertion that failed, etc. so it could build the error message ...

In Ecstasy, we built the support directly into the compiler again:

    val a = 1;
    val b = 2;
    assert a == b;
Produces:

    IllegalState: a == b, a=1, b=2
Re:Microfeatures I'd like to see in more languages by still_grokking on Sunday January 08, 2023 @03:15PM (#34302619)
ScalaTest does the same.