3 ms·
Strikes me as so so. defer is the kind of thing I would mock up in a hurry in my code if a language or framework lacked the proper facilities, but I think you
by PaulHoule 1y ago
Strikes me as so so.
defer is the kind of thing I would mock up in a hurry in my code if a language or framework lacked the proper facilities, but I think you are better served with the with statement in Python or automated resource management in Java.
Similarly I think people should get over Optional and Either and all of that, my experience is that it is a lot of work to use those tools properly. My first experience with C was circa 1985 when I was porting a terminal emulator for CP/M from Byte magazine to OS-9 on the TRS-80 Color Computer and it was pretty traumatic to see how about 10 lines of code on the happy path got bulked up to 50 lines of code that had error handling weaved all around it and through it. When I saw Java in '95 I was so delighted [1] to see a default unhappy path which could be modified with catch {} and fortified with finally {}.
It's cool to think Exceptions aren't cool but the only justification I see for that is that it can be a hassle to populate stack traces for debugging and yeah, back in the 1990s, Exceptions were one of the many things in the C++ spec that didn't actually work. Sure there are difficult problems with error handling such as errors don't respect your ideas of encapsulation [2] but those are rarely addressed by languages and frameworks even though they could be
https://gen5.info/q/2008/08/27/what-do-you-do-when-youve-caught-an-exception/ https://gen5.info/q/2008/08/27/what-do-you-do-when-youve-cau...
putting in ? or Optional and Either though are just moving the deck chairs on the Titanic around.
[1] I know I'm weird. I squee when things are orderly, more people seem to squee when they see that Docker lets them run 5 versions of libc and 7 versions of Java and 15 versions of some library.
[2] Are places where the "desert of the real" intrudes on "the way things are spozed to be"
- lerno 1y agoC3 error handling is fairly novel though. It tries to find a sweet spot between composability, explicitness and C compatibility. The try-catch has nice composability: try { int x = foo_may_fail(); int y = bar_may_fail(x); } catch (... ) { ... } Regular Result types need to use flatmap for this, and of course error codes or multiple returns also struggle with this. With C3: int? x = foo_may_fail(); int? y = bar_may_fail(x); if (catch err = y) { ... return; } // y is implicitly unwrapped to "int" here This is not to say it would satisfy you. But just to illustrate that it's a novel approach that goes beyond Optional and Either and has a lot in common with try-catch.
- throwawaymaths 1y agoI honestly still don't know what `with` does in python. Without looking it up: Since I don't use python all that often, my best guess is that it calls some magic dunder function? I get that "primitives" like +, - aren't actually and ALSO call dunders, but there's a bit of "ssh don't tell me that and let me pretend" in the python ethos, and writing your own dunder function for anything that isn't number-ish is probably a huge code smell, and probably a potential footgun even if it is numberish. which is why `with` always felt weird to me.