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

Modern Programming

lemmy.zip

message-square
19
link
fedilink
2

Modern Programming

lemmy.zip

Maven (famous)@lemmy.zip to Programmer Humor@programming.dev · 1 month ago
message-square
19
link
fedilink
alert-triangle
You must log in or # to comment.
  • Digital Mark@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 month ago

    print( ["even", "odd"][num % 2] )

    If you need to avoid evaluating the wrong branch:

    print( [lambda: "even", lambda: "odd"][num % 2]() )

    • FireIced@lemmy.super.ynh.fr
      link
      fedilink
      arrow-up
      1
      ·
      1 month ago

      Cursed

      • Gamma@programming.dev
        link
        fedilink
        English
        arrow-up
        2
        ·
        1 month ago

        Not as cursed as

        print("eovdedn"[n%2::2]) 
        
  • entropicdrift@lemmy.sdf.org
    link
    fedilink
    arrow-up
    1
    ·
    1 month ago
    print("odd" if num % 2 else "even")
    

    That’s the native python version, for those curious

    • DreadPirateShawn@lemmy.blahaj.zone
      link
      fedilink
      arrow-up
      1
      ·
      1 month ago

      The ternary syntax is really my only real gripe with python design – putting the conditional BETWEEN the true and false values feels so very messy to me.

      • idunnololz@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        1 month ago

        At least you guys have ternary syntax cries in kotlin.

        • aubeynarf@lemmynsfw.com
          link
          fedilink
          arrow-up
          1
          ·
          22 days ago

          in Scala, everything is an expression, including “if”, maybe kotlin is the same?

      • balsoft@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        1 month ago

        Eh, reads pretty naturally to me. That said, (like I lisp)

        • Shareni@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          1 month ago

          Lisps makes more sense to me though

          (if condition a b)

          VS

          a if condition else b

    • Kaboom@reddthat.comBanned
      link
      fedilink
      arrow-up
      0
      arrow-down
      1
      ·
      1 month ago

      Why is the return first?

  • Ephera@lemmy.ml
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 month ago

    For optimal performance, you should rewrite it in Rust:

    inline_python::python! {
        print(js2py.eval_js("(number) => number % 2 ? 'odd' : 'even'")(number))
    };
    
    • ATPA9@feddit.org
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      1 month ago

      And now you can use wasm to run it in a browser!

  • SpaceNoodle@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    1 month ago

    Please. That’s C’s ternary operator. JS is just a pile of garbage cosplaying as a programming language

    • Victor@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      1 month ago

      Why do you say it’s a pile of garbage?

      • SpaceNoodle@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        1 month ago

        Because of all the garbage

        • Fillicia@sh.itjust.works
          link
          fedilink
          arrow-up
          1
          ·
          1 month ago

          Clearly the garbage collector is too effective

          • filcuk@lemmy.zip
            link
            fedilink
            arrow-up
            1
            ·
            1 month ago

            No they’re not supposed to be piling it up

  • kn0wmad1c@programming.dev
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    1 month 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.comBanned
      link
      fedilink
      arrow-up
      0
      arrow-down
      1
      ·
      1 month ago

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

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.

  • 802 users / day
  • 3.82K users / week
  • 7.47K users / month
  • 7.55K users / 6 months
  • 1 local subscriber
  • 25.1K subscribers
  • 254 Posts
  • 2.62K Comments
  • Modlog
  • mods:
  • adr1an@programming.dev
  • Feyter@programming.dev
  • BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne@programming.dev
  • BE: 0.19.12
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org