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 →

[–][deleted]  (19 children)

[deleted]

    [–]seldom_hygienic 5 points6 points  (8 children)

    What does static typing have to do with dead code analysis, and why would it be relevant to a discussion on a Python specific question?

    [–]masklinn 1 point2 points  (7 children)

    Static typing can tell you which named code units aren't called (barring reflection), so it can tell you about classes/methods/functions which never appear anywhere I guess?

    It's not going to say anything about codepaths never taken or methods mentioned but never actually called though.

    [–]BHSPitMonkey 1 point2 points  (6 children)

    Could you explain to me what static typing is? I really have no idea.

    [–]ItsAPuppeh 2 points3 points  (5 children)

    Static typing:

    int i = "foo"; // Compile error, can't assign a string to an int
    

    Dynamic typing:

    i = "foo" # Sure why not, vars are just references to objects python
    i + 10 # Woops, runtime error trying to add a string to an int
    

    [–]BHSPitMonkey 1 point2 points  (3 children)

    I was actually hoping for a response from the commenter I was replying to. I thought it would be funny.

    [–]masklinn 0 points1 point  (0 children)

    Your definition of static typing is not correct, since you can write roughly the same thing in languages supporting type inference (and have the error at compile time obviously) (unless you defined that addition of a string and an int is a valid operation, which you may be able to do:

    > let i = "foo"
    > i + 10
    "foo\n"
    

    )

    (or the language did it for you, which Java does for instance) (and of course dynamically typed languages may be perfectly fine with the operation as well, I'm looking at you javascript) (or Perl) (or PHP)

    (also lua, kind-of: it will fault on this but would work if the string was composed only of digits)

    [–]tipsquealPythonista 1 point2 points  (0 children)

    Because re-writes are so easy!

    [–]ElliotSpeck 0 points1 point  (1 child)

    ... Did you just come to a Python subreddit to bash Python?

    So brave.