News for hackers. Stuff that matters.
Re:How to Assert for Fun and Profit by happytoexplain on Monday October 09, 2023 @11:36PM (#37828261)
>if you are throwing an error in most of the languages your caller function will not get an idea that this function can throw an error

Is this true any more? I feel like most languages, relative to popularity, have compiler-enforced thrown error handling.

Re:How to Assert for Fun and Profit by gdprrrr on Monday October 09, 2023 @11:44PM (#37828307)
C# is one of the offenders. And while Java has checked exceptions, many considered Thema an annoyance and wrap everything in RuntimeException.
Re:How to Assert for Fun and Profit by flakes on Tuesday October 10, 2023 @12:00AM (#37828393)
Very true. Checked exceptions in Java are a form of function coloring problem for modern libraries.

Especially painful when using any of the functional style stream operations, like `map`, `filter`, etc, or any other higher order function library. Most take in the standard `Function` or `BiFunction` interface arguments, which will not support method referencing for anything which includes a checked exception as part of its signature.

Re:How to Assert for Fun and Profit by gpderetta on Tuesday October 10, 2023 @04:37AM (#37829757)
But a better language would allow generalizing over exceptions. In pseudo C++:

  auto map(collection<T> C collection, function<T> F f) -> invoke_result<F, T> throws(invoke_exception<F, T>);
Re:How to Assert for Fun and Profit by TeMPOraL on Tuesday October 10, 2023 @06:07AM (#37830247)
> Checked exceptions in Java are a form of function coloring problem for modern libraries.

So is returning result or error via Either/Expect/Result sum types. Exceptions or Expected, code gets messed up either way.

Re:How to Assert for Fun and Profit by flakes on Wednesday October 11, 2023 @11:31PM (#37853213)
Not quite of the same caliber. A checked exception has the form `R func(T t) throws Err`. A concrete result type (like Rust has) would look like `Result<R, Err> func(T t)`.

The later fits nicely into the `Function<,>` interface, `Function<T, Result<R, Err>>` vs the former requires a different interface entirely, something like `FuncE<T, R, Err>` where `Err` breaks out into an argument for the throws value of the signature.

Because most of the functional libraries in Java work with Function, BiFunction, etc, we end up with incompatible arguments for common patterns such as `map`, `filter`, etc.

Re:How to Assert for Fun and Profit by aiunboxed on Tuesday October 10, 2023 @12:50PM (#37834499)
Typescript, Python all are exception