Earlier quoted context omitted.
Nullpointer exceptions are a huge thing in Java.
I haven't written any Rust in a few years, but last I knew, it was very possible for a Rust program to crash. The guarantee is that it won't corrupt memory while doing so.
Implications of Rewriting a Browser Component in Rust
11–20 of 279 posts
Re: Implications of Rewriting a Browser Component in Rust
#12> could have been caught by a run time bounds check And here I thought rust was all about zero cost abstractions.
If you want to combine the two concepts, I guess you could go for an example like this:
if index >= vec.len() {
panic!("out of bounds");
}
let value = unsafe { vec.get_unchecked(index) };
which can be rewritten using higher level abstractions as: let value = vec[index];
The second is more abstract, and that abstraction is zero cost, you do not pay for using the abstraction more than the explicit code above it.Re: Implications of Rewriting a Browser Component in Rust
#13Earlier quoted context omitted.
Nullpointer exceptions are a huge thing in Java.
I haven't written any Rust in a few years, but last I knew, it was very possible for a Rust program to crash. The guarantee is that it won't corrupt memory while doing so.
In Rust runtime panics are certainly possible (array out of bounds, out of memory, etc), but the ones analogous to Java's NullPointerException have to be explicit opted into (unwrapping optionals) and do not happen implicitly.
Rust lets you handle optionals in nicer ways which lets you be sure you covered the "null" cases at compile time with no runtime panics possible, if you like.
Re: Implications of Rewriting a Browser Component in Rust
#14Earlier quoted context omitted.
It's not, that's C++. Rust requires a lot of runtime checks, but that's the price one has to pay for memory safety.
Rust is about zero cost abstraction. Bound checks can be disabled.
Re: Implications of Rewriting a Browser Component in Rust
#15Earlier quoted context omitted.
Nullpointer exceptions are a huge thing in Java.
I haven't written any Rust in a few years, but last I knew, it was very possible for a Rust program to crash. The guarantee is that it won't corrupt memory while doing so.
Re: Implications of Rewriting a Browser Component in Rust
#16> could have been caught by a run time bounds check And here I thought rust was all about zero cost abstractions.
It's not, that's C++. Rust requires a lot of runtime checks, but that's the price one has to pay for memory safety.
Re: Implications of Rewriting a Browser Component in Rust
#17Earlier quoted context omitted.
I haven't written any Rust in a few years, but last I knew, it was very possible for a Rust program to crash. The guarantee is that it won't corrupt memory while doing so.
There are different reasons why a program can crash. Nullpointer exceptions are one of them. Out-of-memory situations are another. Rust protects you against the former, but not the latter. But at least in my experience I only encountered crashes when I disabled safety checks by calling .unwrap().
/pedantic
Re: Implications of Rewriting a Browser Component in Rust
#18> could have been caught by a run time bounds check And here I thought rust was all about zero cost abstractions.
Re: Implications of Rewriting a Browser Component in Rust
#19> could have been caught by a run time bounds check And here I thought rust was all about zero cost abstractions.
Re: Implications of Rewriting a Browser Component in Rust
#20I primarily use Java for my job. Security and memory related features of Rust are not an advantage compared to Java. But I like rust because it feels modern and produces efficient standalone binaries. Most of my hobby projects are in Rust now. But I would not rewrite any of my work projects in Rust even though they require ultimate performance. That would be a maintenance burden. It is great to see people rewriting i…
Nullpointer exceptions are a huge thing in Java.
More nuanced ones can often be caught by using all args constructors and requiring the constructor values with Objects.requiresNonNull() or similar. Using spring? Don't use field or setter injection, always constructor so the above applies as well. Making the state of your objects largely immutable means their state is more consistent and what is null and when becomes a lot less surprising.
Lastly, write good tests. If you're exhausting the behavior of your system with tests, these things are much less likely to surprise you later.
NPEs are definitely a problem with Java, but they're a very avoidable one as well.
Edit: I don't understand the downvotes. The parent said they're a huge deal and I'm disagreeing because I think they're relatively simple to avoid?