Typescript - Type System explained from Anders Hejlsberg - creator of Typescript
Typescript - Type System explained from Anders Hejlsberg - creator of Typescript
The older programmers of today were once young, and many of them didn't bother to check for errors back then.
That's what the Hello, World! error illustrates. The canonical "Hello, World!" in these languages actually ignores errors, and nobody cares. But it speaks to the general mindset behind C and C++ programmers.
"Eh, it's fine". Until it isn't.
#include <stdio.h>
#include <string.h>
#define HI "Hello, world\n"
int main() {
if (printf(HI) != strlen(HI)) {
return 1;
}
return 0;
}
(And I'm sure astute readers could even find fault with this implementation.)Obviously this is tongue-in-cheek; I would never write code that checks the output of printf(), even if perhaps, in some abstract way, I "should". If we were to believe that the purpose of a "hello world" program was to teach about error handling, then maybe we should write "hello world" this way. But I'm also not sure that's its purpose.
In C that program is written in K&R. In Rust (like several modern languages) that program is provided automatically as a placeholder when you start a new project.
The C program, as I explained, just presses on anyway if there's an error. For example if the standard output on your Unix terminal leads to the full device, that's ignored and the program exits with a success indication.
The Rust program, of course, will panic, and the program exits with a failure indication (if your standard error leads to somewhere the panic report will be sent there unless you've asked for panic to abort)
It's a difference of convention. The convention in Rust is that we should care whether things fail, and if we don't know what to do about them failing we should panic.
Wouldn't hold my breath; I recall a tangent on programmers being "afraid of pointers". Depending on your favourite not-C-pointer way of managing memory, that's saying that use-after-free bugs are a sign of bad programmers, or shunning substructural/region/etc types for verifying that explicit memory management is correct.
I've seen that too... It's pretty funny because in so many modern languages every reference is just a pointer we can't do arithmetic with.
But once we hit the wall, things will shift.