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.
  • S [email protected]

    That's not quite the argument you might think it is

    rbos@lemmy.caR This user is from outside of this forum
    rbos@lemmy.caR This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #33

    Argument?

    S 1 Reply Last reply
    3
    • maven@lemmy.zipM [email protected]
      This post did not contain any content.
      mdhughes@lemmy.sdf.orgM This user is from outside of this forum
      mdhughes@lemmy.sdf.orgM This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #34

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

      If you need to avoid evaluating the wrong branch:

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

      1 Reply Last reply
      36
      • maven@lemmy.zipM [email protected]
        This post did not contain any content.
        E This user is from outside of this forum
        E This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #35

        For optimal performance, you should rewrite it in Rust:

        inline_python::python! {
            print(js2py.eval_js("(number) => number % 2 ? 'odd' : 'even'")(number))
        };
        
        A 1 Reply Last reply
        115
        • rbos@lemmy.caR [email protected]

          Argument?

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

          You know, the stuff in @_

          rbos@lemmy.caR 1 Reply Last reply
          9
          • satyrsack@lemmy.sdf.orgS [email protected]

            Are you just referring to how Python uses the English and/or instead of the more common &&/||? I think what the user above you was talking about was Lua's strange ternary syntax using and/or.

            lime@feddit.nuL This user is from outside of this forum
            lime@feddit.nuL This user is from outside of this forum
            [email protected]
            wrote on last edited by [email protected]
            #37

            no, the linked table shows how python also returns the first non-falsey result of an a or b expression rather than just giving a boolean. it's useful for initialising optional reference args:

            def foo(a: list = None)
                a = a or []
            

            works with and as well.

            1 Reply Last reply
            4
            • E [email protected]

              For optimal performance, you should rewrite it in Rust:

              inline_python::python! {
                  print(js2py.eval_js("(number) => number % 2 ? 'odd' : 'even'")(number))
              };
              
              A This user is from outside of this forum
              A This user is from outside of this forum
              [email protected]
              wrote on last edited by [email protected]
              #38

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

              V 1 Reply Last reply
              66
              • A [email protected]

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

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

                Full circle 😆

                U 1 Reply Last reply
                22
                • S [email protected]

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

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

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

                  S 1 Reply Last reply
                  3
                  • D [email protected]

                    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.

                    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]
                    #41

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

                    rovingnothing29@lemmy.worldR S 2 Replies Last reply
                    17
                    • rbos@lemmy.caR [email protected]

                      It's kinda natural to me having used Perl a lot.

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

                      You clearly haven't used Perl a lot. Perl's ternary looks like:

                      $even = $num % 2 ? "nay" : "yay";

                      Incidentally, it is also the same as PHP's, but mainly because PHP stole it.

                      P rbos@lemmy.caR 2 Replies Last reply
                      3
                      • B [email protected]

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

                        rovingnothing29@lemmy.worldR This user is from outside of this forum
                        rovingnothing29@lemmy.worldR This user is from outside of this forum
                        [email protected]
                        wrote on last edited by
                        #43

                        Oh, (you) (really) (like) (Lisp)?
                        (That's) (great!)

                        H 1 Reply Last reply
                        1
                        • B [email protected]

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

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

                          Lisps makes more sense to me though

                          (if condition a b)

                          VS

                          a if condition else b

                          B 1 Reply Last reply
                          10
                          • V [email protected]

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

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

                            Because of all the garbage

                            F V 2 Replies Last reply
                            15
                            • L [email protected]

                              You clearly haven't used Perl a lot. Perl's ternary looks like:

                              $even = $num % 2 ? "nay" : "yay";

                              Incidentally, it is also the same as PHP's, but mainly because PHP stole it.

                              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
                              #46

                              You do get the if in the middle of stuff though in the form print(debug message) if $debug

                              P 1 Reply Last reply
                              1
                              • V [email protected]

                                Full circle 😆

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

                                Make sure the browser is made using Rust and run on a VM running on Linux, compiled to WASM.

                                1 Reply Last reply
                                11
                                • maven@lemmy.zipM [email protected]
                                  This post did not contain any content.
                                  owl@infosec.pubO This user is from outside of this forum
                                  owl@infosec.pubO This user is from outside of this forum
                                  [email protected]
                                  wrote on last edited by
                                  #48

                                  Just send pseudo code to AI and compile straight to binary.

                                  1 Reply Last reply
                                  16
                                  • P [email protected]

                                    You do get the if in the middle of stuff though in the form print(debug message) if $debug

                                    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
                                    #49

                                    Wait until you learn that postfix conditionals are syntactic sugar and the compiler* turns that line into the equivalent of $debug and print(debug message), putting the conditional in first place, a lot like the ternary operator.

                                    * Perl compiles to bytecode before running.

                                    The ternary operator itself isn't implemented in terms of and (and or) but it could be.

                                    P 1 Reply Last reply
                                    3
                                    • P [email protected]

                                      Wait until you learn that postfix conditionals are syntactic sugar and the compiler* turns that line into the equivalent of $debug and print(debug message), putting the conditional in first place, a lot like the ternary operator.

                                      * Perl compiles to bytecode before running.

                                      The ternary operator itself isn't implemented in terms of and (and or) but it could be.

                                      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
                                      #50

                                      Luckily I don't need to read or write bytecode and all that matters to me is the syntax

                                      1 Reply Last reply
                                      2
                                      • S [email protected]

                                        Because of all the garbage

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

                                        Clearly the garbage collector is too effective

                                        F 1 Reply Last reply
                                        3
                                        • S [email protected]

                                          Lisps makes more sense to me though

                                          (if condition a b)

                                          VS

                                          a if condition else b

                                          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
                                          #52

                                          I was more talking about (+ a b) and such.

                                          1 Reply Last reply
                                          8
                                          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