MTGZone
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Maven (famous)@lemmy.zip to Programmer Humor@programming.dev · 4 天前

Modern Programming

lemmy.zip

message-square
76
fedilink
572

Modern Programming

lemmy.zip

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

    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
      ·
      4 天前

      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
        ·
        4 天前

        Ah that makes sense.

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

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

          • Lifter@discuss.tchncs.de
            link
            fedilink
            arrow-up
            1
            ·
            3 天前

            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
        ·
        4 天前

        deleted by creator

      • kn0wmad1c@programming.dev
        link
        fedilink
        English
        arrow-up
        1
        ·
        4 天前

        deleted by creator

    • Sleepless One@lemmy.ml
      link
      fedilink
      English
      arrow-up
      5
      ·
      4 天前

      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
        ·
        2 天前

        It does. Empty collections, 0, None

    • Kaboom@reddthat.com
      link
      fedilink
      arrow-up
      7
      arrow-down
      2
      ·
      4 天前

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

    • marcos@lemmy.world
      cake
      link
      fedilink
      arrow-up
      2
      ·
      4 天前

      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
      ·
      4 天前

      The joys of dynamic typing.

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

      In JS 0 is the same as False

      • Lifter@discuss.tchncs.de
        link
        fedilink
        arrow-up
        1
        ·
        3 天前

        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
          ·
          3 天前

          Explosion?

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.

  • 372 users / day
  • 4.98K users / week
  • 10.1K users / month
  • 19.5K users / 6 months
  • 4 local subscribers
  • 24.2K subscribers
  • 1.5K Posts
  • 55.1K Comments
  • Modlog
  • mods:
  • Feyter@programming.dev
  • adr1an@programming.dev
  • BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne@programming.dev
  • BE: 0.19.5
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org