56 comments

log in to comment.

  • @Lupie@sopuli.xyz · 4d ago · edited

    No, it should not be an error. If you’re making a calculator and your user enters 1/0, your program should not have the propensity to crash; the result should simply be NaN and you should choose how you display that result to your user.

    • @treadful@lemmy.zip · 4d ago

      You talk like error handling isn’t a thing.

      • @anewfox@lemmy.zip · 4d ago · edited

        fun fact: getting NaN from a numeric calculation is the error that you handle. if this wasn’t obvious, please don’t write code for anyone but yourself. hope this helps.

        • @daychilde@lemmy.world · 4d ago

          if this wasn’t obvious,

          If this wasn’t obvious, be glad of the chance to learn.

          If we all stopped as soon as something simple wasn’t obvious, nobody would learn and nobody would do anything.

          What a terrible reply to someone. It cuts off curiosity and says “You are too stupid to do anything.”

          Yet I bet there was a time that even with that very specific thing, you didn’t think of it that way.

        • @lemonsorrel@lemmy.world · 4d ago

          newcomers to shitting on javascript sometimes learn to blame the tool

        • @treadful@lemmy.zip · 4d ago

          NaN is a primitive value, not an Error.

          >> typeof 1 / "a"
          "number" 
          
    • @daychilde@lemmy.world · 4d ago

      error ≠ crash

      • @bss03@infosec.pub · 4d ago

        fault v. error v. failure

        In common language they can be synonyms, but often aren’t in places (like computing) where there’s a useful difference. A page fault isn’t an error; a handled error doesn’t result in a failure; fault-tolerant systems fail less often than their components fault.