4 ms·
I 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
by fizzynut 4y ago
I 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.
- verve_rat 4y agoIt does seem to me that you are conflating lack of evidence with non-existence though. We haven't measured an effect but that doesn't mean that we can't reason about this in other ways. The lived experience of people that do this thing for a living can be an important resource. You could argue that we are getting in to soft social science here, but is there value in what the collective of trades people think about their tools? We didn't know the science behind steal for a long time, but we still figured out how to make it and that it holds an edge really well. Empirical measurement is not the only way to discover value.
- therealdrag0 4y agoFwiw a similar pattern is seen in cooking, where lots of chefs have reasoned ideas of how things work based on tradition and lived hands on experience, yet are scientifically disproven. Lived experience works to some extent, eliminating failures and making progress, like with your steal example, but that doesn’t mean it can pick optimal options from a list of options that all work to some reasonable extent; aka dynamic typing does also build software.
- b3n 4y ago> The function will generally only work on a subset of types for given variable. This is true for many functions defined in statically typed languages too. Just because your function says it works with an integer, doesn't mean it's necessarily going to work with _any_ integer (think `1/n`). Very often the type used isn't narrow enough. Modern dynamic languages understand this, see for example Clojure's spec[1]. [1] https://clojure.org/about/spec https://clojure.org/about/spec
- Gigachad 4y agoI like libraries and languages that create a bunch of types which are essentially just renaming existing types. So you'll have a type PostID which is just an int but the language won't let you give a PostID to a function that takes UserID even though its both just integers.