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

    I don't understand. What do you mean by deciding what the code should do in the context of language design? Can you give a concrete example? I am confused because the "main" function is required when you make an executable. Otherwise, a library will not contain any main function and we could compile it just fine no? (Shared library)

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

    Python is an interpreted language that doesn't need a main function explicitly. You can define any package entry points you want at the package config level. (setup.py, etc)

    example:
    What I meant was I prefer language that treat developers like adults. If I want ptrhon's "ux" to hide some functions or objects I can do that with underscores, but nothing is private, a developer using my library can do whatever they want with it, access whatever internals they want (at their own risk of course)

    1 Reply Last reply
    0
    • F [email protected]

      What's the difference between a "scripting" language and a "real" one?

      jackbydev@programming.devJ This user is from outside of this forum
      jackbydev@programming.devJ This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #131

      Scripting languages are real. Generally people consider dynamic languages scripting languages but it's not that simple.

      1 Reply Last reply
      0
      • 30p87@feddit.org3 [email protected]

        Not having tons of code in one if statement, but in a function.

        firelizzard@programming.devF This user is from outside of this forum
        firelizzard@programming.devF This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #132

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

        30p87@feddit.org3 1 Reply Last reply
        0
        • F [email protected]

          Unix shell scripts are one of the few holdouts.

          I don't know if this applies to other shells, but bash will not only execute your script line-by-line, it will also read it line-by-line. Which means that you can modify the behavior of a running script by editing lines that have not yet been executed*. It's absolutely bonkers, and I'm sure that it has caused more than one system failure, during upgrades.

          * For example, if you run the following script

          echo "hello"
          sleep 5
          echo "goodbye"
          

          and then edit the third line before the 5 second sleep has elapsed, then the modified line will be executed.

          jackbydev@programming.devJ This user is from outside of this forum
          jackbydev@programming.devJ This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #133

          I have run into the problem of modifying a bash script while it is running.

          1 Reply Last reply
          0
          • _ [email protected]

            Python doesn't need the name main check to function at all. that's just a convenience feature that lets developers also include arbitrary entry points into modules that are part of a library and expected to be used as such. If you're writing a script, a file with a single line in it reading print("hello world") will work fine when run: python thescript.py

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

            Yes, because

            In the first kind of language, the thought process is basically: I have the flow of execution, starting at the top of the file. If I want to make a library, I should build the things I want to build, then get out of the way.

            Note the "I have the flow of execution", and the "if I want to build a library".

            If you just want to build an executable, do as you wish, you already have the flow of execution.

            If you want to build a library, make the relevant classes and functions and get out of the way (i.e., no IO, no long-running tasks).

            If you want to combine them, use the main name check - or, make a package and do entry points that way. Either way works, because both can fulfill the goal of staying out of the way of those importing this as a library.

            1 Reply Last reply
            0
            • embed_me@programming.devE [email protected]

              Agreed. I program mainly in C so its easier for me to make sense of bad C code than bad python code which just makes me cry

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

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

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

                The if block is where my arg parser goes

                1 Reply Last reply
                2
                • S [email protected]

                  As much as I am inclined to agree with this, still can't

                  see: LISP

                  Also, see: Python with more than three lines of logic. I could suspect that's just the me-versus-whitespaces thing, but no, YAML files do not get me dizzy in under thirty seconds of reading. Van Rossum made a huge miscalculation here

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

                  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 1 Reply Last reply
                  1
                  • F [email protected]

                    What's the difference between a "scripting" language and a "real" one?

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

                    A scripting language controls an existing binary. A non-scripting language is used to create a new binary.

                    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?

                      joyo@lemmy.mlJ This user is from outside of this forum
                      joyo@lemmy.mlJ This user is from outside of this forum
                      [email protected]
                      wrote on last edited by
                      #139

                      main.py or did you not read the manual?

                      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?

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