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.
  • 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?

    mousepotatodoesstuff@lemmy.worldM This user is from outside of this forum
    mousepotatodoesstuff@lemmy.worldM This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #140

    Depends on how lazy I am at the moment.

    1 Reply Last reply
    0
    • J [email protected]

      I intended this an sarcastic example; I think it's worse than putting the main outside of the branch because of the extra indent-level. It does have an upside that the main() doesn't exist if you try import this as an module.

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

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

      M 1 Reply Last reply
      2
      • P [email protected]

        Everyone's welcome to their opinion of course, but I find Python more readable than anything else and I resent the visual clutter required to make intentions plain in other languages. Feels like having a conversation where people say the words "comma", "period", etc.

        I also spend more time with Python than anything else and I suspect these two facts about me relate, lol

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

        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 1 Reply Last reply
        0
        • firelizzard@programming.devF [email protected]

          I thought you were saying to literally use def main(): pass, that’s why I was confused

          30p87@feddit.org3 This user is from outside of this forum
          30p87@feddit.org3 This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #143

          Oh, no, that's just the usual placeholder. Though, ... would also be valid iirc, and would fit better as a "TODO" placeholder

          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?

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

            I've always found needing to manually add a class instance parameter (i.e. self) to every object method really weird. And the constructors being named __init__. Not having multiple dispatch is kinda annoying too. Needing to use decorators for class methods, static methods, and abstract classes is also annoying. Now that I think about it, Python kinda sucks (even though it's the language I use the most, lol).

            S 1 Reply Last reply
            0
            • addie@feddit.ukA [email protected]

              I feel that Python is a bit of a 'Microsoft Word' of languages. Your own scripts are obviously completely fine, using a sensible and pragmatic selection of the language features in a robust fashion, but everyone else's are absurd collections of hacks that fall to pieces at the first modification.

              To an extent, 'other people's C++ / Bash scripts' have the same problem. I'm usually okay with 'other people's Java', which to me is one of the big selling points of the language - the slight wordiness and lack of 'really stupid shit' makes collaboration easier.

              Now, a Python script that's more than about two pages long? That makes me question its utility. The 'duck typing' everywhere makes any code that you can't 'keep in your head' very difficult to reason about.

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

              other people's Java

              I'm gonna have to disagree here, it's always a guessing game of how many layers of abstraction they've used to seemingly avoid writing any implementation code... Can't put the code related to "bicycles" in the Bicycle class, no, that obviously goes in WheeledDeviceServiceFactoryBeanImpl that's in the 'utils' package.

              addie@feddit.ukA 1 Reply Last reply
              1
              • E [email protected]

                other people's Java

                I'm gonna have to disagree here, it's always a guessing game of how many layers of abstraction they've used to seemingly avoid writing any implementation code... Can't put the code related to "bicycles" in the Bicycle class, no, that obviously goes in WheeledDeviceServiceFactoryBeanImpl that's in the 'utils' package.

                addie@feddit.ukA This user is from outside of this forum
                addie@feddit.ukA This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #146

                Enough of that crazy talk - plainly WheeledDeviceServiceFactoryBeanImpl is where the dependency injection annotations are placed. If you can decide what the code does without stepping through it with a debugger, and any backtrace doesn't have at least two hundred lines of Spring boot, then plainly it isn't enterprise enough.

                Fair enough, though. You can write stupid overly-abstract shit in any language, but Java does encourage it.

                1 Reply Last reply
                1
                • addie@feddit.ukA [email protected]

                  Well now. My primary exposure to Go would be using it to take first place in my company's 'Advent of Code' several years ago, in order to see what it was like, after which I've been pleased never to have to use it again. Some of our teams have used it to provide microservices - REST APIs that do database queries, some lightweight logic, and conversion to and from JSON - and my experience of working with that is that they've inexplicably managed to scatter all the logic among dozens of files, for what might be done with 80 lines of Python. I suspect the problem in that case is the developers, though.

                  It has some good aspects - I like how easy it is to do a static build that can be deployed in a container.

                  The actual language itself I find fairly abominable. The lack of exceptions means that error handling is all through everything, and not necessarily any better than other modern languages. The lack of overloads means that you'll have multiple definitions of eg. Math.min cluttering things up. I don't think the container classes are particularly good. The implementation of pointers seems solely implemented to let you have null pointer exceptions, it's a pointless wart.

                  If what you're wanting to code is the kind of thing that Google do, in the exact same way that Google do it, and you have a team of hipsters who all know how it works, then it may be a fine choice. Otherwise I would probably recommend using something else.

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

                  I'm now 1 year in to working in Go having been mostly C++ and then mostly large-scale Python dev (with full type annotation).

                  Frankly, I bristle now at people giving Python a hard time, having worked with Go and I now hate Go and the de-facto ethos that surrounds it. Python may be slow, but for a lot of use cases not in any way that matters and modern computers are very fast. Many problem areas are not performance-limited, and many performance problems are algorithmic, not from raw statement execution. I even rewrote an entire system in Python and made it use 20% of the CPU the former C++ solution used, while having much more functionality.

                  The error returns drive me nuts. I looked around for explanations of the reasoning as I wasn't seeing it, and only found bald assertions that exceptions get out of control and somehow error returns don't. Meanwhile standard Go code is very awkward to read because almost every little trivial function calls becomes 4 lines of code, often to do nothing but propagate the error (and errors are just ignored if you forget...). With heavy use of context managers, my error and cancellation handling in Python was always clean, clear, and simple, with code that almost read like whiteboard pseudo-code.

                  The select statement can be cool in Go, but then you realize that literally 98% of the times it's used, it's simply boilerplate code to (verbosely) handle cancellation semantics via the context object you have to pass everywhere. Again, literally code you just don't need in exception-based languages with good structures to manage it like Python context managers.

                  And every time you think "this is stupidly awkward and verbose, surely there's a cleaner way to do this" you find people online advocating writing the same boilerplate code and passing it off as a virtue. e.g. get a value from a map and fall back to a default if it's not there? Nope, not offering that, so everyone must write their own if foo, ok := m[k]; !ok {...} crap. Over and over and over again the answer is "just copy this chunk of code" rather than "standard libraries should provide these commonly needed utilities". Of course we can do anything we want ourselves, it's Turing Complete, but why would we want to perpetually reinvent these wheels?

                  It's an unpopular language, becoming less popular (at least by Google trends) and for good reason. I can see it working well for a narrow set of low level activities with extreme concurrency performance needs, but it's not the only language that could handle that, and for everything else, I think it's the wrong choice.

                  1 Reply Last reply
                  1
                  • driving_crooner@lemmy.eco.brD [email protected]

                    Does everyone call the function of the script main? I never use main(), just call the function what the program is supposed to do, this program calculates the IBNR? The function is called calculate_IBNR(), then at the end of the script if name = 'main': calculate_IBNR(test_params) to test de script, then is imported into a tkinter script to be converter to an exe with pyinstaller

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

                    All of mine are called do_thing() because after a few days of working on it, the scope creep always means the original name was wrong anyway.

                    1 Reply Last reply
                    1
                    • 1 [email protected]

                      I've always found needing to manually add a class instance parameter (i.e. self) to every object method really weird. And the constructors being named __init__. Not having multiple dispatch is kinda annoying too. Needing to use decorators for class methods, static methods, and abstract classes is also annoying. Now that I think about it, Python kinda sucks (even though it's the language I use the most, lol).

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

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