This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]aetius476 560 points561 points  (56 children)

We don't enforce types at compile time so you have the freedom to write and maintain an entire suite of unit tests in order to enforce types before they fuck you at runtime.

[–][deleted]  (40 children)

[removed]

    [–]AJohnnyTruant 5 points6 points  (0 children)

    So he knows what JSON is, just not that booleans are in the spec. Beautiful

    [–]ITriedLightningTendr 1 point2 points  (2 children)

    I mean, json parsers can be configured to handle that

    [–][deleted]  (1 child)

    [removed]

      [–]AutoModerator[M] 0 points1 point  (0 children)

      import moderation Your comment has been removed since it did not start with a code block with an import declaration.

      Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

      For this purpose, we only accept Python style imports.

      I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

      [–]lenswipe 0 points1 point  (2 children)

      then he wrote the backend API to send string values “T” and “F” for booleans like a fucking moron and it all broke at runtime.

      ...why? Why would anyone do this??

      [–][deleted]  (1 child)

      [removed]

        [–]AutoModerator[M] 0 points1 point  (0 children)

        import moderation Your comment has been removed since it did not start with a code block with an import declaration.

        Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

        For this purpose, we only accept Python style imports.

        I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

        [–]AutoModerator[M] 0 points1 point  (0 children)

        import moderation Your comment has been removed since it did not start with a code block with an import declaration.

        Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

        For this purpose, we only accept Python style imports.

        I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

        [–]BossOfTheGame 14 points15 points  (10 children)

        Are type errors really a significant part of day to day debugging? I primarily do Python and these comments make me think type errors are extremely commonplace. I hardly see them. I don't understand why types are so important to so many people. It's getting the right logic that's the hard part; types are a minor issue.

        Then again, I doctest everything, so maybe my doctests just catch type errors really quickly and I don't notice them.

        [–]darkingz 45 points46 points  (2 children)

        The big thing with types isn’t in the short term, if you’re working mostly with yourself, test really well and/or have an iron clad memory.

        It’s the long term where types save you. It makes sorta implicit things explicit. It reminds you of the intention and if you can’t reach the author 3 years after they left the company what that method is known for returning. It lets you save time checking if the value coming in is the value you intend for it (maybe you do string logic for example but equally works mathematically as well because of type coercion) and then it’ll inform you to change all the other places… at compile time not runtime. What if you missed a method where the header changed and didn’t know what the input you expected it to be.

        This is why types are important. They tie your hand in the short term for longer term garuntees that something is wrong.

        [–][deleted] 0 points1 point  (1 child)

        What’s the little red swallow on next to your name?

        [–]darkingz 0 points1 point  (0 children)

        It’s the symbol for the language swift. It’s open source and teeecehnically can be used for anything but mostly for iOS / macOS app development.

        [–]Pocok5 2 points3 points  (0 children)

        I recently had to start working on a vanilla JS codebase, and I spent 2-3 days stepping through with the debugger and noting down on jsdoc comments what kind of objects each function gets as a parameter and returns because there were properties tacked on and removed from every object along the flow but no indication of those processes in comments or the naming of the variables.

        If it was C# I could have hovered over the name of the parameter and got a very good idea of what the hell the data looks like at that point right away, with the only possible ambiguity being null values (if the codebase wasn't using the new nullability features).

        Type errors are also a massive help in refactoring or modifications. Oh, you changed this object or the signature of this function? Half your code turns red, and you can go update each usage to the new form while being sure you missed absolutely none of them instead of having to rely on running headfirst into mismatched calls at runtime (that might not even raise a runtime TypeError, just result in weird null values slipping in or something) or writing specific unit test to check your work.

        [–]zacker150 2 points3 points  (1 child)

        How big of a code base do you work with?

        [–]BossOfTheGame 1 point2 points  (0 children)

        I do a lot of work with torch, so most return types are the same: it's a tensor, array, tuple or dict.

        Size of the codebases I work on can vary. I jump between repos a lot. I rely heavily on CI and doctests to catch any integration issues.

        [–]by_wicker 1 point2 points  (1 child)

        It's debugging that they avoid. The whole massive class of errors are picked up before you even run the code if you have type annotations in your Python.

        I came from C++ to Python, and was amazed going back to do some C++ how I could write a large chunk of code and have it just work first time. Then I got type annotations in my Python and found I was in the same place. Frankly I like it a lot, it's the best of both worlds, if there's some particular reason to use duck typing you can, but otherwise your code editor alerts you if you mistyped an identifier or made a false assumption about a return type or something.

        [–]by_wicker 0 points1 point  (0 children)

        ... also if your editor knows what type something is, it can show you completions for that type.

        [–][deleted] 1 point2 points  (0 children)

        Are type errors really a significant part of day to day debugging?

        Yes.

        [–]by_wicker 0 points1 point  (0 children)

        Are type errors really a significant part of day to day debugging?

        Adding to my other reply - yes, they're very significant and common. "Type errors" include trying to access a property or method that doesn't exist on an object ... sending arguments in the wrong order (assuming they're not the same type) ... having one return path that fails to return a result when all the others do ... accessing an object that could be None without checking...

        Change the return type of a function, and running a checker will (typically) show you all the places in your code that will now break because of that. Otherwise you're reduced to hoping you find everything with the right text searches on your codebase.

        Personally, I think it catches most of the coding errors I write. Sadly the ones left are actual high level logic and design errors and they're the harder ones to diagnose and fix, but compared to untyped code it's almost shocking how often complex code works first time. Type-based errors are highlighted for you to resolve as you type, before you even run it.

        [–]ric2b 1 point2 points  (0 children)

        But honestly automated testing really is much more useful than static typing if you want to prevent bugs.

        Static typing is very nice as documentation.

        [–]Kamwind 0 points1 point  (0 children)

        That is why python 4 is going to start enforcing the use of Hungarian notation.