Slashdot Mirror


Do Strongly Typed Languages Reduce Bugs? (acolyer.org)

"Static vs dynamic typing is always one of those topics that attracts passionately held positions," writes the Morning Paper -- reporting on an "encouraging" study that attempted to empirically evaluate the efficacy of statically-typed systems on mature, real-world code bases. The study was conducted by Christian Bird at Microsoft's "Research in Software Engineering" group with two researchers from University College London. Long-time Slashdot reader phantomfive writes: This study looked at bugs found in open source Javascript code. Looking through the commit history, they enumerated the bugs that would have been caught if a more strongly typed language (like Typescript) had been used. They found that a strongly typed language would have reduced bugs by 15%.

Does this make you want to avoid Python?

11 of 456 comments (clear)

  1. Re:You have to look at the source by Z00L00K · · Score: 5, Informative

    Since I have programmed in many different languages I have personally discovered that strongly statically typed languages do solve a lot of problems because the problems are encountered already at compile time, not during runtime. The problems are also less elusive.

    There are of course still bugs around, but they are more often on the strategical level than on a pure sloppiness level caused by misspellings and mismatching methods where a method is changed but one caller isn't.

    --
    If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
  2. Re:You have to look at the source by Crashmarik · · Score: 4, Informative

    Microsoft's big platforms are C,C++,C# this really doesn't do much for them.

    Lots of Borland/Pascal programmers are saying we told you so though.

  3. Re:Strong typing is like training wheels by halivar · · Score: 3, Informative

    FUCK! I had hex-editor in my head and I fucked it up. Fuck me. I failed. And fuck you, too, for sinking to my level. We all fail together.

  4. Python solves this with decorators by heretic108 · · Score: 3, Informative

    Easy enough to add strong typing in Python by adding a type check decorator to each function and method.

    --
    -- In the beginning was the WORD, and the WORD was UNSIGNED, and the main(){} was without form and void...
    1. Re:Python solves this with decorators by zhiwenchong · · Score: 4, Informative

      I don't mean to be pedantic, but Python is inherently strongly typed.
      What it is not is "statically typed".
      I think there is a general confusion in this thread between strong vs weak typing, and dynamic vs static typing.

  5. Re:You have to look at the source by Anonymous Coward · · Score: 3, Informative

    I find it easier to refactor strongly typed languages as the compiler does most of the work for you before even running the program.
    I also get the feeling that strongly typed languages have better support for IDE based refactoring as more can be safely inferred about their structure.

  6. Title of this thread is messed up. by Jane+Q.+Public · · Score: 4, Informative

    The title of this thread incorrectly conflates "strongly typed" with "statically typed".

    They are two completely different things.

  7. Re:You have to look at the source by Anonymous Coward · · Score: 2, Informative

    Exactly what I was thinking. It isn't just that the end code might have 15% fewer bugs development will be quicker/more confident because a bunch of the stupid little mistakes you make while coding are automatically checked for and swigglies tell you fix them right away.

  8. Makes sense to me by blindseer · · Score: 3, Informative

    As someone that has had to program in a number of languages I can say that strongly typed languages can catch a lot of trivial bugs quickly. One example is an if/then statement that allows non-Boolean arguments. If I mistype a comparison in an if/then statement then I should expect an error on compile. If I type an assignment "if (foo = bar)" instead of a comparison "if (foo == bar)" I expect this to get flagged, but some languages don't see this as a problem.

    I prefer strongly typed languages as it can catch a lot of typographical errors and sloppy logic. It can also be frustrating at times since it can mean nesting type conversions to near absurdity. VHDL comes to mind in this. It can also be frustrating if trying to do something quickly and the compiler complains on what I would think is a pretty obvious implied type conversion.

    It's interesting to see someone try to get an idea on how many errors strongly typed languages would catch. I'm not sure this makes an argument for one language over another. It might make an argument for testing, coding style, and such though.

    --
    I am armed because I am free. I am free because I am armed.
  9. Re:Bug Conservation by jeremyp · · Score: 4, Informative

    But the destructive hard to find bugs are still there with the weakly typed languages. It just takes you longer to get around to dealing with them.

    --
    All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
  10. Re:Perl is strongly typed by Srin+Tuar · · Score: 4, Informative

    Thats still weakly typed, just a different kind of weak. Strongly types is when you fail; "a" . 1 would throw an exception and say "i dont know how I can possibly proceed" if it was strongly typed.

    Strong typing vs weak is a minor detail anyway; the real meat is dynamic vs static.