News for hackers. Stuff that matters.
Re:I am disappointed by dynamic typing by Yoric on Tuesday November 29, 2022 @01:32PM (#33791305)
I may be misunderstanding what you write, but I've had many (many, many) programs that worked for the wrong reasons, which led them to break in very (very, very) ugly ways due to unrelated changes.

The only ways I know of to get rid of (some of) these bugs are to: - use as much static typing as possible; - wherever static typing is not sufficient, sprinkle this with a paranoid dose of assertions.

If I read what you write correctly, that's way beyond "testing for the correct behavior", no?

Re:I am disappointed by dynamic typing by goto11 on Tuesday November 29, 2022 @02:51PM (#33792336)
> which led them to break in very (very, very) ugly ways due to unrelated changes.

Sounds more like a problem with tight coupling than a problem with types per se. A function should not change behavior due to an "unrelated change", regardless of static or dynamic typing.

Re:I am disappointed by dynamic typing by Yoric on Wednesday November 30, 2022 @03:36PM (#33807273)
Let me give you a trivial example (with TypeScript-style syntax, but assuming no TypeScript-style type-checking):

``` function foo(config: {hasYakShaver: boolean}) { if (config.hasYakShaver) { // ... } else { // ... } }

foo({hasChuckYeager: false}); ```

This will accidentally do what I want, but for bad reasons. And one day, quite possibly, a change that appears unrelated will break this.

And that's me being nice. If I start using reflection to do complicated stuff, or if I'm using C++ and the reason for which my code works is memory corruption... well, when I need to figure out what suddenly broke the code, I'm going to be up for serious a moment of loneliness.

Re:I am disappointed by dynamic typing by goto11 on Wednesday November 30, 2022 @04:37PM (#33808127)
Sure, static typing will catch such issues. But there is still no guarantee that the foo function (or the function calling foo) works correctly just because it passes the type checker.

If you have unit tests (or other types of automated testing) you have a much bigger chance of catching logical errors and it will also catch trivial error like misspelling an identifier.

Re:I am disappointed by dynamic typing by Yoric on Friday December 02, 2022 @05:25PM (#33837795)
I was responding to

> Testing for the correct behavior should be enough.

Also, in my experience, automated tests tend to catch many bugs, static typing also catches many bugs and defensive programming catches many bugs, too. There is an intersection between all three, but it's by no mean 100%. So I use all three of these.

And of course, let's not discount monitoring, fuzzing, etc.