6 ms·
This one definitely hits close to home. By empirical measure, static typing reduces bugs, but maybe it's just me. I definitely like the comfort of trusting my t
by leononame 4y ago
This one definitely hits close to home. By empirical measure, static typing reduces bugs, but maybe it's just me. I definitely like the comfort of trusting my types.
My only experience with dynamic typing is really node, which improves a bit with typescript. But I'm still extremely wary of it because it doesn't give you runtime guarantees. It irks me a lot that you can just do JSON.parse, declare any type on it and call it a day. I firmly believe that static typing increases code readability and catches low-hanging fruit, but I'm going to have to sieve through that research it seems.
- chrisseaton 4y ago> By empirical measure, static typing reduces bugs As the article says, this does not appear to be actually true when you go and check.
- tluyben2 4y agoWell, how is this measured? My experience working over 3 decades with large teams also says this is so (static typing does prevent bugs) but that is not science. How do they measure this 'when you go and check'? I am really curious as I don't even understand how people make large systems without static typing and all massively complex systems that I personally have worked with that run for decades transacting billions$ etc without flaws are all statically typed.
- chrisseaton 4y agoWe don't seem to be able to measure it, despite people trying several wacky approaches. Either that means it's hard to measure, or it means the effect is not actually there. Either way, this means that we cannot say that static typing reduces bugs. > all massively complex systems that I personally have worked with that run for decades transacting billions$ etc without flaws are all statically typed Did you try building the same systems without static typing as well and see what the difference was? Or are you just saying that you built systems with static typing and they were successful? That tells you nothing about static typing except that it doesn't prevent successful programs, which is a very weak thing to be able to claim! Lots of people, like you, think static typing is very important for developing software, but when someone challenges this and says 'can you actually show that?' they have never been able to. At some point you need to reconsider if it's actually the case.
- tluyben2 4y agoI do reconsider it all the time; we only have short lives and I cannot build a lot large systems in my life. So that is why I asked if how it is measured. I see that my teams are more effective with static typing, but that also is my management as I, as I said, cannot really imagine writing large systems in not statically typed systems. I write a lot of scheme and k and bash and wrote a lot of tcl and Perl but never could get to scale like I can with statically compiled languages. I lean more to dependently typed languages than dynamic as I simply saw only misery, but, again, this is not saying anything, it is just my experience. I am a bit afraid though, because there is no clear measurement, it is just anyone’s experience. Edit; which actually would be fine; if it works for you and your team, company and business goals…
- chrisseaton 4y ago> I see that my teams are more effective with static typing If you think you really can see evidence for it then I'd encourage you to write up a paper and submit it for peer review. I guess when you sat down to write it you'd suddenly realise that you don't actually have any hard evidence. > cannot really imagine writing large systems in not statically typed systems Ok but lack of imagination is not science. Some people cannot imagine a spherical Earth, but that doesn't make it untrue. For example I work on a system in a dynamically typed language (Ruby) that successfully handles tens of billions a year, so we know that it is possible. (We are adding optional static typing to it, but it was written without it.)
- tluyben2 4y ago> Ok but lack of imagination is not science. Sure, but that’s what I said in the first place. It all seems there is no evidence, not even empirical for either way. I was looking for any, if there was. MS or whatnot must have something no?
- chrisseaton 4y ago> I was looking for any, if there was. I would say in summary that no, we don't have any evidence. Evidence that people have tried to present has been found to be flawed in peer review.
- slaymaker1907 4y agoA lot of the studies have been problematic because they look at toy problems (like leetcode problems). Static typing really starts to show its value in large projects. One huge project I'm aware of that uses a lot of python is the Sims 4 which uses it for a lot of the game engine and mods.
- laurencerowe 4y agoThe article mentions the literature review is from 2014. Many older statically typed languages (Java/C/etc.) don’t enforce null safety. Tony Hoare called it his ‘billion dollar mistake’. https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retractions https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retra... Thankfully more modern type systems (Swift/Kotlin/F#/Rust/TypeScript/etc.) now do, hugely reducing the likelihood of runtime errors. As a mostly dynamic language developer I never saw the benefit of Java-like static typing but more modern type systems seem much more useful.
- chrisseaton 4y ago> hugely reducing the likelihood of runtime errors You say this like it's a fact... but again nobody has been able to show this in a proper scientific study.
- slaymaker1907 4y agoConsidering how many null pointer bugs I've seen, I think that this is a case where absence of evidence is not evidence of absence (at least for null safety).
- chrisseaton 4y agoThere's no evidence of the absence of the easter bunny, but we are happy that he probably doesn't exist since there's an absence of evidence. Write up your experience with null safety as a paper and submit it, because this would be a world-first if you can demonstrate it.
- wtetzner 4y agoI’m not really sure what you’re arguing. You seem to be saying that since we can’t prove that one approach is better than the other, we should just assume they’re all equal. We do have proofs that certain classes of bugs are impossible given a certain type system.
- 4y ago
- fizzynut 4y agoI am curious for why people say this as in my experience when writing a function in a dynamic language that takes a variable as a parameter: The function will generally only work on a subset of types for given variable. If I don't check the type of the variable in the function, the function will not behave as you might expect, e.g. silently fail or crash. If I do check for every possible type for a given variable: I may not have a good way of handling certain types being passed in, I may be forced to either log something out, create a run time crash or even have the function silently fail. All 3 are bad run time behaviours. If I am checking for every type in the functions, then using static typing would cause the failure at compile time so the bugs could never exist, but also being significantly less verbose than the dynamic language equivalent.
- chrisseaton 4y ago> I am curious for why people say this I'm saying it because it's a fact. I'm not giving you an opinion - it's a falsifiable fact that you can verify for yourself - we have as an industry not been able to give any good evidence for static typing reducing bugs that has stood up to peer review. You're presenting arguments for why you think there should be evidence... but when people look there isn't actually any evidence. Maybe your arguments are not sound for some reason that we don't understand, or maybe we are unable to measure the effect.
- fizzynut 4y agoWell, this paper found that a conservative underestimate of 15% of bugs would be saved through static typing: https://www.microsoft.com/en-us/research/wp-content/uploads/2017/09/gao2017javascript.pdf https://www.microsoft.com/en-us/research/wp-content/uploads/... I'm not sure what evidence your fact is based on, feel free to present some evidence for it.
- chrisseaton 4y ago> I'm not sure what evidence your fact is based on, feel free to present some evidence for it. The linked meta-study in the article we're commenting on. https://danluu.com/empirical-pl/ https://danluu.com/empirical-pl/ "under the specific set of circumstances described in the studies, any effect, if it exists at all, is small" And this question has generated the most rebuttals and retractions I've ever seen for flawed studies in computer science - it's notorious. Remember this? https://dl.acm.org/doi/10.1145/3340571 https://dl.acm.org/doi/10.1145/3340571 > Well, this paper found that a conservative underestimate of 15% of bugs would be saved through static typing Yeah does look that one shows a larger effect and has not been rebutted or retracted. One positive measurement against many negative measurements.
- quickthrower2 4y agoInteresting. I wonder what about software development that we do that you can prove scientifically then. Does planning a project mean faster delivery? Does thinking about architecture up front reduce refactors and technical debt. Does estimating lead to faster software development? There is a lot we have to decide without evidence in how we develop software. Maybe we just pick the things that feel right and make us happy.
- moffkalast 4y ago> Does planning a project mean faster delivery? Does that plan include the client changing their mind 10 times before delivering? Or finding out that some approach doesn't work and that pivoting is needed halfway through? Likely depends on how smart the planning is. > Does estimating lead to faster software development? Unlikely, because engineers are then busy ass-pulling useless time figures over and over instead of actually working on the project. All of these points have high random factors attached to them regardless, so you'd need a pretty big sample to say what generally works best.
- quickthrower2 4y agoYes I agree with you. My point is that almost everything we do in management if software teams and architecture decisions is a guess. We have to carry on regardless and make decisions. The nuance is what you do, why you do it and is there cultism or cargo cultism to the decisions.
- deleted 4y ago[deleted]
- rajin444 4y agoThorough understanding of the problem and thorough testing prevent bugs. Static typing allows you to more succinctly express your thorough understanding of a problem, but it does not fix the root problem. Quality of life benefits are where static typing (and in some cases performance) really shines.
- davnicwil 4y ago> It irks me a lot that you can just do JSON.parse, declare any type on it and call it a day You should look at zod [0], which validates data with inferred types based on the validation having passed, so you do have the guarantee of the type being correct at runtime. [0] https://zod.dev https://zod.dev