This doesn't cut it
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Maven (famous)@lemmy.zip to Programmer Humor@programming.dev · 24 hours ago

Modern Programming

lemmy.zip

message-square
67
fedilink
505

Modern Programming

lemmy.zip

Maven (famous)@lemmy.zip to Programmer Humor@programming.dev · 24 hours ago
message-square
67
fedilink
  • kn0wmad1c@programming.dev
    link
    fedilink
    English
    arrow-up
    1
    arrow-down
    2
    ·
    edit-2
    21 hours ago

    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.

    • Kaboom@reddthat.com
      link
      fedilink
      arrow-up
      7
      ·
      21 hours ago

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

    • Sleepless One@lemmy.ml
      link
      fedilink
      English
      arrow-up
      5
      ·
      21 hours ago

      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.

    • moomoomoo309@programming.dev
      link
      fedilink
      English
      arrow-up
      6
      ·
      21 hours ago

      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
        2
        ·
        21 hours ago

        Ah that makes sense.

        • SatyrSack@lemmy.sdf.org
          link
          fedilink
          arrow-up
          2
          arrow-down
          1
          ·
          19 hours ago

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

          • Lifter@discuss.tchncs.de
            link
            fedilink
            arrow-up
            1
            ·
            39 minutes ago

            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
        ·
        21 hours ago

        deleted by creator

      • kn0wmad1c@programming.dev
        link
        fedilink
        English
        arrow-up
        1
        ·
        21 hours ago

        deleted by creator

    • marcos@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      21 hours ago

      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
      ·
      21 hours ago

      The joys of dynamic typing.

    • Maven (famous)@lemmy.zipOP
      link
      fedilink
      arrow-up
      3
      arrow-down
      1
      ·
      21 hours ago

      In JS 0 is the same as False

      • Lifter@discuss.tchncs.de
        link
        fedilink
        arrow-up
        1
        ·
        37 minutes ago

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

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

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.4K users / day
  • 5.05K users / week
  • 10.2K users / month
  • 18.9K users / 6 months
  • 1 local subscriber
  • 24.1K subscribers
  • 887 Posts
  • 17.5K Comments
  • Modlog
  • mods:
  • adr1an@programming.dev
  • Feyter@programming.dev
  • BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne@programming.dev
  • BE: 0.19.8
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org