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. Python needs an actual default function

Python needs an actual default function

Scheduled Pinned Locked Moved Programmer Humor
programmerhumor
159 Posts 89 Posters 1 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.
  • M [email protected]

    I thought confusion about indent levels was the whole point of using python

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

    But it feels like main function should not be indented

    1 Reply Last reply
    0
    • D [email protected]

      Since Java 21, this has been shortened significantly. https://www.baeldung.com/java-21-unnamed-class-instance-main

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

      Impossible.

      1 Reply Last reply
      0
      • S [email protected]

        Nah self is quite important. The main part of a method is to access the state of the object. self is just the interface to it.

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

        Guess I just prefer languages that do it this way:

        class AClass {
          var aProp = 0
        
          fun aMethod() {
            aProp++
          }
        }
        

        Though I suppose confusion and bugs can happen when you do something like:

        class AClass {
          var aProp = 0
        
          fun aMethod(aProp: Int) {
            // `this.aProp` is needed to access the property
          }
        }
        
        1 Reply Last reply
        0
        • J [email protected]

          Does Lua rank far below python for you? I have so much rage against it. At least with Python I don't have to do a bunch of steps to just get it to do something. May take me a while to get through bad Python code, but Lua makes my eyes bleed and I begin to regret my life choices in trying to understand wtf these people wrote.

          embed_me@programming.devE This user is from outside of this forum
          embed_me@programming.devE This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #153

          Never had the opportunity to work with it. Python is much more pervasive compared to Lua I reckon

          1 Reply Last reply
          0
          • hiddenlayer555@lemmy.mlH [email protected]

            Also, do y'all call main() in the if block or do you just put the code you want to run in the if block?

            iavicenna@lemmy.worldI This user is from outside of this forum
            iavicenna@lemmy.worldI This user is from outside of this forum
            [email protected]
            wrote on last edited by [email protected]
            #154

            wait till you see

            if __name__ = "__main__":
            
               main()
            `
            hiddenlayer555@lemmy.mlH 1 Reply Last reply
            1
            • iavicenna@lemmy.worldI [email protected]

              wait till you see

              if __name__ = "__main__":
              
                 main()
              `
              hiddenlayer555@lemmy.mlH This user is from outside of this forum
              hiddenlayer555@lemmy.mlH This user is from outside of this forum
              [email protected]
              wrote on last edited by [email protected]
              #155

              Luckily Python is one step ahead:

              Python 3.13.3 (main, Apr 22 2025, 00:00:00) [GCC 15.0.1 20250418 (Red Hat 15.0.1-0)] on linux
              Type "help", "copyright", "credits" or "license" for more information.
              >>> if __name__ = "__main__":
              ... 
              ...    main()
              ...    
                  File "<python-input-0>", line 1
                  if __name__ = "__main__":
                      ^^^^^^^^^^^^^^^^^^^^^
              SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
              

              Also TIL that := is a thing in Python.

              iavicenna@lemmy.worldI 1 Reply Last reply
              0
              • hiddenlayer555@lemmy.mlH [email protected]

                Luckily Python is one step ahead:

                Python 3.13.3 (main, Apr 22 2025, 00:00:00) [GCC 15.0.1 20250418 (Red Hat 15.0.1-0)] on linux
                Type "help", "copyright", "credits" or "license" for more information.
                >>> if __name__ = "__main__":
                ... 
                ...    main()
                ...    
                    File "<python-input-0>", line 1
                    if __name__ = "__main__":
                        ^^^^^^^^^^^^^^^^^^^^^
                SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
                

                Also TIL that := is a thing in Python.

                iavicenna@lemmy.worldI This user is from outside of this forum
                iavicenna@lemmy.worldI This user is from outside of this forum
                [email protected]
                wrote on last edited by [email protected]
                #156

                yea I also couldnt get the formatting to work right, triple quotes kept turning things into accented letters, so I gave up.

                and also := also known as the walrus operator is very fun and sometimes very convenient to use

                1 Reply Last reply
                0
                • S [email protected]

                  Someone should get their hands on someone like me and someone like you and study their brains. I spend most time with PHP and C++, and Python looks like an attempt to write code like prose literature. Very interesting how much of this is habbit, as it can't be just that: reading prose and poetry in English/Russian/Japanese never produced this kind of resentment

                  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 [email protected]
                  #157

                  I would love that! I do think there are probably interesting underlying personality factors / preferences for a lot of this stuff as well.

                  I do think that many of Python's characteristics map to my own personality and I bet there's something to that. Things like syntax of course, but not strictly syntax, also things like "The Zen of Python", and the way its a "jack-of-all-trades, master-of-none". I also really kind of need the freedom and accompanying responsibility to break any "rules" on a whim (Python will happily let you overwrite its own internals while running, for instance), but I almost never do anything that uses it...

                  I could probably keep going lol. Feels like a "people looking like their pets" scenario, lmao

                  S 1 Reply Last reply
                  0
                  • P [email protected]

                    I would love that! I do think there are probably interesting underlying personality factors / preferences for a lot of this stuff as well.

                    I do think that many of Python's characteristics map to my own personality and I bet there's something to that. Things like syntax of course, but not strictly syntax, also things like "The Zen of Python", and the way its a "jack-of-all-trades, master-of-none". I also really kind of need the freedom and accompanying responsibility to break any "rules" on a whim (Python will happily let you overwrite its own internals while running, for instance), but I almost never do anything that uses it...

                    I could probably keep going lol. Feels like a "people looking like their pets" scenario, lmao

                    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 [email protected]
                    #158

                    Thank you for sharing your thoughts 🙂

                    Python will happily let you overwrite its own internals while running, for instance

                    Damn, that's cool and I did not even know. Pretty sure I would not do this in production code, but very glad very this possibility exists

                    1 Reply Last reply
                    0
                    • eager_eagle@lemmy.worldE [email protected]

                      The if block is still in the global scope, so writing the code in it is a great way to find yourself scratching your head with a weird bug 30 minutes later.

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

                      Interesting observation. Can you give an example where this is relevant?

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