• @[email protected]
    link
    fedilink
    English
    104 days ago

    While I do agree with most of what is said here, I have a hangup on one of the points: Thinking that “docstrings and variable names” are a trustworthy way to indicate types. Python is not a statically typed language - never will be. You can have as much type hinting as you want, but you will never have a guarantee that some variable holds the type you think it does, short of checking the type at runtime. Also, code logic can change over time, and there is no guarantee that comments, docstrings and variable names will always be up to date.

    By all means, having good docstrings, variable names, and type hinting is important, but none of them should be treated as some kind of silver bullet that gets you around the fact that I can access __globals__ at any time and change any variable to whatever I want if I’m so inclined.

    This doesn’t have to be a bad thing though. I use both Python and C++ daily, and think that the proper way to use Python is to fully embrace duck typing. However that also means my code should be written in such a way that it will work as long as whatever input to it conforms loosely to whatever type I’m expecting to receive.

  • Bobby Turkalino
    link
    English
    43 days ago

    The “but muh types” criticism of Python has always been completely ignorant of the main use cases of Python. Like yeah, probably shouldn’t use it in avionics or medical devices. But scientific computing where you’re basically just using the interpreter as a calculator? You really only care about whether something’s an integer or not. Float vs. double isn’t gonna kill you

    • @[email protected]
      link
      fedilink
      English
      33 days ago

      We use optional types everywhere for our server code, and that works really well. Not sure what if not variable: means? Just look at its type, no big deal. We don’t annotate everything, but we annotate enough that static analysis tools can tell us what the type of pretty much any variable is. And most of the time, it’s not even necessary because the variables are clear enough that the type can be inferred.

      So yeah, not an issue.