News for hackers. Stuff that matters.
Re:Const all the things? by mastax on Monday January 24, 2022 @10:33AM (#30058875)
I really like the way C# did this:

    void foo<T>(T by_value, ref T by_ref, in T by_immutable_ref, out T out_only);
Append `?` to any type to make it optional. (Though that is more of a lint than truly part of the type system).

`out` parameters pass no value in and must pass a value out. Isn't that just a return value, semantically? Yes, but we didn't used to have value tuples and destructuring so we had to make do. It can still be nicer for some things:

    bool TryParse(string input, out int value)

    if (int.TryParse("123", out int value))
        // Use value
Re:Const all the things? by Jenk on Monday January 24, 2022 @10:48AM (#30059076)
Then async comes along and you can't use `out` in async methods :)

Thus (anonymous) tuples were introduce so we can do it Go/Rust-style:

    async Task<(bool, T)> Foo<T>(T value) {
        /* do something async like a web request or file read etc. */
        var aThing = await GetAThing<T>(value);
        return (aThing != null, aThing);
    }