Re:TypeScript Is Surprisingly OK for Compilers
by baq on Friday August 18, 2023 @06:05AM
(#37173530)
not really; can't immediately return from the lambda caller without throwing, always have to either try/catch anyway or if/else the return value of the lambda. (also, it's rather ugly to read and inconvenient to write.)
[ Parent
| on HN ]
Re:TypeScript Is Surprisingly OK for Compilers
by jve on Friday August 18, 2023 @07:02AM
(#37173986)
Another idea, introduce ??? that would invoke on exception :)
var something = (mayThrow()
??? (SomeException ex) => { log.Info(ex); return null} )
??? (Exception ex) => { log.Fatal(ex); throw; };
Or maybe just start using Results as return type and get ValueOrDefault :) But when it comes to handling exceptions, I think it explodes there with ifs and processing IENumerables: https://github.com/altmann/FluentResultsBut then again, simpler Results wrapper may be used perhaps. But it is a different way of coding and takes some mental shift on how to think about errors and distinguish between error results and true exceptions.
Oh, csharplang already had discussion on the matters about try/catch single statements: https://github.com/dotnet/csharplang/issues/786
Re:TypeScript Is Surprisingly OK for Compilers
by scotty79 on Friday August 18, 2023 @06:47PM
(#37183117)
> can't immediately return from the lambda caller without throwing
You want to immediately return in the middle of something that was supposed to simulate just evaluating an expression?
You can't immediately return in the middle of 2+2 as well because return is a statement and can't be a part of expression.