Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
Lena ( lena@gregtech.eu )  to Programmer Humor@programming.dev · 1 day ago

What the fuck javascript

gregtech.eu

message-square
23
link
fedilink
251

What the fuck javascript

gregtech.eu

Lena ( lena@gregtech.eu )  to Programmer Humor@programming.dev · 1 day ago
message-square
23
link
fedilink
alert-triangle
You must log in or register to comment.
  • Everyday0764 ( Everyday0764@lemmy.zip ) 
    link
    fedilink
    arrow-up
    1
    ·
    1 hour ago

    there is a game / challenge for this

  • baramintal ( baramintal@lemmy.org ) 
    link
    fedilink
    arrow-up
    2
    ·
    6 hours ago

    The beauty of JavaScript.

    You probably haven’t encountered truthsy and falsy values yet?

  • iuminou ( thethunderwolf@lemmy.dbzer0.com ) 
    link
    fedilink
    English
    arrow-up
    8
    ·
    16 hours ago

    this makes sense

    NaN is a “this was meant to be a number but it somehow isnt”

  • ThunderComplex ( ThunderComplex@lemmy.today ) 
    link
    fedilink
    arrow-up
    56
    ·
    1 day ago

    I think this, and the fact that NaN == NaN is false, make perfect sense.
    NaN is the result of mathematically undefined behavior. You’re not going to get a NaN outside of a number context, so tying it together in the Number scope is fine.

    • LillyPip ( LillyPip@lemmy.ca ) 
      link
      fedilink
      English
      arrow-up
      8
      ·
      24 hours ago

      Same reason NULL != NULL. It makes sense if you understand how these values work.

    • threeonefour ( threeonefour@piefed.ca ) 
      link
      fedilink
      English
      arrow-up
      8
      ·
      1 day ago

      The result of mathematically undefined behaviour should be an error, but sure, go ahead and return Keleven. 1/0 = keleven fuck it.

      • bss03 ( bss03@infosec.pub ) 
        link
        fedilink
        English
        arrow-up
        26
        ·
        1 day ago

        NaN is one of the ways IEEE maths signals an erroneous calculation when the only outbound communication channel is the returned IEEE value. Reading the history and rationale of the floating-point standard will likely convince you this was and probably is a good compromise.

        Because IEEE values often have hardware acceleration that is a significant factor in performance, languages rarely (if ever) choose to map all IEEE error values to language-specific error reporting (e.g. a thrown exception or error-tracking algebraic data type).

        JS is hardly an outlier here.

        I do think it probably violates the principle of least surprise, but I don’t think I understand the scale of “momentum” change that would need to take place across society (industry, academia, etc.) to align it with naive expectations.

      • ThunderComplex ( ThunderComplex@lemmy.today ) 
        link
        fedilink
        arrow-up
        14
        ·
        1 day ago

        NaN is a error and it’s your responsibility to handle it gracefully. No need to halt the entire program when you fuck up some maths.

        • threeonefour ( threeonefour@piefed.ca ) 
          link
          fedilink
          English
          arrow-up
          15
          ·
          1 day ago

          NaN is a error

          Error.isError(NaN)
          // False
          
          • lime! ( lime@feddit.nu ) 
            link
            fedilink
            arrow-up
            13
            ·
            1 day ago

            nan is a ieee754-defined error. what javascript calls errors these days (it tends to change a lot) has little to nothing to do with that. it’s on every developer to familiarise themself with ieee754, it’s one of the most important documents in the profession.

            while nan is an invalid floating-point number, it is a valid value for a float-typed field. making it into an error is like adding a bit labelled “crash” to every number in your program.

          • anewfox ( anewfox@lemmy.zip ) 
            link
            fedilink
            arrow-up
            3
            ·
            24 hours ago

            please do everyone a favor and stop writing code.

      • Lupie ( Lupie@sopuli.xyz ) 
        link
        fedilink
        arrow-up
        11
        ·
        1 day ago

        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 ( treadful@lemmy.zip ) 
          link
          fedilink
          English
          arrow-up
          5
          ·
          1 day ago

          You talk like error handling isn’t a thing.

          • anewfox ( anewfox@lemmy.zip ) 
            link
            fedilink
            arrow-up
            7
            ·
            24 hours ago

            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.

            • treadful ( treadful@lemmy.zip ) 
              link
              fedilink
              English
              arrow-up
              1
              ·
              23 hours ago

              NaN is a primitive value, not an Error.

              >> typeof 1 / "a"
              "number" 
              
  • bss03 ( bss03@infosec.pub ) 
    link
    fedilink
    English
    arrow-up
    36
    ·
    1 day ago

    https://www.destroyallsoftware.com/talks/wat is much better. This post is pretty low-effort.

    • Lena ( lena@gregtech.eu ) OP
      link
      fedilink
      arrow-up
      14
      ·
      24 hours ago

      I love that talk.

      And yes, this post is low-effort, but so are most posts on here. Just a bunch of screenshots from various microblogging platforms reposted from Reddit.

  • Colloidal ( Colloidal@programming.dev ) 
    link
    fedilink
    arrow-up
    12
    ·
    23 hours ago

    It’s clearly bread.

  • palordrolap ( palordrolap@fedia.io ) 
    link
    fedilink
    arrow-up
    16
    ·
    1 day ago

    Infinity is also a number in JavaScript / IEEE number formats, but you’ll get a lot of grumbling from mathematicians with that sort of assertion.

    • anton ( anton@lemmy.blahaj.zone ) 
      link
      fedilink
      arrow-up
      4
      ·
      11 hours ago

      Once you accept that each float represent a range of reals most design decisions make sense.
      Infinity is just the name given to values that are too large to represent otherwise and negative zero includes negative values too close to zero.

      What mathematics probably hate most about floats is that rounding breaks commutativity.

      • bss03 ( bss03@infosec.pub ) 
        link
        fedilink
        English
        arrow-up
        1
        ·
        2 hours ago

        What mathematics probably hate most about floats is that rounding breaks commutativity.

        Actually, the maths people in my circles tend to complain more about how the normal floating-point equality test doesn’t define an equivalence relation, but really any of the violations of field properties can attract complaints.

  • bigmclargehuge ( bigmclargehuge@lemmy.zip ) 
    link
    fedilink
    arrow-up
    13
    ·
    1 day ago

    The way I think about it: number is a js type. A floating point double, in other languages.

    NaN is a state that a number type can be in, representing a situation where the outcome of the numeric operation cannot be determined.

    Anywho, also yea ….JavaScript is goofy

  • Señor Mono ( SrMono@feddit.org ) 
    link
    fedilink
    arrow-up
    3
    ·
    1 day ago

    https://youtu.be/et8xNAc2ic8

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
    • If the mod doesn’t find it funny, you’re banned. Ha-ha!.. For real: do not use the community for “statements”. There are other places for such content. Keep it chill and funny.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 1.17K users / day
  • 2.76K users / week
  • 5.18K users / month
  • 8.36K users / 6 months
  • 465 local subscribers
  • 34.1K subscribers
  • 1.66K Posts
  • 27.4K Comments
  • Modlog
  • mods:
  • Feyter ( Feyter@programming.dev ) 
  • adr1an ( anzo@programming.dev ) 
  • BurningTurtle ( BurningTurtle@programming.dev ) 
  • Pierre-Yves Lapersonne ( pylapp@programming.dev ) 
  • BE: 0.19.21
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code