Live data from Hacker News

Bugs in Hello World

blog.sunfishcode.online

261–262 of 262 posts

Re: Bugs in Hello World

#261

Earlier quoted context omitted.

hello.c is meant as the first program a new student encounters when learning C. At that point, the student has enough to worry about; writing code to a file, checking for syntactic errors, basic program structure, using the compiler, executing the binary, understanding what `#include ` means,... Sure, we could update it: // hello_v2.0.c #include #include #include int main(void) { printf("Hello, World!\n"); fflush(std…

This just demonstrates that C is an awful programming language for writing correct programs. Compare this with Rust, where the usual hello world will just do the right thing: $ cat > a.rs fn main() { println!("Hello World"); } $ rustc a.rs $ ./a Hello World $ echo $? 0 $ ./a > /dev/full thread 'main' panicked at 'failed printing to stdout: No space left on device (os error 28)', library/std/src/io/stdio.rs:1187:9 not…

Or Zig which tries to make it easy to actually handle those errors.

Re: Bugs in Hello World

#262

Earlier quoted context omitted.

Indeed. One of the things you notice when writing say, Advent of Code solutions in Rust is that you're writing unwrap() a lot e.g. something like let geese = usize::from_str_radix(line.strip_prefix("and also ").unwrap().strip_suffix(" geese.").unwrap(), 10).unwrap(); All these functions, usize::from_str_radix, str::strip_prefix, str::strip_suffix are Options which could be None, and we need to decide what to do with…

> Sure enough sometimes while rushing to solve an AoC problem (...) >In a C program taking the same approach (...) "Writing C" and "rushing" is a strategy that cannot give you correct, robust software.

Exactly. Whereas writing Rust and rushing can give you correct, robust software.
Post reply on HN