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.
  • grrgyle@slrpnk.netG [email protected]

    I'm not sure I'm following the implication. Name=main is for scripts primary, is it not?

    I've never thought to add more than one of these conditionals anyway...

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

    So you might have a script that does stuff as a library, and it should get environment variables and other info from the calling script. You use the same script for doing one off stuff on different computers.

    So you make it do something slightly different or make it set it's path and look into the current folder when you run it directly. This change in logic could be in a few points in the script.

    1 Reply Last reply
    0
    • P [email protected]

      How do you feel about other peoples Go code?

      yogurtwrong@lemmy.worldY This user is from outside of this forum
      yogurtwrong@lemmy.worldY This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #124

      I used it for a while and I think it's been one of the best languages I've tried. C for example is too barebones for modern desktop apps. Apps written in Rust are great but most of the time, it's just not worth the effort. And stuff like Python, JS is... uhh.. where do I even begin

      I think Go hits the sweet spot between these. Unlike C, it at least has some simple error/panic mechanism, GC so you don't have to worry about memory much and some modern features on top of that. And unlike Python it can actually create reasonably snappy programs.

      In any programming language, there will always be multiple cases where you need to link C libraries. CGo, although people don't seem to be adoring it, is actually... okay? I mean of course it does still have some overhead but it's still one of the nicer ways to link C libraries with your code. And Go being similar to C makes writing bindings so much easier

      Multithreading in Go is lovely. Or as I read somewhere "you merely adopted multithreading, I was born with it"

      Packaging is handled pretty nicely, pulling a library from the net is fairly trivial. And the standard directory structure for Go, although I'm not used to it, makes organizing stuff much easier and is easy to adopt

      As you would've guessed from the amount of times I mentioned C in this comment, I basically see Go as the "bigger C for different situations"

      1 Reply Last reply
      2
      • S [email protected]

        Readability? Me eyes bleed from a day of partially staring at python code, and there is a whole another week of that ahead. Tzinch (Edit: Tzeentch) help me

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

        Like in every programming language, it depends who wrote the code. OK, *nearly every programming language, see: LISP.

        You can write cryptic, write-only programs in about any language, but you can even write readable and maintainable PERL scripts (despite people claiming this to be impossible).

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

          Like in every programming language, it depends who wrote the code. OK, *nearly every programming language, see: LISP.

          You can write cryptic, write-only programs in about any language, but you can even write readable and maintainable PERL scripts (despite people claiming this to be impossible).

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

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

            That is not how Python works. There are very few languages that work by executing line-by-line anymore. Unix shell scripts are one of the few holdouts. JavaScript also does it to a certain extent; the browser starts executing line-by-line while a compiler step works in the background. Once the compiler is done, it starts execution of the compiled form right where the line-by-line execution left off. It helps JavaScript be more responsive since it doesn't have to wait for the compiler to finish.

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

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

              This is the most excellent summary of Go I have ever read. I agree with everything you've said, although as a fan of Scala and in particular its asynchronous programming ecosystem (cats for me, but I'll forgive those who prefer the walled garden of zio) I would also add that, whilst its async model with go routines is generally pretty easy to use, it can shit the bed on some highly-concurrent workloads and fail to schedule stuff in time that it really should've, and because it's such a mother-knows-best language there's fuck all you can do to give higher priority to the threads that you happen to know need more TLC

              1 Reply Last reply
              0
              • _ [email protected]

                Letting the developer decide what the code should do.

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

                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)

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