4 ms·
> is more likely to be correct. This is a moot statement. Here is a thought experiment that demonstrates the pointlessness of languages like Rust in terms of c
by ActorNightly 1y ago
> is more likely to be correct.
This is a moot statement. Here is a thought experiment that demonstrates the pointlessness of languages like Rust in terms of correctness.
Lets say your goal is ultimate correctness - i.e for any possible input/inital state, the program produces a known and deterministic output.
You can chose 1 of 2 languages to write your program in:
First is standard C
Second is an absolutely strict programming language, that incorporates not only memory membership Rust style, but every single object must have a well defined type that determines not only the set of values that the object can have, but the operations on that object, which produce other well defined types. Basically, the idea is that if your program compiles, its by definition correct.
The issue is, the time it takes to develop the program to be absolutely correct is about the same. In the first case with C, you would write your program with carefully designed memory allocation (something like mempool that allocates at the start), you would design unit tests, you would run valgrind, and so on.
In the second case, you would spend a lot more time carefully designing types and operations, leading to a lot of churn of code-compile-fix error-repeat, taking you way longer to develop the program.
You could argue that the programmer is somewhat incompetent (for example, forgets to run valgrind), so the second language will have a higher change of being absolutely correct. However the argument still holds - in the second language, a slightly incompetent programmer can be lazy and define wide ranging types (similar to `any` in languages like typescript), leading to technical correctness, but logic bugs.
So in the end, it really doesn't matter which language you chose if you want ultimate correctness, because its all up to the programmer. However, if your goal is rapid prototyping, and you can guarantee that your input is constrained to a certain range, and even though out of range program will lead to a memory bug or failure of some sort, programming in something like C is going to be more efficient, whereas the second language will force you write a lot more code for basic things.
- ashdksnndck 1y agoThis claim makes some sense to me if your development life cycle is: write and compile once, never touch again. Working at a company with lots of systems written by former employees running in production… the advantages of Rust become starkly obvious. If it’s C++, I walk on eggshells. I have to become a Jedi master of the codebase before I can make any meaningful change, lest I become responsible for some disaster. If it’s Rust, I can just do stuff and I’ve never broken anything. Unit tests of business logic are all the QA I need. Other than that, if it compiles it works.
- ActorNightly 1y ago>If it’s Rust, I can just do stuff and I’ve never broken anything. This is not true. Case and point- Java. Many times simpler than Rust, and large codebases are as horrible as C++ ones.
- ashdksnndck 1y agoI have two primary complaints about Java, relative to Rust: 1. NullPointerException. I get some object with a bunch of fields and I don’t know which of them are null. In Rust I am given a struct, and usually the fields aren’t an Option unless they need to be. 2. Complicated design patterns with inheritance. Maybe it’s more of a problem with the culture/ecosystem than Java the language. But Rust doesn’t have inheritance, and traits are less complicated. So you rarely get the same smells. Compared to C++, Java is easier to debug, but I still have a lot of “wtf” moments trying to understand what the author was thinking. It is almost like the language is so simple to write, people are making the program more complicated on purpose just to make it interesting.
- ActorNightly 1y agoThe point is that programmers are ultimately responsible for clean code. You can write very good C code that is very easy to debug. Languages don't really matter for this.
- JambalayaJimbo 1y agoYour example is of a greenfield project rather than living code that is constantly updated, in some cases by many people simultaneously. The compiler being a gate for correctness is far superior in the latter case.
- ActorNightly 1y agoIf you enforce very strict interfaces through language, no matter how many people work on them, the tradeoff still applies. For example, you can have multiple people working on a code base for the second case, and some sub team has a new requirement for added functionality. Now they have to go refactor a whole bunch of the codebase to make all the types coherent. And consequently, shortcuts happen here, which leads to shit codebases.
- JambalayaJimbo 1y agoLazy developers are going to choose the path of least resistance. A well designed type system will be intuitive, communicate well the original developer's wishes, and add lots of friction for doing stupid things. A lazy developer will not want to refactor the whole codebase!
- IshKebab 1y agoThis isn't true in practice. People don't write impossibly comprehensive test suites in C, and they don't use extremely loose types in Rust either. It really does matter which language you choose if you want correct code. > programming in something like C is going to be more efficient, whereas the second language will force you write a lot more code for basic things. Like how string manipulation is so much simpler and easier in C compared to Rust? Hmm.
- ActorNightly 1y agoAlso practice, most of Rust codebases are filled with `unsafe`, for interface with system libraries. Also the argument of forcing a language onto a project based on the lowest common denominator of programmers never plays out - this is how you get insanely messy Java codebases. Language choice will never solve poor programming style. >Like how string manipulation is so much simpler and easier in C compared to Rust? Hmm. Plenty of libraries for C for this.
- IshKebab 1y ago> most of Rust codebases are filled with `unsafe` That is absolutely untrue. Most Rust codebases have very few uses of `unsafe`. I have written tens of thousands of lines of Rust and used `unsafe` I think once. Maybe twice. > Language choice will never solve poor programming style. It absolutely does. Rust pushes you very strongly into the "pit of success". You can Google that term if you want to learn. > Plenty of libraries for C for this. I have yet to see a single C program in the wild use anything other than libc for string manipulation. I'm sure they exist but they are the 0.1%.
- someone_19 1y ago> Second is an absolutely strict programming language, that incorporates not only memory membership Rust style, but every single object must have a well defined type that determines not only the set of values that the object can have, but the operations on that object, which produce other well defined types. Basically, the idea is that if your program compiles, its by definition correct. That is Rust? This is how his system of types and traits works.