Live data from Hacker News

Cold Showers

github.com

131–140 of 363 posts

Re: Cold Showers

#131
post #62

Earlier quoted context omitted.

It’s basically self-evident that static analysis reduces bugs. It’s trivial to construct an example of where type information would catch a bug. Unless there is some reason that including type information increases bugs, the existence of a single example where type information catches a bug would prove that overall type information reduces total bug count.

This reminds me of the studies done related to traffic lights and stop signs. Removing traffic lights and stop signs actually reduces accidents because drivers are more careful when driving through intersections which reduces speeds and drivers become more alert. Developers will adapt to their toolset. If you have a statically typed language, you trust it will deal with type related issues and you become more lax wit…

I can't speak for all Ruby developers but I found that I could read a pull request from just about anyone I worked with a and find a spot where they hadn't covered a possible nil with a test. And yes, we had coverage checks.

A type system can keep you from having to write those tests.

Re: Cold Showers

#132

> Static Typing reduces bugs. At least to me, the big advantage of static typing is not that it (allegedly) reduces bugs, but that it aids my understanding and helps in navigating the program. It's a tool for thinking and communicating.

I've never found static typing to aid in my understanding of a program. For example: def add_item_to_cart(item) vs void add_item_to_cart(IItem item) They are equally easy to understand. The first is easier to read.

What about

    addItemsToCart(items)
Vs

    Type ItemCode: string;
    Type ItemDetails = {...};
 

 
    addItemsToCart(items:ItemCode[])
or, for a slightly different implementation:

    addItemsToCart(items:Record)


If you only use trivial examples, types seem silly. But in real examples they become more useful. In this case looking at the function signature give you immediate information about the implementation that is missing from the untyped version.

EDIT: please excuse formatting, I'm on mobile and cannot get it to add spaces before the last code block

Re: Cold Showers

#133

Earlier quoted context omitted.

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…

> 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 eviden…

It 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.

Re: Cold Showers

#134

>Hype: "Static Typing reduces bugs." Oof, that one is a huge can of worms.

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 c…

> 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

Re: Cold Showers

#135
post #79

> Static Typing reduces bugs. At least to me, the big advantage of static typing is not that it (allegedly) reduces bugs, but that it aids my understanding and helps in navigating the program. It's a tool for thinking and communicating.

Allegedly? Have you ever written code in a dynamically typed language? I'm forever fixing TypeErrors and AttributeErrors and the like. I suppose it's not even necessary to argue about experience fixing them or not, just the fact that those are runtime errors rather than compile-time (and so we presume not shipped) shows it reduces bugs doesn't it?

I always notate my functions with JSDocs and my DTOs as jsdoc types which in any modern IDE gives you the same advantages that you would get out of the explicit typescript interface/type.

And Unlike typescript my code doesn't need to be transpiled at all since it is already vanilla JS.

Re: Cold Showers

#136

Earlier quoted context omitted.

> 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 eviden…

Well, 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/... I'm not sure what evidence your fact is based on, feel free to present some evidence for it.

> 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/

"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

> 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.

Re: Cold Showers

#137

Earlier quoted context omitted.

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 c…

> By empirical measure, static typing reduces bugs As the article says, this does not appear to be actually true when you go and check.

[deleted]

Re: Cold Showers

#138
post #81

Earlier quoted context omitted.

A 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.

Your argument is analogous to the one used by homeopaths and those believing in telekinesis. "There is an effect but it disappears in a laboratory setting, but it's still there!"

All effects disappear if you don’t use strong enough measurement techniques

Re: Cold Showers

#139
post #70

Earlier quoted context omitted.

that it aids my understanding and helps in navigating the program Static typing reduces bugs because it aids your understanding.

Well, it also fails to compile. Which to me is better than blowing up at runtime, or worse, not blowing up but giving weird results.

This is a superpower during refactoring.

Re: Cold Showers

#140

> Hype: "Identifiers should be self-documenting! Use full names, not abbreviations." > Shower: Researchers had programmers fix bugs in a codebase, either with all of the identifiers were abbreviated, or where all of the identifiers were full-words. They found no difference in time taken or quality of debugging. That's a very weird take on the statement. The downside of using abbreviations is probably dominated by the…

How new devs modify the code depends on its names too. So does how we further consume code modules. Architecture and system complexity are virtually emergent from names. So I agree. Kind of a nonsense one.
Post reply on HN