• My opinion: Python may not be the best at everything it does, but it’s in the top 3-5 languages in the following areas:

    • Very easy to install, write and understand
    • Great libraries for a lot of applications
    • Large community, lots of people with experience in it

    It will always be a practical choice for those reasons. There are probably a lot more as well that I can’t think of at the moment.

    • Python is not the best at anything, but is the second best at almost everything. That’s the reason I use it. Everything I need to do, I know I can do it in python, maybe isn’t going to be the better or faster it could be, but it will work.

    • Henson ( Henson@feddit.dk ) 
      link
      fedilink
      arrow-up
      17
      ·
      1 year ago

      I would add its a easy Scripting language. No compilation problem, richer that shell/bash makes it a powerfull choice.

      And a really dont like it.

        • Frezik ( frezik@lemmy.blahaj.zone ) 
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year ago

          Python is largely compiled. All the pieces of a compiler are built into how it processes things. Almost nothing works on an interpreter model anymore, where each line is parsed and executed before handling the next. Unix-style shell scripts are one of the very few exceptions. I believe JavaScript also starts being interpreted in the browser in order to start executing immediately, but then a compiled version is swapped into the runtime as soon as it’s ready.

          • flatbield ( furrowsofar@beehaw.org ) 
            link
            fedilink
            English
            arrow-up
            3
            ·
            1 year ago

            Depends on what you mean by compiled. Python (CPython from python.org) typically translates to meta code and that is interpreted. True compilation to binary runs about 100x faster. Python is slow though there are faster versions and ways around it. Speed and threading are Python’s biggest issues.

            • Frezik ( frezik@lemmy.blahaj.zone ) 
              link
              fedilink
              English
              arrow-up
              2
              ·
              1 year ago

              I mean that there are successive steps to transform the entire code into tokens, the tokens into an AST, and the AST into some intermediary or final form.

              True compilation to binary runs about 100x faster.

              No, it doesn’t. Take a look at any of the number of projects that have attempted to compile Java to native code over the years. You’d be lucky to see any substantive gain at all. They sometimes have a use for packaging everything up in a single distributed binary, but you don’t do it for speed.

              Things like C and Rust are fast because the language semantics can be compiled in a fast way.

              • flatbield ( furrowsofar@beehaw.org ) 
                link
                fedilink
                English
                arrow-up
                2
                ·
                1 year ago

                We will have to disagree on that. This is all problem spectific, but I have found C code integrated via ctypes, cffi, or by a C extension is over 100x Python alone. Interestingly Python, Numba, and Numpy together which is a more pythonic solution can get to those speeds too.

                All of the other approaches I have tried are much slower: Nuitka, Cython, Numpy alone, PyPy, etc.

                To get best speeds one has to compile for your specific architecture and enable things like vectorization, auto parallel, and fast math. Most default builds including libraries do not do that.

                • Frezik ( frezik@lemmy.blahaj.zone ) 
                  link
                  fedilink
                  English
                  arrow-up
                  1
                  ·
                  1 year ago

                  This is all problem spectific, but I have found C code integrated via ctypes, cffi, or by a C extension is over 100x Python alone. Interestingly Python, Numba, and Numpy together which is a more pythonic solution can get to those speeds too.

                  Of course you did. Those are changing the semantics of the language. For example, things like Numpy store arrays more like how C does it than Python. That makes all the difference, not merely compiling to native code.

      • Yeah, you can use it both for full applications (web or desktop) as well as simple scripts. The flow of getting from something simple to a full blown application is pretty smooth and natural - better than just starting out in Java or C++ and taking at least an hour before you get anything that runs.

    • masterspace ( masterspace@lemmy.ca ) 
      link
      fedilink
      English
      arrow-up
      13
      ·
      1 year ago

      Python is popular because it’s whitespace based syntax make noobs think it’s easy to read. This and it’s pre-installation on Linux made it popular amongst academics who embraced it for data analysis. This lead to a lot of data scientists embracing it and writing libraries for it which created a virtuous cycle in that arena.

      And it’s a damn shame because Python, and it’s whitespace nonsense and lack of type system, is a horribly impractical language for building anything at scale.

  • I think it’s just because it is always recommended as an “easy” language that’s good for beginners.

    The only other thing it has going for it is that it has a REPL (and even that was shit until very recently), which I think is why it became popular for research.

    It doesn’t have anything else going for it really.

    • It’s extraordinarily slow
    • The static type hints are pretty decent if you use Pyright but good luck convincing the average Python dev to do that.
    • The tooling is awful. uv is a lifesaver there but even with uv it’s a bit of a mess.
    • The package system is a mess. Most people just want to import files using a relative path, but that’s pretty much impossible without horrible hacks.
    • The official documentation is surprisingly awful.
    • Implicit variable declaration is a stupid footguns.

    The actual syntax is not too bad really, but everything around it is.

    • I think it’s just because it is always recommended as an “easy” language that’s good for beginners.

      The only other thing it has going for it is that it has a REPL (and even that was shit until very recently), which I think is why it became popular for research.

      If that’s the case, then why didn’t Javascript take its place instead? It’s arguably even better at Python in both of those areas…

  • Flamekebab ( Flamekebab@piefed.social ) 
    link
    fedilink
    English
    arrow-up
    7
    ·
    1 year ago

    I would argue it’s because it is Good Enough. The most popular solutions to things are rarely the optimum ones but the ones that are generally applicable.

    For example, I could fight with bash’s unpleasant syntax or I could do it more easily (but less efficiently) with Python. Would it be as performant? Absolutely not - but the performance gains wouldn’t be worth the time and maintainability.

      • masterspace ( masterspace@lemmy.ca ) 
        link
        fedilink
        English
        arrow-up
        4
        ·
        edit-2
        1 year ago

        Lazy is an overly harsh and judgemental way to put it (virtually all programmers start with some high level simplified language), but the sentiment arises because it’s syntax is designed to be easy for people writing code, but at the cost of people maintaining code.

        The whitespace delimiters, the lack of type system, the lack of semi-colons … They’re all things that people who haven’t programmed before think make programming easier. In reality they all make in the wild production programs waaay harder to maintain.

        There’s a reason that JavaScript has been surpassed by TypeScript for professional developers, and it did so remarkably quickly. All that ‘extra’ information that seems pointless for a new dev to express, in reality constrains your program, makes it more readable and understandable, reduces the amount of tests you have to write, and makes it easier for someone else to come in and make a change to it and be confident they haven’t broken anything.

        • Python’s type system is dramatically better than Javascript’s though. Try doing things like '' + True and Javascript will do incredibly stupid things. Python will just give you a type error. Also, look at things like == vs === in Javascript as well. That’s the biggest reason why Typescript replaced it overnight. Python has found a better balance between productivity and error safety.

          In my opinion, the biggest shortcoming of Python’s dynamic typing system is that you need to have very thorough test coverage to be sure that your code doesn’t have semantic errors (a lot more than, say, Java). It has gotten better with the introduction of type hints, those I don’t have much experience with them, so I can’t say how much.

          • Feyd ( Feyd@programming.dev ) deleted by creator
            link
            fedilink
            arrow-up
            2
            ·
            1 year ago

            In my opinion, the biggest shortcoming of Python’s dynamic typing system is that you need to have very thorough test coverage to be sure that your code doesn’t have semantic errors

            That is a large shortcoming.

            • Sure, but as with all things, it can depend on a lot of factors. All code needs some degree of testing, though one could certainly argue that Python needs more than Java and Java needs more than Rust/Haskell/etc. So you could argue that the productivity gain of using Python is offset by the productivity loss of extra testing. It’s still hard to say which one wins out in the end.

              • Feyd ( Feyd@programming.dev ) deleted by creator
                link
                fedilink
                arrow-up
                7
                ·
                1 year ago

                People underestimate the cost of testing.

                1. It has to actually happen to be effective and is something that can be dropped under time pressure where something built into the language cannot.
                2. Test code is also code that is not guaranteed to be correct, and also incurs it’s own maintenance tolls

                Removing the need for entire classes of tests cases is a huge win

          • flatbield ( furrowsofar@beehaw.org ) 
            link
            fedilink
            English
            arrow-up
            2
            ·
            1 year ago

            Go might be a close 2nd language wise but not the others. All of the above have a pretty narrow application range too. Even with a good lamguage, you would have to have the libraries too and pypi is pretty big.

            • All three of those languages have library ecosystems at least as good as Python’s. Typescript is just as easy to learn and as fast to write as Python. I don’t see why you’d think Python is faster. If I add up all the time I’ve lost to Python’s terrible tooling it’s quite a lot slower!

              Rust is definitely harder to learn - I’ll give you that. But once you have learnt it it’s just as fast as Typescript and Python. Especially if your “fast to write” metric measures to when you program is correct.

  • flatbield ( furrowsofar@beehaw.org ) 
    link
    fedilink
    English
    arrow-up
    4
    ·
    edit-2
    1 year ago

    Presumably because it minimizes developer time in writing code and is easy to use and it come with great libraries. That is why I have been using it since 1998.

    Edit: People use to think I was crazy using Python. It was interesting seeing people slowly get a clue over the years.

  • I started using it as an alternative to Octave/Matlab and Perl. Python is better at general programming than Octave/Matlab, and better syntax than Perl (IMO) while being almost as easy to do the same stuff I was using Perl for. It’s very good for quickly writing small scripts. Issues can arise on large projects/teams because of stuff like type safety, and it also has issues with performance.