Live data from Hacker News

Programmers should never trust anyone, not even themselves

carbon-steel.github.io

51–60 of 163 posts

Re: Programmers should never trust anyone, not even themselves

#51
post #9

> Failing tests indicate the presence of bugs, but passing tests do not promise their absence. If only :) Far too often I find myself working with tests that patch one too many implementation details, putting me in a refactoring pickle

> refactoring pickle

Been there. Change one tiny thing, and 20 tests fail all over the place. But hey, at least we had ~95% test coverage! /s

The more time some piece of code has survived in production, the more "trusted" it becomes, approaching but never reaching 100% "trust" (I can't think of a more precise word at the moment).

For tests it's similar; the longer they had remained unchanged while also proving useful (e.g. catching stuff before a merge), the more trusted they become.

So when any code changes, its "trust level" resets to zero at that point, whether it's runtime code or test code. The only exception might be if the test code reads from a list of inputs and expected outputs, and the only change is adding a new input/output to that list, without modifying the test code itself.

Tests that change too frequently can't be trusted, and chances are those tests are at the wrong level of abstraction.

That's how I see it at least.

Re: Programmers should never trust anyone, not even themselves

#52
post #9

> Failing tests indicate the presence of bugs, but passing tests do not promise their absence. If only :) Far too often I find myself working with tests that patch one too many implementation details, putting me in a refactoring pickle

> refactoring pickle Been there. Change one tiny thing, and 20 tests fail all over the place. But hey, at least we had ~95% test coverage! /s The more time some piece of code has survived in production, the more "trusted" it becomes, approaching but never reaching 100% "trust" (I can't think of a more precise word at the moment). For tests it's similar; the longer they had remained unchanged while also proving useful…

Just been beaten by a bug in a production system... hidden in code silently for more than 10 years !

It just mean that for 10 years, this codepath has not been taken (The conditions for this specific error case was not met for 10 years) :-(

Actually, it would be a good monitoring information to know which path are "hot" (almost always taken since the beginning), "warm" (from time to time) or "cold" (never executed). It could help build a targetd trust. I guess that it might be possible for VM languages (like based on JVM) because the VM could monitor this... but it might be harder for machine code

Re: Programmers should never trust anyone, not even themselves

#54
post #12
post #11

Earlier quoted context omitted.

Or even worse, tests that test implementation details that doesn't matter for the actual outcome.

If I had a dollar for each frontend test that actually don't actually test anything I would be able to retire by now!

Tests that don't test anything come in at least two categories for me:

- test that were useless, are still useless and will always be useless

- tests that are currently useless but were used in the "wtf should i write" phase of coding (templating/TDD/ whatever you want to call it).

I'm partial towards the seconds, and i like when they're not removed, because often you understand how the API/algorithm was coded thanks to them (and its often unit tests). But ideally, both should be out of a codebase.

Re: Programmers should never trust anyone, not even themselves

#56

Earlier quoted context omitted.

> refactoring pickle Been there. Change one tiny thing, and 20 tests fail all over the place. But hey, at least we had ~95% test coverage! /s The more time some piece of code has survived in production, the more "trusted" it becomes, approaching but never reaching 100% "trust" (I can't think of a more precise word at the moment). For tests it's similar; the longer they had remained unchanged while also proving useful…

Just been beaten by a bug in a production system... hidden in code silently for more than 10 years ! It just mean that for 10 years, this codepath has not been taken (The conditions for this specific error case was not met for 10 years) :-( Actually, it would be a good monitoring information to know which path are "hot" (almost always taken since the beginning), "warm" (from time to time) or "cold" (never executed).…

This could be interesting. Unfortunately it'd be a performance hog to do. Some kinds of things do work with this (see performance guided optimisation in compilers)

Re: Programmers should never trust anyone, not even themselves

#57
post #11
post #9

> Failing tests indicate the presence of bugs, but passing tests do not promise their absence. If only :) Far too often I find myself working with tests that patch one too many implementation details, putting me in a refactoring pickle

Or even worse, tests that test implementation details that doesn't matter for the actual outcome.

But if you don't test those, you may break someone's workflow!

https://xkcd.com/1172/

Re: Programmers should never trust anyone, not even themselves

#58
post #45
post #28

Earlier quoted context omitted.

I guess you need to compartmentalise into different kinds of 'trust'. The not 'trusting' you do with a computer is different from the trusting you do with fellow humans in daily life. They just happen to use the same word in English.

I trust the computer far more than the fellow humans. The computer will generally give a predictable output for a given input. "fellow humans in daily life" .... not so much.

I hope you never have to cross a street, or get anywhere near a car with a human behind the wheel.

Re: Programmers should never trust anyone, not even themselves

#59
post #4

>> Random access of a character in a text buffer could take constant time (for ASCII) or linear time (for UTF-8) depending on the character encoding This is true, but incomplete. All unicode encodings take linear time, not just utf-8. That's because a character can contain multiple code points. Utf-32 allows for random access of code points in constant time, but not characters. Utf-16 has variable length code points…

Pedantically, UTF-16 has some code points out of order. The way I've always seen it implemented results in more operations spent on some points than others. See this example C code: https://icu-project.org/docs/papers/utf16_code_point_order.h...

UTF-8 doesn't suffer from this design flaw.

Re: Programmers should never trust anyone, not even themselves

#60
> Failing tests indicate the presence of bugs, but passing tests do not promise their absence.

As somebody who primarily lives on the testing side of the house, I've definitely run into cases where the developer promises that their unit tests will make a new feature less buggy, then about 5 minutes later I either find a mistake in the test or I find a bug in something that the developer didn't think to test at all.

I've also seen instances where tests are written too early, using a data structure that gets changed in development, and then causes churn in the unit tests since now they have to be fixed too.

I've generally come to think that unit tests should be used to baseline something after it ships, but aren't that useful before that point (and could even be a waste of time if they take a long time to write). I don't think I'll ever be able to convince anybody at my company about this though lol

Post reply on HN