• 2 Posts
  • 5 Comments
Joined 1 year ago
cake
Cake day: June 6th, 2023

help-circle

  • nyjan@feddit.deto196@lemmy.blahaj.zonerule
    link
    fedilink
    arrow-up
    2
    ·
    8 months ago

    My personal take on this, at least when dealing with more complex or production code:

    Performance is not an issue with exceptions if you don’t use them for control flow, they should be an unusual occurrence wherever possible.

    If you expect to throw and later handle an exception regularly, I’d try to include relevant info about the failure in the returned value, or even better in the returned type, and skip throwing the exception altogether.

    Returning a type that contains both error info and the actual result (if there is one) and forces the caller of your function to handle any contained error info before being able to access the actual result has the same effect as a try/catch block without the major performance implications.

    This is basically what rust does everywhere in order to completely remove the concept of exceptions, but it’s a nice performance optimization for langues with exceptions as well.

    Exceptions should interrupt your programs flow, not control it, at least in all hot execution paths. Thanks for coming to my ted talk


  • nyjan@feddit.detoich_iel@feddit.deich⏱️iel
    link
    fedilink
    Deutsch
    arrow-up
    18
    arrow-down
    1
    ·
    1 year ago

    Naja das kommt, mutmaße ich, mitunter auf die Strecken an die du gefahren bist. Ich fahre mehrmals in der Woche Fernverkehr und bin trotz der aktuell katastrophalen deutschlandweiten Pünktlichkeit der Bahn bei Fahrten durch Ostdeutschland quasi nie verspätet angekommen, bei Strecken über z.B. Frankfurt und/oder Mannheim könnte ich mich hingegen nicht an eine einzige Fahrt ohne Verspätung und Zwischenfälle erinnern.