On Mon, Oct 5, 2020 at 3:03 PM 'Bryan C. Mills' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

>
> The core of the problem is that `assert` functions generally *cannot* provide
> enough context to produce useful test failures
> <http://golang.org/wiki/CodeReviewComments#useful-test-failures>. An
> `assert` call compares values, but does not report the relevant inputs and
> calls leading to those values — and the description of the inputs and the
> operations performed on those inputs are what the person diagnosing the
> test failure will need in order to figure out what went wrong.
>
>
This is an excellent example of boolean blindness. A pass or panic is
essentially the same as the values true and false. But the astute reader
will realize that just knowing that an expression evaluates to "true"
doesn't give you any information as to why. Many programs then have other
functions you can call to get a description of what is wrong in the
program, but this leads to a style where you first compute a boolean value,
then have a large chunk of code which is used to figure out what is wrong.

It is often better to return a more complex data structure for the error in
a program, and make it a Stringer so it has a human readable variant. This
ensures the program is able to work with the data structure underneath,
without relying on the human text, while also providing the human a way to
understand what is wrong[1].

Another example of this in action would be the government telling you that
you have to pay $10K in taxes, but upon request they cannot tell you how
much of that is from gifts, income, wealth, etc. You become "blind" to the
details of the computation and are only given a final number to look at. If
you have a data structure, you can have an "Eval()" method on it which can
compute the final number. This claws at the concept of Free constructions
and universal mapping properties in Category Theory: you have a data
structure which throws away no information. Then you attach several
interpreters to this structure, each with their own view of the data at
hand. Sometimes you just want the sum you have to pay in taxes. Some times
you want it as an HTML table, JSON or Spreadsheet. And some times as an R
data frame. Hence you use the general structure such that all other
derivations factorize through it.

Finally, a mathematical variant is knowing that a theorem is true without
knowing its proof.

[1] And if you have proper pattern matching in the language, you can then
get rid of if..then..else which becomes redundant: match x with true -> ..
| false -> ..end

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGrdgiXWXa9XpsJSgJQ6T10B_RqUNFo_kET30MdszSe5sO0nAg%40mail.gmail.com.

Reply via email to