Lemmy Mengsk
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Maven (famous)@lemmy.zip to Programmer Humor@programming.dev · 1 个月前

Modern Programming

lemmy.zip

external-link
message-square
76
fedilink
585
external-link

Modern Programming

lemmy.zip

Maven (famous)@lemmy.zip to Programmer Humor@programming.dev · 1 个月前
message-square
76
fedilink
  • kn0wmad1c@programming.dev
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    2
    ·
    edit-2
    1 个月前

    num % 2 isn’t a boolean result in any of these languages, so I feel like it would always output “odd”

    Edit: 0 is false, everything else is true.

    • moomoomoo309@programming.dev
      link
      fedilink
      English
      arrow-up
      8
      ·
      1 个月前

      All of those languages will convert numbers into booleans, 0 is false, all other numbers are true.

      • kn0wmad1c@programming.dev
        link
        fedilink
        English
        arrow-up
        3
        ·
        1 个月前

        Ah that makes sense.

        • SatyrSack@lemmy.sdf.org
          link
          fedilink
          arrow-up
          2
          arrow-down
          1
          ·
          1 个月前

          It doesn’t make sense. I understand it, but it doesn’t make sense.

          • Lifter@discuss.tchncs.de
            link
            fedilink
            arrow-up
            1
            ·
            1 个月前

            I agree. If anything it should check if there is a nuumber and 0 is clearly a number.

      • kn0wmad1c@programming.dev
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 个月前

        deleted by creator

      • kn0wmad1c@programming.dev
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 个月前

        deleted by creator

    • Sleepless One@lemmy.ml
      link
      fedilink
      English
      arrow-up
      5
      ·
      1 个月前

      In JS at least, there’s a concept of truthiness and falsiness. 0, undefined, null, and a few other non-boolean values are treated as false if used in conditionals and logical operations, while every other value is treated as true. I’m pretty sure python has something similar.

      • Hammerheart@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        1 个月前

        It does. Empty collections, 0, None

    • Kaboom@reddthat.com
      link
      fedilink
      arrow-up
      7
      arrow-down
      3
      ·
      1 个月前

      0 is false in C, Python, and JS. It should work

    • Maven (famous)@lemmy.zipOP
      link
      fedilink
      arrow-up
      3
      arrow-down
      1
      ·
      1 个月前

      In JS 0 is the same as False

      • Lifter@discuss.tchncs.de
        link
        fedilink
        arrow-up
        1
        ·
        1 个月前

        They are not the same, but 0 can be implicitly converted to false.

        What do you get if you do: 0 === false

        • Lysergid@lemmy.ml
          link
          fedilink
          arrow-up
          1
          ·
          1 个月前

          Explosion?

    • marcos@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      1 个月前

      You’d be surprised.

      But seriously, numbers can be used as booleans in an impressive number of languages. Including machine code for almost every machine out there.

    • Colloidal@programming.dev
      link
      fedilink
      arrow-up
      3
      arrow-down
      1
      ·
      1 个月前

      The joys of dynamic typing.

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
Visibility: Public
globe

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

  • 2.68K users / day
  • 2.68K users / week
  • 3.4K users / month
  • 19.2K users / 6 months
  • 1 local subscriber
  • 25.1K subscribers
  • 1.23K Posts
  • 27.5K Comments
  • Modlog
  • mods:
  • Feyter@programming.dev
  • adr1an@programming.dev
  • BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne@programming.dev
  • BE: 0.19.8
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org