Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Programmer Humor
  3. Modern Programming

Modern Programming

Scheduled Pinned Locked Moved Programmer Humor
programmerhumor
74 Posts 46 Posters 2 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • entropicdrift@lemmy.sdf.orgE [email protected]
    print("odd" if num % 2 else "even")
    

    That's the native python version, for those curious

    G This user is from outside of this forum
    G This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #7

    That's way too non-convoluted enough

    entropicdrift@lemmy.sdf.orgE 1 Reply Last reply
    9
    • capuccino@lemmy.worldC [email protected]

      I love something = condition and result1 or result2 in lua

      R This user is from outside of this forum
      R This user is from outside of this forum
      [email protected]
      wrote on last edited by [email protected]
      #8

      Python does that, too.

      https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not

      satyrsack@lemmy.sdf.orgS 1 Reply Last reply
      7
      • G [email protected]

        That's way too non-convoluted enough

        entropicdrift@lemmy.sdf.orgE This user is from outside of this forum
        entropicdrift@lemmy.sdf.orgE This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #9

        Python is kinda like that in general, unless you try to make it read like ass

        C W 2 Replies Last reply
        14
        • maven@lemmy.zipM [email protected]
          This post did not contain any content.
          P This user is from outside of this forum
          P This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #10

          Yeah... I played that "serial killer or programming language inventor" game.

          The only one I was completely in disagreement with was the inventor of Python. He's definitely a mass-murderer

          C 1 Reply Last reply
          9
          • maven@lemmy.zipM [email protected]
            This post did not contain any content.
            kn0wmad1c@programming.devK This user is from outside of this forum
            kn0wmad1c@programming.devK This user is from outside of this forum
            [email protected]
            wrote on last edited by [email protected]
            #11

            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.

            maven@lemmy.zipM moomoomoo309@programming.devM C K M 6 Replies Last reply
            2
            • entropicdrift@lemmy.sdf.orgE [email protected]

              Python is kinda like that in general, unless you try to make it read like ass

              C This user is from outside of this forum
              C This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #12

              Clearly an inferior language. /s

              1 Reply Last reply
              3
              • kn0wmad1c@programming.devK [email protected]

                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.

                maven@lemmy.zipM This user is from outside of this forum
                maven@lemmy.zipM This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #13

                In JS 0 is the same as False

                L 1 Reply Last reply
                2
                • kn0wmad1c@programming.devK [email protected]

                  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.devM This user is from outside of this forum
                  moomoomoo309@programming.devM This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #14

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

                  kn0wmad1c@programming.devK 3 Replies Last reply
                  7
                  • kn0wmad1c@programming.devK [email protected]

                    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.

                    C This user is from outside of this forum
                    C This user is from outside of this forum
                    [email protected]
                    wrote on last edited by
                    #15

                    The joys of dynamic typing.

                    1 Reply Last reply
                    1
                    • moomoomoo309@programming.devM [email protected]

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

                      kn0wmad1c@programming.devK This user is from outside of this forum
                      kn0wmad1c@programming.devK This user is from outside of this forum
                      [email protected]
                      wrote on last edited by
                      #16

                      Ah, that makes sense.

                      1 Reply Last reply
                      0
                      • kn0wmad1c@programming.devK [email protected]

                        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.

                        K This user is from outside of this forum
                        K This user is from outside of this forum
                        [email protected]
                        wrote on last edited by
                        #17

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

                        1 Reply Last reply
                        6
                        • kn0wmad1c@programming.devK [email protected]

                          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.

                          M This user is from outside of this forum
                          M This user is from outside of this forum
                          [email protected]
                          wrote on last edited by
                          #18

                          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.

                          1 Reply Last reply
                          1
                          • entropicdrift@lemmy.sdf.orgE [email protected]
                            print("odd" if num % 2 else "even")
                            

                            That's the native python version, for those curious

                            K This user is from outside of this forum
                            K This user is from outside of this forum
                            [email protected]
                            wrote on last edited by
                            #19

                            Why is the return first?

                            J B 2 Replies Last reply
                            7
                            • moomoomoo309@programming.devM [email protected]

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

                              kn0wmad1c@programming.devK This user is from outside of this forum
                              kn0wmad1c@programming.devK This user is from outside of this forum
                              [email protected]
                              wrote on last edited by
                              #20

                              That makes sense. However, num % 2 equaling 0 would mean it's even, and not "odd" like the ternary operator is outputting, yeah?

                              1 Reply Last reply
                              0
                              • moomoomoo309@programming.devM [email protected]

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

                                kn0wmad1c@programming.devK This user is from outside of this forum
                                kn0wmad1c@programming.devK This user is from outside of this forum
                                [email protected]
                                wrote on last edited by
                                #21

                                Ah that makes sense.

                                satyrsack@lemmy.sdf.orgS 1 Reply Last reply
                                2
                                • kn0wmad1c@programming.devK [email protected]

                                  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.

                                  sleeplessone@lemmy.mlS This user is from outside of this forum
                                  sleeplessone@lemmy.mlS This user is from outside of this forum
                                  [email protected]
                                  wrote on last edited by
                                  #22

                                  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.

                                  H 1 Reply Last reply
                                  4
                                  • K [email protected]

                                    Why is the return first?

                                    J This user is from outside of this forum
                                    J This user is from outside of this forum
                                    [email protected]
                                    wrote on last edited by
                                    #23

                                    I think the idea is it reads more naturally, so you can read it like this return A if statement is true else return B

                                    N 1 Reply Last reply
                                    16
                                    • entropicdrift@lemmy.sdf.orgE [email protected]
                                      print("odd" if num % 2 else "even")
                                      

                                      That's the native python version, for those curious

                                      D This user is from outside of this forum
                                      D This user is from outside of this forum
                                      [email protected]
                                      wrote on last edited by
                                      #24

                                      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.

                                      rbos@lemmy.caR B idunnololz@lemmy.worldI 3 Replies Last reply
                                      83
                                      • K [email protected]

                                        Why is the return first?

                                        B This user is from outside of this forum
                                        B This user is from outside of this forum
                                        [email protected]
                                        wrote on last edited by [email protected]
                                        #25

                                        Edit... I reread your comment and realized that python does it differently and that everything I typed was irrelevant... I'm still gonna leave it if anyone is interested in ternary expressions, but I suppose the answer to your question is, that's just how python does it.

                                        That's how ternary operators are designed to work. In essence, if you're looking to do a single line if/then, you can directly assign a variable from the result of a ternary expression.

                                        As an example, I was scripting something earlier where there may or may not be a value returned from a function, but I still had to do something with that return value later. For this thing, I was using JavaScript.

                                        I ended up with:

                                        return platform == "name"  ? "Option 1" : "Option 2"
                                        

                                        If I were to write that out in a typical if/then it would be:

                                        if (platform == "name") {
                                            return "option 1"
                                        } else {
                                            return "option 2"
                                        }
                                        
                                        

                                        A ternary starts with a boolean expression, then the if true value, else the false value. That's returned to either a variable or if in a function like my example, to the object calling the function. It's just a way to write less code that in many cases is easier to read.

                                        1 Reply Last reply
                                        8
                                        • P [email protected]

                                          Yeah... I played that "serial killer or programming language inventor" game.

                                          The only one I was completely in disagreement with was the inventor of Python. He's definitely a mass-murderer

                                          C This user is from outside of this forum
                                          C This user is from outside of this forum
                                          [email protected]
                                          wrote on last edited by [email protected]
                                          #26

                                          Are you sure it isn't just that he's Dutch?

                                          1 Reply Last reply
                                          4
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups