3 ms·
Rust? I love it but it is moving 5x the rate of C++. Static analysis may save us in this one. Yes. Rust is complicated, but the compiler is unusually good at t
by Animats 5y ago
Rust? I love it but it is moving 5x the rate of C++. Static analysis may save us in this one.
Yes. Rust is complicated, but the compiler is unusually good at telling you what you did wrong. Before it results in a crash.
The underlying problem with C/C++ is that it still doesn't have a decent array story. " char * " is so 1970s. That can't be fixed without breaking so much. All you can do is try to paper over the problem with templates. But the mold always seeps through the wallpaper. Look at the example in the original posting that reads:
FILE* fp = fopen(fname.c_str(), "r");
There it is, access to a raw pointer. Why is that even allowed any more? You ought to have to wrap "Unsafe" around it, or something.*
- shaklee3 5y agoBecause it needs to support 40+ years of legacy code. What's wrong with the more modern array types?
- habibur 5y agoBecause the underlying OS API expects a char* as file name.
- nyberg 5y agoRather, the underlying OS requires an array of bytes terminated by 0 which can be hidden behind a decent API. The type being poor at expressing this is not a limitation of the OS but of the C type system. E.g in zig this would be `[*:0]u8` which is "a pointer to a region of memory of unknown length terminated by a 0 sentinel value". It's still a pointer but nothing says the type system can't track more state around it.
- Animats 5y agoSo why isn't the Linux API properly encapsulated for C++? Rust does that. C++ got off on a weird I/O direction. That file << item << item; syntax never really caught on. Someone liked Currying too much.
- clappski 5y agoC++ has a great array story - `std::array<char, N>`. `fopen` is a C API, so yeah you have to pass it C-strings. Note that Rust has to do the exact same thing (albeit calling `open64` rather than `fopen`), you can see it in the source for the stdlib here https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/fs.rs#L764 https://github.com/rust-lang/rust/blob/master/library/std/sr...
- MaxBarraclough 5y ago> Why is that even allowed any more? You ought to have to wrap "Unsafe" around it There have been a few different projects aiming to introduce 'proper arrays' into C, but they never get traction, even when carefully designed for good backward compatibility. C is seemingly just too resistant to change. Here's Walter Bright's suggestion. [0] Aside: why is the word story so popular on Hacker News these days? We can just say C doesn't have decent arrays. We aren't discussing its history, we're discussing a specific technical facet of the language. [0] https://www.digitalmars.com/articles/C-biggest-mistake.html https://www.digitalmars.com/articles/C-biggest-mistake.html